コード例 #1
0
 def convertelement(self, theoo):
     """convert an oo element into a list of base units (.po or XLIFF)"""
     if self.sourcelanguage in theoo.languages:
         part1 = theoo.languages[self.sourcelanguage]
     else:
         logging.error(
             "/".join(theoo.lines[0].getkey()) + "language not found: %s",
             self.sourcelanguage)
         return []
     if self.blankmsgstr:
         # use a blank part2
         part2 = oo.ooline()
     else:
         if self.targetlanguage in theoo.languages:
             part2 = theoo.languages[self.targetlanguage]
         else:
             # if the language doesn't exist, the translation is missing ... so make it blank
             part2 = oo.ooline()
     if "x-comment" in theoo.languages:
         translators_comment = theoo.languages["x-comment"]
     else:
         translators_comment = oo.ooline()
     key = oo.makekey(part1.getkey(), self.long_keys)
     unitlist = []
     for subkey in ("text", "quickhelptext", "title"):
         unit = self.maketargetunit(part1, part2, translators_comment, key,
                                    subkey)
         if unit is not None:
             unitlist.append(unit)
     return unitlist
コード例 #2
0
ファイル: oo2xliff.py プロジェクト: flyeven/translate
 def convertelement(self, theoo):
     """convert an oo element into a list of base units (.po or XLIFF)"""
     if self.sourcelanguage in theoo.languages:
         part1 = theoo.languages[self.sourcelanguage]
     else:
         logging.error("/".join(theoo.lines[0].getkey()) +
                       "language not found: %s", self.sourcelanguage)
         return []
     if self.blankmsgstr:
         # use a blank part2
         part2 = oo.ooline()
     else:
         if self.targetlanguage in theoo.languages:
             part2 = theoo.languages[self.targetlanguage]
         else:
             # if the language doesn't exist, the translation is missing ... so make it blank
             part2 = oo.ooline()
     if "x-comment" in theoo.languages:
         translators_comment = theoo.languages["x-comment"]
     else:
         translators_comment = oo.ooline()
     key = oo.makekey(part1.getkey(), self.long_keys)
     unitlist = []
     for subkey in ("text", "quickhelptext", "title"):
         unit = self.maketargetunit(part1, part2, translators_comment, key, subkey)
         if unit is not None:
             unitlist.append(unit)
     return unitlist
コード例 #3
0
 def applytranslation(self, key, subkey, theoo, unit):
     """applies the translation from the source unit to the oo unit"""
     if not self.includefuzzy and unit.isfuzzy():
         return
     makecopy = False
     if self.languages is None:
         part1 = theoo.lines[0]
         if len(theoo.lines) > 1:
             part2 = theoo.lines[1]
         else:
             makecopy = True
     else:
         part1 = theoo.languages[self.languages[0]]
         if self.languages[1] in theoo.languages:
             part2 = theoo.languages[self.languages[1]]
         else:
             makecopy = True
     if makecopy:
         part2 = oo.ooline(part1.getparts())
     unquotedid = unit.source
     unquotedstr = unit.target
     # If there is no translation, we don't want to add a line
     if len(unquotedstr) == 0:
         return
     # finally set the new definition in the oo, but not if its empty
     if len(unquotedstr) > 0:
         setattr(part2, subkey, unquotedstr)
     # set the modified time
     if self.timestamp_str:
         part2.timestamp = self.timestamp_str
     if self.languages:
         part2.languageid = self.languages[1]
     if makecopy:
         theoo.addline(part2)
コード例 #4
0
ファイル: po2oo.py プロジェクト: XLeonardo/translate-1
 def applytranslation(self, key, subkey, theoo, unit):
     """applies the translation from the source unit to the oo unit"""
     if not self.includefuzzy and unit.isfuzzy():
         return
     makecopy = False
     if self.languages is None:
         part1 = theoo.lines[0]
         if len(theoo.lines) > 1:
             part2 = theoo.lines[1]
         else:
             makecopy = True
     else:
         part1 = theoo.languages[self.languages[0]]
         if self.languages[1] in theoo.languages:
             part2 = theoo.languages[self.languages[1]]
         else:
             makecopy = True
     if makecopy:
         part2 = oo.ooline(part1.getparts())
     unquotedid = unit.source
     unquotedstr = unit.target
     # If there is no translation, we don't want to add a line
     if len(unquotedstr) == 0:
         return
     # finally set the new definition in the oo, but not if its empty
     if len(unquotedstr) > 0:
         setattr(part2, subkey, unquotedstr)
     # set the modified time
     if self.timestamp_str:
         part2.timestamp = self.timestamp_str
     if self.languages:
         part2.languageid = self.languages[1]
     if makecopy:
         theoo.addline(part2)