[CalendarServer-changes] [13271] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Mon Apr 14 13:11:08 PDT 2014


Revision: 13271
          http://trac.calendarserver.org//changeset/13271
Author:   sagen at apple.com
Date:     2014-04-14 13:11:08 -0700 (Mon, 14 Apr 2014)
Log Message:
-----------
Remap Chinese language codes

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/localization.py
    CalendarServer/trunk/twistedcaldav/test/test_localization.py

Modified: CalendarServer/trunk/twistedcaldav/localization.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/localization.py	2014-04-14 18:56:23 UTC (rev 13270)
+++ CalendarServer/trunk/twistedcaldav/localization.py	2014-04-14 20:11:08 UTC (rev 13271)
@@ -484,7 +484,19 @@
         outFile.write(result)
 
 
+def _remapLanguageCode(code):
+    """
+    Remap certain language codes to others, per the localization team
+    """
 
+    if code == "zh-Hans":  # Simplified Chinese
+        code = "zh_CN"
+    elif code == "zh-Hant":  # Traditional Chinese
+        code = "zh_TW"
+
+    return code
+
+
 def getLanguage(config):
     """
     If the language has been specified explicitly in the config, return it.  Otherwise
@@ -492,8 +504,8 @@
 
     @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
+    @return: The language code -- on OS X the supported ones are:
+        de, en, es, fr, it, ja, ko, nl, zh_CN, zh_TW
     @rtype: C{str}
     """
     if config.Localization.Language:
@@ -501,6 +513,7 @@
 
     try:
         language = NSLocale.preferredLanguages()[0]
+        language = _remapLanguageCode(language)
     except:
         language = "en"
 

Modified: CalendarServer/trunk/twistedcaldav/test/test_localization.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_localization.py	2014-04-14 18:56:23 UTC (rev 13270)
+++ CalendarServer/trunk/twistedcaldav/test/test_localization.py	2014-04-14 20:11:08 UTC (rev 13271)
@@ -16,7 +16,9 @@
 
 from __future__ import with_statement
 
-from twistedcaldav.localization import translationTo, getLanguage, _
+from twistedcaldav.localization import (
+    translationTo, getLanguage, _remapLanguageCode, _
+)
 from twistedcaldav.ical import Component
 from twistedcaldav.test.util import TestCase
 from twistedcaldav.config import ConfigDict
@@ -175,3 +177,13 @@
         """
 
         self.assertEquals(getLanguage(ConfigDict({"Localization" : {"Language" : "xyzzy"}})), "xyzzy")
+
+
+    def test_remap(self):
+        """
+        Verify proper remapping of Chinese language codes
+        """
+        self.assertEquals(_remapLanguageCode("en"), "en")
+        self.assertEquals(_remapLanguageCode("zh-Hans"), "zh_CN")
+        self.assertEquals(_remapLanguageCode("zh-Hant"), "zh_TW")
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140414/5659f116/attachment.html>


More information about the calendarserver-changes mailing list