示例#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)
示例#2
0
文件: formats.py 项目: wandeg/weblate
 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)
示例#3
0
文件: base.py 项目: daleathan/weblate
 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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#8
0
文件: base.py 项目: daleathan/weblate
 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)
示例#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)
示例#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)
示例#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)
示例#12
0
 def get_source(self):
     if self.template is None:
         return self.mainunit.getid()
     return get_string(self.template.target)
示例#13
0
 def test_none(self):
     self.assertEqual(get_string(None), "")
示例#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()
示例#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)
示例#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)
示例#17
0
 def test_multistring(self):
     self.assertEqual(get_string(multistring(["foo", "bar"])),
                      "foo\x1e\x1ebar")
示例#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)
示例#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
示例#20
0
文件: base.py 项目: nijel/weblate
 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)
示例#21
0
 def target(self):
     if self.unit is None:
         return ""
     return get_string(self.unit.source)
示例#22
0
 def source(self):
     if self.template is not None:
         return get_string(self.template.source)
     return self.unit.getid()
示例#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)
示例#24
0
 def test_surrogates(self):
     self.assertEqual(get_string("\ud83d\udc68\u200d\ud83d\udcbbАгенты"),
                      "👨‍💻Агенты")
示例#25
0
文件: ttkit.py 项目: nijel/weblate
 def target(self):
     """Return target string from a ttkit unit."""
     if self.unit is None:
         return ''
     return get_string(self.unit.target)
示例#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)
示例#27
0
 def test_int(self):
     self.assertEqual(get_string(42), "42")
示例#28
0
 def source(self):
     if self.template is None:
         return self.mainunit.getid()
     return get_string(self.template.target)
示例#29
0
文件: ttkit.py 项目: nijel/weblate
 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)
示例#30
0
 def target(self):
     """Return target string from a ttkit unit."""
     if self.unit is None:
         return ''
     return get_string(self.unit.target)
示例#31
0
文件: ttkit.py 项目: nijel/weblate
 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)