[CalendarServer-changes] [9811] CalendarServer/trunk/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Fri Sep 14 14:34:56 PDT 2012
Revision: 9811
http://trac.macosforge.org/projects/calendarserver/changeset/9811
Author: sagen at apple.com
Date: 2012-09-14 14:34:53 -0700 (Fri, 14 Sep 2012)
Log Message:
-----------
Determine iMIP language in this order: caldavd.plist, OS X user prefs, English.
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/localization.py
CalendarServer/trunk/twistedcaldav/mail.py
CalendarServer/trunk/twistedcaldav/stdconfig.py
CalendarServer/trunk/twistedcaldav/test/test_localization.py
Modified: CalendarServer/trunk/twistedcaldav/localization.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/localization.py 2012-09-14 19:18:54 UTC (rev 9810)
+++ CalendarServer/trunk/twistedcaldav/localization.py 2012-09-14 21:34:53 UTC (rev 9811)
@@ -27,7 +27,7 @@
try:
from Foundation import (
- NSPropertyListImmutable, NSPropertyListSerialization, NSData
+ NSPropertyListImmutable, NSPropertyListSerialization, NSData, NSUserDefaults
)
foundationImported = True
except ImportError:
@@ -474,3 +474,25 @@
with open(dest, "wb") as outFile:
outFile.write(result)
+
+
+def getLanguage(config):
+ """
+ If the language has been specified explicitly in the config, return it. Otherwise
+ look it up via NSUserDefaults on OS X. Failing that, return "en"
+
+ @param config: The configuration object to examine
+ @type config: ConfigDict
+ @return: The two-letter language code -- on OS X the supported ones are:
+ de, en, es, fr, it, ja, ko, nl
+ @rtype: C{str}
+ """
+ if config.Localization.Language:
+ return config.Localization.Language
+
+ try:
+ language = NSUserDefaults.standardUserDefaults().objectForKey_(u"AppleLanguages")[0]
+ except:
+ language = "en"
+
+ return language
Modified: CalendarServer/trunk/twistedcaldav/mail.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/mail.py 2012-09-14 19:18:54 UTC (rev 9810)
+++ CalendarServer/trunk/twistedcaldav/mail.py 2012-09-14 21:34:53 UTC (rev 9811)
@@ -69,7 +69,7 @@
from twistedcaldav.config import config
from twistedcaldav.directory.util import transactionFromRequest
from twistedcaldav.ical import Property
-from twistedcaldav.localization import translationTo, _
+from twistedcaldav.localization import translationTo, getLanguage, _
from twistedcaldav.resource import CalDAVResource
from twistedcaldav.schedule import deliverSchedulePrivilegeSet
from twistedcaldav.scheduling.cuaddress import normalizeCUAddr
@@ -554,7 +554,7 @@
calendar = (yield ical.Component.fromIStream(request.stream))
originator = request.headers.getRawHeaders("originator")[0]
recipient = request.headers.getRawHeaders("recipient")[0]
- language = config.Localization.Language
+ language = getLanguage(config)
if not (yield self.mailer.outbound(originator,
recipient, calendar, language=language)):
Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py 2012-09-14 19:18:54 UTC (rev 9810)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py 2012-09-14 21:34:53 UTC (rev 9811)
@@ -810,7 +810,7 @@
"Localization" : {
"TranslationsDirectory" : "/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/share/translations",
"LocalesDirectory" : "/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/share/locales",
- "Language" : "en",
+ "Language" : "",
},
Modified: CalendarServer/trunk/twistedcaldav/test/test_localization.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_localization.py 2012-09-14 19:18:54 UTC (rev 9810)
+++ CalendarServer/trunk/twistedcaldav/test/test_localization.py 2012-09-14 21:34:53 UTC (rev 9811)
@@ -16,9 +16,10 @@
from __future__ import with_statement
-from twistedcaldav.localization import translationTo, _
+from twistedcaldav.localization import translationTo, getLanguage, _
from twistedcaldav.ical import Component
from twistedcaldav.test.util import TestCase
+from twistedcaldav.config import ConfigDict
from pycalendar.datetime import PyCalendarDateTime
import os
@@ -140,3 +141,10 @@
(u'11:05 (PDT) otay 18:15 (EDT)', u'4 ourshay 10 inutesmay'))
self.assertEquals(t.monthAbbreviation(1), "ANJAY")
+
+ def test_getLanguage(self):
+ """
+ Test that getLanguage( ) examines config.
+ """
+
+ self.assertEquals(getLanguage(ConfigDict({"Localization" : {"Language" : "xyzzy"}})), "xyzzy")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120914/84a78a52/attachment.html>
More information about the calendarserver-changes
mailing list