Skip to content

Instantly share code, notes, and snippets.

@zbyna
Created October 7, 2022 03:33
Show Gist options
  • Save zbyna/69d582ddc51e97006a1c8379bd948975 to your computer and use it in GitHub Desktop.
Save zbyna/69d582ddc51e97006a1c8379bd948975 to your computer and use it in GitHub Desktop.
Locale and its flag for language name
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