- Revision
- 11411
- Author
- bkirsch
- Date
- 2006-08-14 15:26:58 -0700 (Mon, 14 Aug 2006)
Log Message
Added WxMessageFactory testing support and now unload the global _WX_LOCALE before setting it to a new locale. This is need for wx to properly localize
Modified Paths
Added Paths
Diff
Modified: trunk/chandler/i18n/i18nmanager.py (11410 => 11411)
--- trunk/chandler/i18n/i18nmanager.py 2006-08-14 20:35:20 UTC (rev 11410) +++ trunk/chandler/i18n/i18nmanager.py 2006-08-14 22:26:58 UTC (rev 11411) @@ -393,6 +393,8 @@ @type fallback: c{boolean} """ + self._testing = False + if localeSet is None: localeSet = self.discoverLocaleSet() @@ -942,6 +944,12 @@ @type locale: ASCII c{str} """ + global _WX_LOCALE + + # Need to unload wx.Locale object otherwise it will + # hold a dangling reference and not use the new Locale + _WX_LOCALE = None + lc = findWxLocale(locale) if not lc.IsOk() and hasCountryCode(locale): @@ -961,9 +969,10 @@ raise I18nException("Invalid wxPython Locale: " \ "'%s'" % locale) - - # Store a reference to the wx.Locale instance - global _WX_LOCALE + # Keep a Global reference to the Wx Locale + # To ensure it does not get unloaded during the + # application life cycle. There can be only one + # wx locale per Python instance _WX_LOCALE = lc def findWxLocale(locale):
Added: trunk/chandler/i18n/tests/wxLocalizationTest2.py (11410 => 11411)
--- trunk/chandler/i18n/tests/wxLocalizationTest2.py 2006-08-14 20:35:20 UTC (rev 11410) +++ trunk/chandler/i18n/tests/wxLocalizationTest2.py 2006-08-14 22:26:58 UTC (rev 11411) @@ -0,0 +1,18 @@ +import i18n +import sys +from i18n import wxMessageFactory as w + +i18nMan = i18n._I18nManager + + +def translate(): + print "Using Locale: ", i18n.getLocaleSet()[0] + print "Cancel: ", w("Cancel").encode("utf8") + print "Quit: ", w("&Quit").encode("utf8") + + +i18nMan.initialize('fr_CA') +translate() +i18nMan.setLocaleSet('es_UY') +translate() + Property changes on: trunk/chandler/i18n/tests/wxLocalizationTest2.py ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native
Modified: trunk/chandler/i18n/tests/xTestI18n.py (11410 => 11411)
--- trunk/chandler/i18n/tests/xTestI18n.py 2006-08-14 20:35:20 UTC (rev 11410) +++ trunk/chandler/i18n/tests/xTestI18n.py 2006-08-14 22:26:58 UTC (rev 11411) @@ -4,6 +4,7 @@ import os from i18n import * from i18n.i18nmanager import * +from i18n import wxMessageFactory as w this_module = "i18n.tests.TestI18n" @@ -19,7 +20,6 @@ # A wx application instance must be created # before using the wx translation API's self.app = wx.App() - os.environ["UNIT_TESTING"] = "True" self.i18nMan = i18n._I18nManager @@ -31,13 +31,32 @@ self.i18nMan.initialize(self.LOCALE_SET, self.INI_FILE) self.mf = MessageFactory(self.PROJECT, self.CATALOG) - def tearDown(self): - os.environ["UNIT_TESTING"] = "True" - def testWxMessageFactory(self): - # XXX Awaiting wxstd.mo discovery by wxPython - pass + self.assertEquals(w("Cancel"), u"Annuler") + self.assertEquals(w("&Quit"), u"&Quitter") + self.i18nMan.setLocaleSet("es_UY") + self.assertEquals(w("Cancel"), u"Cancelar") + self.assertEquals(w("&Quit"), u"&Salir") + + self.i18nMan.setLocaleSet("en") + self.assertEquals(w("Cancel"), u"Cancel") + self.assertEquals(w("&Quit"), u"&Quit") + + # The 'test' locale is a debug keyword + # which sets the locale set to ['fr_CA', 'fr'] + # and enables the testing mode flag. + # In testing mode all values returned by + # the WxMessageFactory method insert + # a (WX)\u00FC: at the start of the string. + self.i18nMan.setLocaleSet("test") + self.assertEquals(w("Cancel"), u"(WX)\u00FC: Annuler") + self.assertEquals(w("&Quit"), u"(WX)\u00FC: &Quitter") + + # Restore the default locale set + self.i18nMan.setLocaleSet(self.LOCALE_SET) + + def testChandlerMessageFactory(self): """ This is a simple test to ensure that
_______________________________________________ Commits mailing list [email protected] http://lists.osafoundation.org/mailman/listinfo/commits
