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 test_properties_decode_slashu(): # The real input strings don't have double backslashes, but we have to # double them here because Python immediately decode them, even for raw # strings. assert quote.propertiesdecode("abc\\u1e13") == "abcḓ" assert quote.propertiesdecode("abc\\u0020") == "abc " # NOTE Java only accepts 4 digit unicode, Mozilla accepts two # unfortunately, but it seems harmless to accept both. assert quote.propertiesdecode("abc\\u20") == "abc "
def test_properties_decode_slashu(self): # The real input strings don't have double backslashes, but we have to # double them here because Python immediately decode them, even for raw # strings. assert quote.propertiesdecode(u"abc\\u1e13") == u"abcḓ" assert quote.propertiesdecode(u"abc\\u0020") == u"abc " # NOTE Java only accepts 4 digit unicode, Mozilla accepts two # unfortunately, but it seems harmless to accept both. assert quote.propertiesdecode("abc\\u20") == u"abc "
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 target(self): """Return target string from a ttkit unit.""" if self.unit is None: return '' # Need to decode property encoded string # 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
def test_propertiesdecode(): assert quote.propertiesdecode("abc") == "abc" assert quote.propertiesdecode("abc\\u1e13") == "abcḓ" assert quote.propertiesdecode("abc\\u1E13") == "abcḓ" assert quote.propertiesdecode("abc\N{LEFT CURLY BRACKET}") == "abc{" assert quote.propertiesdecode("abc\\") == "abc\\" assert quote.propertiesdecode("abc\\") == "abc\\"
def test_propertiesdecode(self): assert quote.propertiesdecode(u"abc") == u"abc" assert quote.propertiesdecode(u"abc\\u1e13") == u"abcḓ" assert quote.propertiesdecode(u"abc\\u1E13") == u"abcḓ" assert quote.propertiesdecode(u"abc\N{LEFT CURLY BRACKET}") == u"abc{" assert quote.propertiesdecode(u"abc\\") == u"abc\\" assert quote.propertiesdecode(u"abc\\") == u"abc\\"
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(unit): ''' Returns target string from a ttkit unit. ''' if unit is None: return '' if is_unit_key_value(unit): # Need to decode property encoded string if isinstance(unit, propunit): # This is basically stolen from # translate.storage.properties.propunit.gettarget # which for some reason does not return translation value = quote.propertiesdecode(unit.value) value = re.sub(u"\\\\ ", u" ", value) return value return unit.value else: if hasattr(unit.target, 'strings'): return join_plural(unit.target.strings) else: return 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 gettarget(self): return re.sub(u"\\\\ ", u" ", quote.propertiesdecode(self.translation))
def gettarget(self): translation = quote.propertiesdecode(self.translation) translation = re.sub(u"\\\\ ", u" ", translation) return translation
def getsource(self): value = quote.propertiesdecode(self.value) return value
def decode(cls, string): return quote.propertiesdecode(string)
def getsource(self): value = quote.propertiesdecode(self.value) value = re.sub(u"\\\\ ", u" ", value) return value
def getsource(self): return quote.propertiesdecode(self.value)
def test_properties_decode_slashu(self): assert quote.propertiesdecode(u"abc\u1e13") == u"abcḓ" assert quote.propertiesdecode(u"abc\u0020") == u"abc " # NOTE Java only accepts 4 digit unicode, Mozilla accepts two # unfortunately, but it seems harmless to accept both. assert quote.propertiesdecode("abc\u20") == u"abc "
def decode(string): return quote.propertiesdecode(string)
def source(self): # Need to decode property encoded string return quote.propertiesdecode(super(PropertiesUnit, self).source)
def source(self): # Need to decode property encoded string return quote.propertiesdecode( super(PropertiesUnit, self).source )