Ejemplo n.º 1
0
 def getoutput(self):
     """convert the element back into formatted lines for a .properties file"""
     notes = self.getnotes()
     if notes:
         notes += u"\n"
     if self.isblank():
         return notes
     else:
         if "\\u" in self.value and self.personality == "mozilla":
             self.value = quote.mozillapropertiesencode(self.source)
         if "\\u" in self.translation and self.personality == "mozilla":
             self.translation = quote.mozillapropertiesencode(self.target)
         value = self.translation or self.value
         return u"%s%s%s%s\n" % (notes, self.name, self.delimiter, value)
Ejemplo n.º 2
0
 def getoutput(self):
     """convert the element back into formatted lines for a .properties file"""
     notes = self.getnotes()
     if notes:
         notes += u"\n"
     if self.isblank():
         return notes
     else:
         if "\\u" in self.value and self.personality == "mozilla":
             self.value = quote.mozillapropertiesencode(self.source)
         if "\\u" in self.translation and self.personality == "mozilla":
             self.translation = quote.mozillapropertiesencode(self.target)
         value = self.translation or self.value
         return u"%s%s%s%s\n" % (notes, self.name, self.delimeter, value)
Ejemplo n.º 3
0
 def settarget(self, target):
     self._rich_target = None
     target = data.forceunicode(target)
     if self.personality == "mozilla" or self.personality == "skype":
         self.translation = quote.mozillapropertiesencode(target or u"")
     else:
         self.translation = quote.javapropertiesencode(target or u"")
Ejemplo n.º 4
0
 def setsource(self, source):
     self._rich_source = None
     source = data.forceunicode(source)
     if self.personality == "mozilla" or self.personality == "skype":
         self.value = quote.mozillapropertiesencode(source or u"")
     else:
         self.value = quote.javapropertiesencode(source or u"")
Ejemplo n.º 5
0
 def setsource(self, source):
     """Sets the source AND the target to be equal"""
     source = data.forceunicode(source)
     if self.personality == "mozilla":
         self.value = quote.mozillapropertiesencode(source or u"")
     else:
         self.value = quote.javapropertiesencode(source or u"")
Ejemplo n.º 6
0
 def convertline(self, line):
     returnline = ""
     # handle multiline msgid if we're in one
     if self.inmultilinemsgid:
         msgid = quote.rstripeol(line).strip()
         # see if there's more
         self.inmultilinemsgid = (msgid[-1:] == '\\')
         # if we're echoing...
         if self.inecho:
             returnline = line
     # otherwise, this could be a comment
     elif line.strip()[:1] == '#':
         returnline = quote.rstripeol(line) + eol
     else:
         line = quote.rstripeol(line)
         equalspos = line.find('=')
         # if no equals, just repeat it
         if equalspos == -1:
             returnline = quote.rstripeol(line) + eol
         # otherwise, this is a definition
         else:
             # backslash at end means carry string on to next line
             if quote.rstripeol(line)[-1:] == '\\':
                 self.inmultilinemsgid = True
             # now deal with the current string...
             key = line[:equalspos].strip()
             # Calculate space around the equal sign
             prespace = line.lstrip()[line.lstrip().find(' '):equalspos]
             postspacestart = len(line[equalspos + 1:])
             postspaceend = len(line[equalspos + 1:].lstrip())
             postspace = line[equalspos + 1:equalspos +
                              (postspacestart - postspaceend) + 1]
             if self.inputdict.has_key(key):
                 self.inecho = False
                 value = self.inputdict[key]
                 if isinstance(value, str):
                     value = value.decode('utf8')
                 if self.personality == "mozilla" or self.personality == "skype":
                     returnline = key + prespace + "=" + postspace + quote.mozillapropertiesencode(
                         value) + eol
                 else:
                     returnline = key + prespace + "=" + postspace + quote.javapropertiesencode(
                         value) + eol
             else:
                 self.inecho = True
                 returnline = line + eol
     if isinstance(returnline, unicode):
         returnline = returnline.encode('utf-8')
     return returnline
