def test(self) -> None: assets_directory_path = Path(__file__).parents[3] / 'assets' for locale_path_name in listdir(assets_directory_path / 'locale'): locale = locale_path_name.replace('_', '-') self.assertIsInstance( open_translations(locale, assets_directory_path), gettext.NullTranslations)
def _init_translations(self) -> None: self._translations['en-US'] = gettext.NullTranslations() for locale in self._configuration.locales: for assets_path in reversed(self._assets.paths): translations = open_translations(locale, assets_path) if translations: translations.add_fallback(self._translations[locale]) self._translations[locale] = translations
def translations(self) -> Dict[str, gettext.NullTranslations]: if len(self._translations) == 0: self._translations['en-US'] = gettext.NullTranslations() for locale_configuration in self._configuration.locales: for assets_path, _ in reversed(self._assets.paths): translations = open_translations( locale_configuration.locale, assets_path) if translations: translations.add_fallback( self._translations[locale_configuration]) self._translations[locale_configuration] = translations return self._translations
def _init_translations(self) -> None: self._translations['en-US'] = gettext.NullTranslations() for locale in self._configuration.locales: for resources_path in reversed(self._resources.paths): translations = open_translations(locale, resources_path) if translations: translations.add_fallback(self._translations[locale]) self._translations[locale] = translations try: self.translations[self._configuration.default_locale].install() except KeyError: logger = logging.getLogger() logger.debug('No translations found for default locale %s.' % self._configuration.default_locale)
def test(self) -> None: locale = 'nl-NL' locale_path_name = 'nl_NL' with TemporaryDirectory() as assets_directory_path: lc_messages_directory_path = path.join(assets_directory_path, 'locale', locale_path_name, 'LC_MESSAGES') makedirs(lc_messages_directory_path) po = """ # Dutch translations for PROJECT. # Copyright (C) 2019 ORGANIZATION # This file is distributed under the same license as the PROJECT project. # FIRST AUTHOR <EMAIL@ADDRESS>, 2019. # msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" "POT-Creation-Date: 2020-11-18 23:28+0000\n" "PO-Revision-Date: 2019-10-05 11:38+0100\n" "Last-Translator: \n" "Language: nl\n" "Language-Team: nl <*****@*****.**>\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.7.0\n" #: betty/ancestry.py:457 msgid "Subject" msgstr "Onderwerp" """ with open(path.join(lc_messages_directory_path, 'betty.po'), 'w') as f: f.write(po) self.assertIsInstance( open_translations(locale, assets_directory_path), gettext.NullTranslations)
def test(self) -> None: for locale_path_name in listdir(path.join(_ASSETS_DIRECTORY_PATH, 'locale')): locale = locale_path_name.replace('_', '-') self.assertIsInstance(open_translations(locale, _ASSETS_DIRECTORY_PATH), gettext.NullTranslations)