33 from PyQt5.QtCore import QLocale, QLibraryInfo, QTranslator, QCoreApplication
35 from classes.logger
import log
36 from classes
import info
37 from classes
import settings
45 app = QCoreApplication.instance()
51 "path": QLibraryInfo.location(QLibraryInfo.TranslationsPath)},
53 "pattern":
'qtbase_%s',
54 "path": QLibraryInfo.location(QLibraryInfo.TranslationsPath)},
57 "path": os.path.join(info.PATH,
'locale',
'QT')},
59 "pattern":
'qtbase_%s',
60 "path": os.path.join(info.PATH,
'locale',
'QT')},
62 "pattern": os.path.join(
'%s',
'LC_MESSAGES',
'OpenShot'),
63 "path": os.path.join(info.PATH,
'locale')},
67 locale_names = [os.environ.get(
'LANG', QLocale().system().
name()),
68 os.environ.get(
'LOCALE', QLocale().system().
name())
73 if preference_lang !=
"Default":
75 locale_names.insert(0, preference_lang)
78 log.info(
"Qt Detected Languages: {}".
format(QLocale().system().uiLanguages()))
79 log.info(
"LANG Environment Variable: {}".
format(os.environ.get(
'LANG', QLocale().system().
name())))
80 log.info(
"LOCALE Environment Variable: {}".
format(os.environ.get(
'LOCALE', QLocale().system().
name())))
83 locale.setlocale(locale.LC_ALL,
'C')
86 found_language =
False 87 for locale_name
in locale_names:
90 if 'en_US' in locale_name:
91 log.info(
"Skipping English language (no need for translation): {}".
format(locale_name))
95 for type
in translator_types:
96 trans = QTranslator(app)
99 app.installTranslator(trans)
100 found_language =
True 104 log.info(
"Exiting translation system (since we successfully loaded: {})".
format(locale_name))
113 app = QCoreApplication.instance()
119 "path": QLibraryInfo.location(QLibraryInfo.TranslationsPath)},
121 "pattern": os.path.join(
'%s',
'LC_MESSAGES',
'OpenShot'),
122 "path": os.path.join(info.PATH,
'locale')},
126 locale_names = [os.environ.get(
'LANG', QLocale().system().
name()),
127 os.environ.get(
'LOCALE', QLocale().system().
name())
131 found_language =
False 132 for locale_name
in locale_names:
135 if 'en_US' in locale_name:
139 for type
in translator_types:
140 trans = QTranslator(app)
142 found_language =
True 146 return locale_name.replace(
".UTF8",
"").replace(
".UTF-8",
"")
161 locale_parts = locale_name.split(
'_')
163 i = len(locale_parts)
164 while not success
and i > 0:
165 formatted_name = pattern %
"_".join(locale_parts[:i])
166 log.info(
'Attempting to load {} in \'{}\''.
format(formatted_name, path))
167 success = translator.load(formatted_name, path)
169 log.info(
'Successfully loaded {} in \'{}\''.
format(formatted_name, path))
179 app = QCoreApplication.instance()
183 for locale_name
in info.SUPPORTED_LANGUAGES:
184 native_lang_name = QLocale(locale_name).nativeLanguageName().title()
185 country_name = QLocale(locale_name).nativeCountryName().title()
186 all_languages.append((locale_name, native_lang_name, country_name))
def get_all_languages()
Get all language names and countries packaged with OpenShot.
def init_language()
Find the current locale, and install the correct translators.
def get_current_locale()
Get the current locale name from the current system.
def get_settings()
Get the current QApplication's settings instance.
def find_language_match(pattern, path, translator, locale_name)
Match all combinations of locale, language, and country.