Ejemplo n.º 7
0
 def convertline(self, line):
     returnline = ""
     # handle multiline msgid if we're in one
     if self.inmultilinemsgid:
         msgid = quote.rstripeol(line).strip()
         # see if there's more
         self.inmultilinemsgid = msgid[-1:] == "\\"
         # if we're echoing...
         if self.inecho:
             returnline = line
     # otherwise, this could be a comment
     elif line.strip()[:1] == "#":
         returnline = quote.rstripeol(line) + eol
     else:
         line = quote.rstripeol(line)
         equalspos = line.find("=")
         # if no equals, just repeat it
         if equalspos == -1:
             returnline = quote.rstripeol(line) + eol
         # otherwise, this is a definition
         else:
             # backslash at end means carry string on to next line
             if quote.rstripeol(line)[-1:] == "\\":
                 self.inmultilinemsgid = True
             # now deal with the current string...
             key = line[:equalspos].strip()
             # Calculate space around the equal sign
             prespace = line.lstrip()[line.lstrip().find(" ") : equalspos]
             postspacestart = len(line[equalspos + 1 :])
             postspaceend = len(line[equalspos + 1 :].lstrip())
             postspace = line[equalspos + 1 : equalspos + (postspacestart - postspaceend) + 1]
             if self.inputdict.has_key(key):
                 self.inecho = False
                 value = self.inputdict[key]
                 if isinstance(value, str):
                     value = value.decode("utf8")
                 if self.personality == "mozilla" or self.personality == "skype":
                     returnline = key + prespace + "=" + postspace + quote.mozillapropertiesencode(value) + eol
                 else:
                     returnline = key + prespace + "=" + postspace + quote.javapropertiesencode(value) + eol
             else:
                 self.inecho = True
                 returnline = line + eol
     if isinstance(returnline, unicode):
         returnline = returnline.encode("utf-8")
     return returnline
Ejemplo n.º 8
0
 def encode(cls, string, encoding=None):
     return quote.mozillapropertiesencode(string or u"")
Ejemplo n.º 9
0
 def test_mozillapropertiesencode(self):
     assert quote.mozillapropertiesencode(u"abc") == u"abc"
     assert quote.mozillapropertiesencode(u"abcḓ") == u"abcḓ"
     assert quote.mozillapropertiesencode(u"abc\n") == u"abc\\n"
Ejemplo n.º 10
0
 def test_mozillapropertiesencode(self):
     assert quote.mozillapropertiesencode("abc") == "abc"
     assert quote.mozillapropertiesencode("abcḓ") == "abcḓ"
     assert quote.mozillapropertiesencode("abc\n") == "abc\\n"
Ejemplo n.º 11
0
 def encode(cls, string):
     return quote.mozillapropertiesencode(string or u"")
Ejemplo n.º 12
0
 def encode(cls, string, encoding=None):
     """Encode the string"""
     string = quote.mozillapropertiesencode(string or u"")
     string = quote.mozillaescapemarginspaces(string or u"")
     return string
Ejemplo n.º 13
0
 def encode(cls, string, encoding=None):
     """Encode the string"""
     string = quote.mozillapropertiesencode(string or u"")
     string = quote.mozillaescapemarginspaces(string or u"")
     return string
Ejemplo n.º 14
0
 def settarget(self, target):
     target = data.forceunicode(target)
     if self.personality == "mozilla" or self.personality == "skype":
         self.translation = quote.mozillapropertiesencode(target or u"")
     else:
         self.translation = quote.javapropertiesencode(target or u"")
Ejemplo n.º 15
0
 def setsource(self, source):
     source = data.forceunicode(source)
     if self.personality == "mozilla" or self.personality == "skype":
         self.value = quote.mozillapropertiesencode(source or u"")
     else:
         self.value = quote.javapropertiesencode(source or u"")