def test_catalog_write_mo(tempdir): (tempdir / 'test.po').write_text('#') cat = i18n.CatalogInfo(tempdir, 'test', 'utf-8') cat.write_mo('en', lambda *a, **kw: None) assert os.path.exists(cat.mo_path) with open(cat.mo_path, 'rb') as f: assert read_mo(f) is not None
def test_catalog_write_mo(dir): (dir / 'test.po').write_text('#') cat = i18n.CatalogInfo(dir, 'test', 'utf-8') cat.write_mo('en') assert path.exists(cat.mo_path) with open(cat.mo_path, 'rb') as f: assert read_mo(f) is not None
def _get_translations(): translations = [] locale = request.factory.config.locales.get(sent_locale) catalog = read_mo(open(locale.get('path'), 'rb')) for msg in list(catalog)[1:]: translations.append( {'msgid': msg.id, 'msgstr': msg.string and msg.string or msg.id}) return translations
def test_basics(self): mo_path = os.path.join(self.datadir, 'project', 'i18n', 'de', 'LC_MESSAGES', 'messages.mo') with open(mo_path, 'rb') as mo_file: catalog = mofile.read_mo(mo_file) self.assertEqual(2, len(catalog)) self.assertEqual('TestProject', catalog.project) self.assertEqual('0.1', catalog.version) self.assertEqual('Stange', catalog['bar'].string) self.assertEqual(['Fuhstange', 'Fuhstangen'], catalog['foobar'].string)
def test_basics(self): mo_file = open(os.path.join(self.datadir, "project", "i18n", "de", "LC_MESSAGES", "messages.mo")) try: catalog = mofile.read_mo(mo_file) self.assertEqual(2, len(catalog)) self.assertEqual("TestProject", catalog.project) self.assertEqual("0.1", catalog.version) self.assertEqual("Stange", catalog["bar"].string) self.assertEqual(["Fuhstange", "Fuhstangen"], catalog["foobar"].string) finally: mo_file.close()
def setup_locales(self): for locale in listdir(LOCALES_DIR): locale_dir = join(LOCALES_DIR, locale) if not isdir(locale_dir): continue try: l = Locale.parse(locale) except UnknownLocaleError: continue mo_file = join(LOCALES_DIR, locale, 'LC_MESSAGES', 'messages.mo') if not isfile(mo_file): continue self.languages.append(Language(locale, l.display_name)) self.locales[locale] = [] catalog = read_mo(open(mo_file, 'rb')) for msg in list(catalog)[1:]: self.locales[locale].append( Translation(msg.id, msg.string and msg.string or msg.id) ) self.languages.sort(key=lambda x: x.display_name.lower())