def setUp(self): self.unit = Unit(translation=Translation( component=Component( project=Project(source_language=Language(), slug="p", name="p"), slug="c", name="c", ), language=Language(), )) self.profile = Profile()
def test_description(self): unit = Unit( source="string", target="I have two two lemons lemons", translation=Translation( language=Language("cs"), component=Component(source_language=Language("en")), ), ) check = Check(unit=unit) self.assertEqual( self.check.get_description(check), "Text contains the same word twice in a row: lemons, two", )
def test_add_encoding(self): out = tempfile.NamedTemporaryFile() self.FORMAT.add_language(out.name, Language(code='cs', nplurals=2), TEST_POT_UNICODE) data = out.read().decode('utf-8') self.assertTrue('Michal Čihař' in data) out.close()
def check_unit(self, nplurals=3, **kwargs): if nplurals == 3: equation = 'n==0 ? 0 : n==1 ? 1 : 2' else: equation = '0' lang = Language( code='zz', nplurals=nplurals, pluralequation=equation ) project = Project( slug='test', source_language=Language.objects.get(code='en'), ) subproject = SubProject(slug='comp', project=project) unit = Unit( translation=Translation( language=lang, subproject=subproject ), **kwargs ) exporter = self.get_exporter(lang) exporter.add_unit(unit) return self.check_export(exporter)
def get_exporter(self, lang=None): if lang is None: lang = Language(code='xx') return self._class( language=lang, project=Project(slug='test', name='TEST'), )
def validate_render_component(value, translation=None, **kwargs): from weblate.trans.models import Project, Component, Translation from weblate.lang.models import Language component = Component( project=Project( name='project', slug='project', id=-1, ), name='component', slug='component', branch='master', vcs='git', id=-1, ) if translation: kwargs['translation'] = Translation( id=-1, component=component, language_code='xx', language=Language(name='xxx', code='xx'), ) else: kwargs['component'] = component validate_render(value, **kwargs)
def test_description(self): unit = Unit( source="{0}''s brush is {1} centimeters tall", target="{0}'s brush is {1} centimeters tall", extra_flags="java-messageformat", translation=Translation( component=Component( file_format="auto", source_language=Language("en"), ), language=Language("cs"), ), ) check = Check(unit=unit) self.assertEqual( self.check.get_description(check), "You need to pair up an apostrophe with another one.", )
def test_add(self): if self.FORMAT.supports_new_language(): self.assertTrue(self.FORMAT.is_valid_base_for_new(self.BASE)) out = tempfile.NamedTemporaryFile(suffix='.{0}'.format(self.EXT), mode='w+') self.FORMAT.add_language(out.name, Language(code='cs'), self.BASE) data = out.read() self.assertTrue(self.MATCH in data) out.close()
def test_add_encoding(self): out = os.path.join(self.tempdir, 'test.po') self.FORMAT.add_language( out, Language(code='cs', nplurals=2), TEST_POT_UNICODE ) with open(out, 'rb') as handle: data = handle.read().decode('utf-8') self.assertTrue('Michal Čihař' in data)
def test_add(self): self.assertTrue(self.FORMAT.is_valid_base_for_new(self.BASE)) out = os.path.join(self.tempdir, 'test.{0}'.format(self.EXT)) self.FORMAT.add_language( out, Language(code='cs', nplurals=2), self.BASE ) with open(out, 'r') as handle: data = handle.read() self.assertTrue(self.MATCH in data)
def check_unit(self, nplurals=3, **kwargs): lang = Language(code='zz', nplurals=nplurals) project = Project( slug='test', source_language=Language.objects.get(code='en'), ) subproject = SubProject(slug='comp', project=project) unit = Unit(translation=Translation(language=lang, subproject=subproject), **kwargs) exporter = self.get_exporter() exporter.add_unit(unit) return self.check_export(exporter)
def validate_render_component(value, translation=None, **kwargs): from weblate.lang.models import Language from weblate.trans.models import Component, Project, Translation component = Component( project=Project(name="project", slug="project", id=-1), name="component", slug="component", branch="main", vcs="git", id=-1, ) if translation: kwargs["translation"] = Translation( id=-1, component=component, language_code="xx", language=Language(name="xxx", code="xx"), ) else: kwargs["component"] = component validate_render(value, **kwargs)
def test_arrows(self): self.check_chars(Language(code="cs"), 12, ["→", "⇒"], source="→⇒→⇒")
def test_cs(self): chars = list(get_special_chars(Language(code="cs"))) self.assertEqual(len(chars), 10)
def test_arrows_rtl(self): self.check_chars( Language(code='ar', direction='rtl'), 12, ['←', '⇐'], source='→⇒→⇒' )
def test_arrows(self): self.check_chars(Language(code='cs'), 11, ['→', '⇒'], source='→⇒→⇒')
def test_additional(self): self.check_chars( Language(code='cs'), 13, ['a', 'h', 'o', 'j'], additional='ahoj' )
def test_settings(self): chars = list(get_special_chars(Language(code='cs'))) self.assertEqual(len(chars), 262)
def test_brx_add(self): chars = list(get_special_chars(Language(code='brx'), 'ahoj')) self.assertEqual(len(chars), 13)
def test_brx(self): chars = list(get_special_chars(Language(code='brx'))) self.assertEqual(len(chars), 9)
def test_af(self): chars = list(get_special_chars(Language(code='af'))) self.assertEqual(len(chars), 10)
def test_additional(self): self.check_chars(Language(code="cs"), 14, ["a", "h", "o", "j"], additional="ahoj")
def test_brx_add(self): chars = list(get_special_chars(Language(code="brx"), "ahoj")) self.assertEqual(len(chars), 14)
def test_arrows_rtl(self): self.check_chars(Language(code="ar", direction="rtl"), 13, ["←", "⇐"], source="→⇒→⇒")
def get_exporter(self): return self._class( language=Language(code='xx'), project=Project(slug='test', name='TEST'), )