[CalendarServer-changes] [5639] CalendarServer/trunk/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Fri May 21 14:41:28 PDT 2010
Revision: 5639
http://trac.macosforge.org/projects/calendarserver/changeset/5639
Author: sagen at apple.com
Date: 2010-05-21 14:41:24 -0700 (Fri, 21 May 2010)
Log Message:
-----------
Parse binary translation .strings files.
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/localization.py
CalendarServer/trunk/twistedcaldav/mail.py
CalendarServer/trunk/twistedcaldav/stdconfig.py
Modified: CalendarServer/trunk/twistedcaldav/localization.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/localization.py 2010-05-21 02:59:59 UTC (rev 5638)
+++ CalendarServer/trunk/twistedcaldav/localization.py 2010-05-21 21:41:24 UTC (rev 5639)
@@ -26,6 +26,12 @@
from twext.python.log import Logger
+try:
+ from Foundation import *
+ foundationImported = True
+except ImportError:
+ foundationImported = False
+
from twistedcaldav.config import config
log = Logger()
@@ -355,6 +361,9 @@
lprojRoot = settings.TranslationsDirectory
gnuRoot = settings.LocalesDirectory
+ if not foundationImported:
+ return
+
# Do we have an Apple translations directory?
if lprojRoot and gnuRoot and os.path.exists(lprojRoot):
@@ -393,47 +402,7 @@
class ParseError(Exception):
pass
-def parseString(text, index=0):
- value = ""
-
- while index < len(text):
- ch = text[index]
-
- if ch == '"':
- if text[index-1] != "\\":
- # At unescaped quote
- if value:
- # ...marking end of string; return it
- return (value, index+1)
- else:
- # ...marking beginning of string; skip it
- index += 1
- continue
-
- value += text[index]
- index += 1
-
- # no closing quote "
- raise ParseError("No closing quote")
-
-def parseLine(line):
-
- key, index = parseString(line)
- remaining = line[index:].strip()
- if remaining[0] != "=":
- raise ParseError("Expected equals sign")
- remaining = remaining[1:].strip()
- value, index = parseString(remaining)
- return (key, value)
-
-
-boms = {
- codecs.BOM_UTF8 : 'UTF8',
- codecs.BOM_UTF16_BE : 'UTF-16BE',
- codecs.BOM_UTF16_LE : 'UTF-16LE',
-}
-
def convertStringsFile(src, dest):
strings = { }
@@ -446,35 +415,17 @@
# can't create directory to hold .po file
return
- with open(src) as input:
- contents = input.read()
- for bom, encoding in boms.iteritems():
- if contents.startswith(bom):
- contents = contents[len(bom):]
- break
- else:
- encoding = "UTF8"
+ # Parse the binary plist .strings file:
+ parser = NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_
+ data = NSData.dataWithContentsOfMappedFile_(src)
+ strings, format, error = parser(data, NSPropertyListImmutable, None, None)
+ if error:
+ raise ParseError(error)
- contents = contents.decode(encoding)
- lines = contents.split("\n")
-
- for num, line in enumerate(lines):
- # print num, line
- line = line.strip()
- if not line.startswith('"'):
- continue
-
- try:
- key, value = parseLine(line)
- except ParseError, err:
- log.info("Error on line %d of %s: %s" % (num+1, src, str(err)))
- raise
-
- strings[key] = value
-
# The format of GNUtext MO files is described here:
# http://www.gnu.org/software/autoconf/manual/gettext/MO-Files.html
+ strings = dict(strings)
originals = strings.keys()
originals.sort()
Modified: CalendarServer/trunk/twistedcaldav/mail.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/mail.py 2010-05-21 02:59:59 UTC (rev 5638)
+++ CalendarServer/trunk/twistedcaldav/mail.py 2010-05-21 21:41:24 UTC (rev 5639)
@@ -966,6 +966,10 @@
else:
formatString = _("Event reply: %(summary)s")
+ # The translations we get back from gettext are utf-8 encoded
+ # strings, so convert to unicode
+ formatString = formatString.decode("utf-8")
+
details['subject'] = msg['Subject'] = formatString % {
'summary' : details['summary']
}
@@ -1007,6 +1011,12 @@
details['plainOrganizer'] = (orgCN if not orgEmail else
"%s <%s>" % (orgCN, orgEmail))
+ # The translations we get back from gettext are utf-8 encoded
+ # strings, so convert to unicode
+ for key in details.keys():
+ if isinstance(details[key], str):
+ details[key] = details[key].decode("utf-8")
+
# plain text version
if canceled:
plainTemplate = u"""%(subject)s
Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py 2010-05-21 02:59:59 UTC (rev 5638)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py 2010-05-21 21:41:24 UTC (rev 5639)
@@ -495,7 +495,7 @@
"Localization" : {
"TranslationsDirectory" : "/usr/share/caldavd/share/translations",
"LocalesDirectory" : "/usr/share/caldavd/share/locales",
- "Language" : "English",
+ "Language" : "en",
},
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100521/3ec60636/attachment.html>
More information about the calendarserver-changes
mailing list