def test_get_catalogs_for_xx_without_outdated(dir): (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.mo').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.mo').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test3.pot').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test3.mo').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.mo').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test5.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test5.mo').write_text('#') catalogs = i18n.get_catalogs([dir / 'loc1'], 'xx', force_all=False) assert not catalogs catalogs = i18n.get_catalogs([dir / 'loc1'], 'xx', force_all=True) domains = set(c.domain for c in catalogs) assert domains == set([ 'test1', 'test2', path.normpath('sub/test4'), path.normpath('sub/test5'), ])
def test_get_catalogs_for_xx_without_outdated(dir): (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.mo').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.mo').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test3.pot').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test3.mo').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.mo').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test5.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test5.mo').write_text('#') catalogs = i18n.get_catalogs([dir / 'loc1'], 'xx', force_all=False) assert not catalogs catalogs = i18n.get_catalogs([dir / 'loc1'], 'xx', force_all=True) domains = set(c.domain for c in catalogs) assert domains == set([ 'test1', 'test2', path.normpath('sub/test4'), path.normpath('sub/test5'), ])
def compile_update_catalogs(self): catalogs = i18n.get_catalogs( [path.join(self.srcdir, x) for x in self.config.locale_dirs], self.config.language) message = 'targets for %d po files that are out of date' % len( catalogs) self.compile_catalogs(catalogs, message)
def test_get_catalogs_for_en(dir): (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'xx_dom.po').write_text('#') (dir / 'loc1' / 'en' / 'LC_MESSAGES').makedirs() (dir / 'loc1' / 'en' / 'LC_MESSAGES' / 'en_dom.po').write_text('#') catalogs = i18n.get_catalogs([dir / 'loc1'], 'en', force_all=False) domains = set(c.domain for c in catalogs) assert domains == set(['en_dom'])
def test_get_catalogs_for_en(dir): (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'xx_dom.po').write_text('#') (dir / 'loc1' / 'en' / 'LC_MESSAGES').makedirs() (dir / 'loc1' / 'en' / 'LC_MESSAGES' / 'en_dom.po').write_text('#') catalogs = i18n.get_catalogs([dir / 'loc1'], 'en', force_all=False) domains = set(c.domain for c in catalogs) assert domains == set(['en_dom'])
def test_get_catalogs_from_multiple_locale_dirs(dir): (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#') (dir / 'loc2' / 'xx' / 'LC_MESSAGES').makedirs() (dir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#') (dir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#') catalogs = i18n.get_catalogs([dir / 'loc1', dir / 'loc2'], 'xx') domains = sorted(c.domain for c in catalogs) assert domains == ['test1', 'test1', 'test2']
def test_get_catalogs_from_multiple_locale_dirs(dir): (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#') (dir / 'loc2' / 'xx' / 'LC_MESSAGES').makedirs() (dir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#') (dir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#') catalogs = i18n.get_catalogs([dir / 'loc1', dir / 'loc2'], 'xx') domains = sorted(c.domain for c in catalogs) assert domains == ['test1', 'test1', 'test2']
def test_get_catalogs_with_compact(dir): (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test3.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#') catalogs = i18n.get_catalogs([dir / 'loc1'], 'xx', gettext_compact=True) domains = set(c.domain for c in catalogs) assert domains == set(['test1', 'test2', 'sub'])
def test_get_catalogs_with_compact(dir): (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test3.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#') catalogs = i18n.get_catalogs([dir / 'loc1'], 'xx', gettext_compact=True) domains = set(c.domain for c in catalogs) assert domains == set(['test1', 'test2', 'sub'])
def compile_specific_catalogs(self, specified_files): def to_domain(fpath): docname, _ = path.splitext(path_stabilize(fpath)) dom = find_catalog(docname, self.config.gettext_compact) return dom specified_domains = set(map(to_domain, specified_files)) catalogs = i18n.get_catalogs( [path.join(self.srcdir, x) for x in self.config.locale_dirs], self.config.language, True) catalogs = [f for f in catalogs if f.domain in specified_domains] message = 'targets for %d po files that are specified' % len(catalogs) self.compile_catalogs(catalogs, message)
def compile_specific_catalogs(self, specified_files): def to_domain(fpath): docname, _ = path.splitext(path_stabilize(fpath)) dom = find_catalog(docname, self.config.gettext_compact) return dom specified_domains = set(map(to_domain, specified_files)) catalogs = i18n.get_catalogs( [path.join(self.srcdir, x) for x in self.config.locale_dirs], self.config.language, True) catalogs = [f for f in catalogs if f.domain in specified_domains] message = 'targets for %d po files that are specified' % len(catalogs) self.compile_catalogs(catalogs, message)
def test_get_catalogs_for_xx(dir): (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test3.pot').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test5.po').write_text('#') (dir / 'loc1' / 'en' / 'LC_MESSAGES').makedirs() (dir / 'loc1' / 'en' / 'LC_MESSAGES' / 'test6.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_ALL').makedirs() (dir / 'loc1' / 'xx' / 'LC_ALL' / 'test7.po').write_text('#') catalogs = i18n.get_catalogs([dir / 'loc1'], 'xx', force_all=False) domains = set(c.domain for c in catalogs) assert domains == set([ 'test1', 'test2', path.normpath('sub/test4'), path.normpath('sub/test5'), ])
def test_get_catalogs_for_xx(dir): (dir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test3.pot').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub').makedirs() (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test5.po').write_text('#') (dir / 'loc1' / 'en' / 'LC_MESSAGES').makedirs() (dir / 'loc1' / 'en' / 'LC_MESSAGES' / 'test6.po').write_text('#') (dir / 'loc1' / 'xx' / 'LC_ALL').makedirs() (dir / 'loc1' / 'xx' / 'LC_ALL' / 'test7.po').write_text('#') catalogs = i18n.get_catalogs([dir / 'loc1'], 'xx', force_all=False) domains = set(c.domain for c in catalogs) assert domains == set([ 'test1', 'test2', path.normpath('sub/test4'), path.normpath('sub/test5'), ])
def test_get_catalogs_with_non_existent_locale_dirs(): catalogs = i18n.get_catalogs(['dummy'], 'xx') assert not catalogs
def compile_all_catalogs(self): catalogs = i18n.get_catalogs( [path.join(self.srcdir, x) for x in self.config.locale_dirs], self.config.language, True) message = 'all of %d po files' % len(catalogs) self.compile_catalogs(catalogs, message)
def compile_update_catalogs(self): catalogs = i18n.get_catalogs( [path.join(self.srcdir, x) for x in self.config.locale_dirs], self.config.language) message = 'targets for %d po files that are out of date' % len(catalogs) self.compile_catalogs(catalogs, message)
def compile_all_catalogs(self): catalogs = i18n.get_catalogs( [path.join(self.srcdir, x) for x in self.config.locale_dirs], self.config.language, True) message = 'all of %d po files' % len(catalogs) self.compile_catalogs(catalogs, message)
def test_get_catalogs_with_non_existent_locale(dir): catalogs = i18n.get_catalogs([dir / 'loc1'], 'xx') assert not catalogs catalogs = i18n.get_catalogs([dir / 'loc1'], None) assert not catalogs
def test_get_catalogs_with_non_existent_locale(dir): catalogs = i18n.get_catalogs([dir / 'loc1'], 'xx') assert not catalogs catalogs = i18n.get_catalogs([dir / 'loc1'], None) assert not catalogs
def test_get_catalogs_with_non_existent_locale_dirs(): catalogs = i18n.get_catalogs(['dummy'], 'xx') assert not catalogs