Created
October 7, 2022 03:33
-
-
Save zbyna/69d582ddc51e97006a1c8379bd948975 to your computer and use it in GitHub Desktop.
Locale and its flag for language name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pycountry | |
from babel import Locale | |
from babel.core import LOCALE_ALIASES | |
import pathlib | |
import shutil | |
inputList = ['Czech', 'Bulgarian', 'Chinese', 'English', 'French', 'German', 'Modern Greek (1453-)', 'Hungarian', 'Indonesian', 'Japanese', | |
'Polish', 'Portuguese(BR)', 'Portuguese', 'Romanian', 'Russian', 'Spanish', 'Turkish'] | |
localeList = [] | |
for pol in inputList: | |
language = pycountry.languages.get(name=pol) | |
if language is None: | |
localeName = pol | |
localeList.append(Locale('pt','BR')) | |
else: | |
localeName = language.alpha_2 | |
if localeName in LOCALE_ALIASES: | |
localeList.append(Locale.parse(LOCALE_ALIASES[localeName])) | |
else: | |
localeList.append(Locale.parse('zh_CN')) | |
# https://github.com/python-babel/babel/issues/543 | |
# babel.Locale('zh', 'CN') nefunguje | |
for pol in localeList: | |
print(pol.language, pol.territory , pol.get_language_name('cs')) | |
for pol in localeList: | |
print(pol.language + '_' + pol.territory) | |
for pom in localeList: | |
print(pom.territory.lower() + '.png') | |
cestaTo = pathlib.WindowsPath(r'E:\Dokumenty_ZbynA\Python - projects\Locale for Count for Time\locale') | |
# cestaFrom = pathlib.WindowsPath(r'E:\Dokumenty_ZbynA\Python - projects\Locale for Count for Time\80x60') | |
cestaFrom = pathlib.WindowsPath(r'E:\Dokumenty_ZbynA\Python - projects\Locale for Count for Time\40x30') | |
for pom in localeList: | |
aktualniFile = cestaFrom.joinpath(pom.territory.lower() + '.png') | |
aktualniFile = shutil.copy(aktualniFile, cestaTo) | |
shutil.move(aktualniFile,cestaTo.joinpath(pom.language + '_' + pom.territory + '.png')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment