def check_unit(self, nplurals=3, template=None, source_info=None, **kwargs): if nplurals == 3: formula = "n==0 ? 0 : n==1 ? 1 : 2" else: formula = "0" lang = Language.objects.create(code="zz") plural = Plural.objects.create(language=lang, number=nplurals, formula=formula) project = Project(slug="test") component = Component( slug="comp", project=project, file_format="xliff", template=template, source_language=Language.objects.get(code="en"), ) translation = Translation(language=lang, component=component, plural=plural) # Fake file format to avoid need for actual files translation.store = EmptyFormat(BytesIOMode("", b"")) unit = Unit(translation=translation, id_hash=-1, **kwargs) if source_info: for key, value in source_info.items(): setattr(unit, key, value) # The dashes need special handling in XML based formats unit.__dict__["unresolved_comments"] = [ Comment(comment="Weblate translator comment ---- ") ] unit.__dict__["suggestions"] = [ Suggestion(target="Weblate translator suggestion") ] else: unit.__dict__["unresolved_comments"] = [] unit.source_unit = unit exporter = self.get_exporter(lang, translation=translation) exporter.add_unit(unit) return self.check_export(exporter)
def check_unit(self, nplurals=3, template=None, source_info=None, **kwargs): if nplurals == 3: equation = "n==0 ? 0 : n==1 ? 1 : 2" else: equation = "0" lang = Language.objects.create(code="zz") plural = Plural.objects.create( language=lang, number=nplurals, equation=equation ) project = Project(slug="test", source_language=Language.objects.get(code="en")) component = Component( slug="comp", project=project, file_format="xliff", template=template ) translation = Translation(language=lang, component=component, plural=plural) # Fake file format to avoid need for actual files translation.store = EmptyFormat(BytesIOMode("", b"")) unit = Unit(translation=translation, id_hash=-1, **kwargs) if source_info: for key, value in source_info.items(): setattr(unit, key, value) unit.get_comments = fake_get_comments unit.__dict__["suggestions"] = [ Suggestion(target="Weblate translator suggestion") ] else: unit.get_comments = empty_get_comments exporter = self.get_exporter(lang, translation=translation) exporter.add_unit(unit) return self.check_export(exporter)
def check_unit(self, nplurals=3, template=None, **kwargs): if nplurals == 3: equation = 'n==0 ? 0 : n==1 ? 1 : 2' else: equation = '0' lang = Language.objects.create( code='zz', ) plural = Plural.objects.create( language=lang, number=nplurals, equation=equation ) project = Project( slug='test', source_language=Language.objects.get(code='en'), ) component = Component( slug='comp', project=project, file_format='xliff', template=template ) translation = Translation( language=lang, component=component, plural=plural, ) # Fake file format to avoid need for actual files translation.store = EmptyFormat(BytesIOMode('', b'')) unit = Unit(translation=translation, id_hash=-1, **kwargs) exporter = self.get_exporter(lang, translation=translation) exporter.add_unit(unit) return self.check_export(exporter)
def check_unit(self, nplurals=3, template=None, source_info=None, **kwargs): if nplurals == 3: equation = 'n==0 ? 0 : n==1 ? 1 : 2' else: equation = '0' lang = Language.objects.create(code='zz', ) plural = Plural.objects.create(language=lang, number=nplurals, equation=equation) project = Project( slug='test', source_language=Language.objects.get(code='en'), ) component = Component(slug='comp', project=project, file_format='xliff', template=template) translation = Translation( language=lang, component=component, plural=plural, ) # Fake file format to avoid need for actual files translation.store = EmptyFormat(BytesIOMode('', b'')) unit = Unit(translation=translation, id_hash=-1, **kwargs) if source_info: for key, value in source_info.items(): setattr(unit, key, value) unit.get_comments = fake_get_comments unit.__dict__['suggestions'] = [ Suggestion(target='Weblate translator suggestion') ] else: unit.get_comments = empty_get_comments exporter = self.get_exporter(lang, translation=translation) exporter.add_unit(unit) return self.check_export(exporter)