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 QLocale().system().
name()
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))
105 info.CURRENT_LANGUAGE = locale_name
114 app = QCoreApplication.instance()
120 "path": QLibraryInfo.location(QLibraryInfo.TranslationsPath)},
122 "pattern": os.path.join(
'%s',
'LC_MESSAGES',
'OpenShot'),
123 "path": os.path.join(info.PATH,
'locale')},
127 locale_names = [os.environ.get(
'LANG', QLocale().system().
name()),
128 os.environ.get(
'LOCALE', QLocale().system().
name())
132 found_language =
False
133 for locale_name
in locale_names:
136 if 'en_US' in locale_name:
140 for type
in translator_types:
141 trans = QTranslator(app)
143 found_language =
True
147 return locale_name.replace(
".UTF8",
"").replace(
".UTF-8",
"")
162 locale_parts = locale_name.split(
'_')
164 i = len(locale_parts)
165 while not success
and i > 0:
166 formatted_name = pattern %
"_".join(locale_parts[:i])
167 log.info(
'Attempting to load {} in \'{}\''.format(formatted_name, path))
168 success = translator.load(formatted_name, path)
170 log.info(
'Successfully loaded {} in \'{}\''.format(formatted_name, path))
180 app = QCoreApplication.instance()
184 for locale_name
in info.SUPPORTED_LANGUAGES:
186 native_lang_name = QLocale(locale_name).nativeLanguageName().title()
187 country_name = QLocale(locale_name).nativeCountryName().title()
188 all_languages.append((locale_name, native_lang_name, country_name))
def find_language_match
Match all combinations of locale, language, and country.
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_all_languages
Get all language names and countries packaged with OpenShot.
def get_settings
Get the current QApplication's settings instance.