Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 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)
Example #6
0
 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)
Example #7
0
 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)
Example #8
0
 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)
Example #9
0
 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)
Example #10
0
 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)
Example #11
0
 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)
Example #12
0
 def get_source(self):
     if self.template is None:
         return self.mainunit.getid()
     return get_string(self.template.target)
Example #13
0
 def test_none(self):
     self.assertEqual(get_string(None), "")
Example #14
0
 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()
Example #15
0
 def target(self):
     """Return target string from a Translate Toolkit unit."""
     if self.unit is None:
         return ""
     return get_string(self.unit.target)
Example #16
0
 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)
Example #17
0
 def test_multistring(self):
     self.assertEqual(get_string(multistring(["foo", "bar"])),
                      "foo\x1e\x1ebar")
Example #18
0
 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)
Example #19
0
 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
Example #20
0
 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)
Example #21
0
 def target(self):
     if self.unit is None:
         return ""
     return get_string(self.unit.source)
Example #22
0
 def source(self):
     if self.template is not None:
         return get_string(self.template.source)
     return self.unit.getid()
Example #23
0
 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)
Example #24
0
 def test_surrogates(self):
     self.assertEqual(get_string("\ud83d\udc68\u200d\ud83d\udcbbАгенты"),
                      "👨‍💻Агенты")
Example #25
0
 def target(self):
     """Return target string from a ttkit unit."""
     if self.unit is None:
         return ''
     return get_string(self.unit.target)
Example #26
0
 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)
Example #27
0
 def test_int(self):
     self.assertEqual(get_string(42), "42")
Example #28
0
 def source(self):
     if self.template is None:
         return self.mainunit.getid()
     return get_string(self.template.target)
Example #29
0
 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)
Example #30
0
 def target(self):
     """Return target string from a ttkit unit."""
     if self.unit is None:
         return ''
     return get_string(self.unit.target)
Example #31
0
 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)