예제 #1
0
 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()
예제 #2
0
 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",
     )
예제 #3
0
 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()
예제 #4
0
 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)
예제 #5
0
 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'),
     )
예제 #6
0
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)
예제 #7
0
 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.",
     )
예제 #8
0
 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)
예제 #10
0
 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)
예제 #11
0
 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)
예제 #12
0
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)
예제 #13
0
 def test_arrows(self):
     self.check_chars(Language(code="cs"), 12, ["→", "⇒"], source="→⇒→⇒")
예제 #14
0
 def test_cs(self):
     chars = list(get_special_chars(Language(code="cs")))
     self.assertEqual(len(chars), 10)
예제 #15
0
 def test_arrows_rtl(self):
     self.check_chars(
         Language(code='ar', direction='rtl'), 12, ['←', '⇐'], source='→⇒→⇒'
     )
예제 #16
0
 def test_arrows(self):
     self.check_chars(Language(code='cs'), 11, ['→', '⇒'], source='→⇒→⇒')
예제 #17
0
 def test_additional(self):
     self.check_chars(
         Language(code='cs'), 13, ['a', 'h', 'o', 'j'], additional='ahoj'
     )
예제 #18
0
 def test_settings(self):
     chars = list(get_special_chars(Language(code='cs')))
     self.assertEqual(len(chars), 262)
예제 #19
0
 def test_brx_add(self):
     chars = list(get_special_chars(Language(code='brx'), 'ahoj'))
     self.assertEqual(len(chars), 13)
예제 #20
0
 def test_brx(self):
     chars = list(get_special_chars(Language(code='brx')))
     self.assertEqual(len(chars), 9)
예제 #21
0
 def test_af(self):
     chars = list(get_special_chars(Language(code='af')))
     self.assertEqual(len(chars), 10)
예제 #22
0
 def test_additional(self):
     self.check_chars(Language(code="cs"),
                      14, ["a", "h", "o", "j"],
                      additional="ahoj")
예제 #23
0
 def test_brx_add(self):
     chars = list(get_special_chars(Language(code="brx"), "ahoj"))
     self.assertEqual(len(chars), 14)
예제 #24
0
 def test_arrows_rtl(self):
     self.check_chars(Language(code="ar", direction="rtl"),
                      13, ["←", "⇐"],
                      source="→⇒→⇒")
예제 #25
0
 def get_exporter(self):
     return self._class(
         language=Language(code='xx'),
         project=Project(slug='test', name='TEST'),
     )