def get_source(self): ''' Returns source string from a ttkit unit. ''' if (isinstance(self.mainunit, tsunit) and self.template is None and self.mainunit.hasplural()): # Need to apply special magic for plurals here # as there is no singlular/plural in the source string return join_plural([ self.unit.source, self.unit.source, ]) if self.is_unit_key_value(): # Need to decode property encoded string if isinstance(self.mainunit, propunit): if self.template is not None: return quote.propertiesdecode(self.template.value) else: return quote.propertiesdecode(self.unit.name) if self.template is not None: return self.template.value else: return self.unit.name else: if self.template is not None: return get_string(self.template.target) else: return get_string(self.unit.source)
def get_source(self): """Return source string from a ttkit unit.""" if self.is_unit_key_value(self.mainunit): # Need to decode property encoded string if isinstance(self.mainunit, propunit): if self.template is not None: return quote.propertiesdecode(self.template.value) return quote.propertiesdecode(self.unit.name) if self.template is not None: return self.template.value return self.unit.name else: if self.template is not None: return get_string(self.template.target) return get_string(self.unit.source)
def get_previous_source(self): """ Returns previous message source if there was any. """ if not self.is_fuzzy() or not hasattr(self.unit, "prev_source"): return "" return get_string(self.unit.prev_source)
def get_previous_source(self): ''' Returns previous message source if there was any. ''' if not self.is_fuzzy() or not hasattr(self.unit, 'prev_source'): return '' return get_string(self.unit.prev_source)
def get_target(self): """Return target string from a ttkit unit.""" if self.unit is None: return '' if self.is_unit_key_value(self.unit): # Need to decode property encoded string if isinstance(self.unit, propunit): # This is basically stolen from # translate.storage.properties.propunit.gettarget # which for some reason does not return translation value = quote.propertiesdecode(self.unit.value) value = re.sub('\\\\ ', ' ', value) return value return self.unit.value return get_string(self.unit.target)
def get_target(self): """ Returns target string from a ttkit unit. """ if self.unit is None: return "" if isinstance(self.unit, tsunit) and not self.unit.isreview() and not self.unit.istranslated(): # For Qt ts, empty translated string means source should be used return self.get_source() if self.is_unit_key_value(): # Need to decode property encoded string if isinstance(self.unit, propunit): # This is basically stolen from # translate.storage.properties.propunit.gettarget # which for some reason does not return translation value = quote.propertiesdecode(self.unit.value) value = re.sub(u"\\\\ ", u" ", value) return value return self.unit.value else: return get_string(self.unit.target)
def get_target(self): ''' Returns target string from a ttkit unit. ''' if self.unit is None: return '' if (isinstance(self.unit, tsunit) and not self.unit.isreview() and not self.unit.istranslated()): # For Qt ts, empty translated string means source should be used return self.get_source() if self.is_unit_key_value(): # Need to decode property encoded string if isinstance(self.unit, propunit): # This is basically stolen from # translate.storage.properties.propunit.gettarget # which for some reason does not return translation value = quote.propertiesdecode(self.unit.value) value = re.sub(u"\\\\ ", u" ", value) return value return self.unit.value else: return get_string(self.unit.target)
def get_source(self): if self.template is None: return self.mainunit.getid() return get_string(self.template.target)
def test_none(self): self.assertEqual(get_string(None), "")
def get_source(self): # Needed to avoid translate-toolkit construct ID # as context\04source if self.template is None: return get_string(self.mainunit.source) return super(CSVUnit, self).get_source()
def target(self): """Return target string from a Translate Toolkit unit.""" if self.unit is None: return "" return get_string(self.unit.target)
def source(self): # Needed to avoid Translate Toolkit construct ID # as context\04source if self.template is None: return self.unescape_csv(get_string(self.mainunit.source)) return self.unescape_csv(super().source)
def test_multistring(self): self.assertEqual(get_string(multistring(["foo", "bar"])), "foo\x1e\x1ebar")
def source(self): """Return source string from a ttkit unit.""" if self.template is not None: return get_string(self.template.target) return get_string(self.unit.source)
def source(self): # Needed to avoid translate-toolkit construct ID # as context\04source if self.template is None: return get_string(self.mainunit.source) return super(CSVUnit, self).source
def _calculate_string_hash(self, context: str, source: str) -> int: """Calculates id hash for a string.""" return self.unit_class.calculate_id_hash( self.has_template or self.is_template, get_string(source), context)
def target(self): if self.unit is None: return "" return get_string(self.unit.source)
def source(self): if self.template is not None: return get_string(self.template.source) return self.unit.getid()
def source(self): """Return source string from a Translate Toolkit unit.""" if self.template is not None: return get_string(self.template.value) return get_string(self.unit.name)
def test_surrogates(self): self.assertEqual(get_string("\ud83d\udc68\u200d\ud83d\udcbbАгенты"), "👨💻Агенты")
def target(self): """Return target string from a ttkit unit.""" if self.unit is None: return '' return get_string(self.unit.target)
def previous_source(self): """Return previous message source if there was any.""" if not self.is_fuzzy(): return '' return get_string(self.unit.prev_source)
def test_int(self): self.assertEqual(get_string(42), "42")
def source(self): if self.template is None: return self.mainunit.getid() return get_string(self.template.target)