Changeset 3288

Show
Ignore:
Timestamp:
07/27/07 16:20:08 (1 year ago)
Author:
paul
Message:

I was seeing errors on Mac when setting language to 'es' and exiting the app: the
"Application Finished" message couldn't be converted using ugettext(): the mac_roman
charmap codec couldn't translate the accented character.

Changing to default to sys.getfilesystemencoding(), and ultimately 'utf-8' seems
to work. Nizamov, please make sure I didn't break your setup.

I admit I don't really understand how locale.getlocale() is supposed to work, but
from what I've read we need to respect it if it has been set.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/dLocalize.py

    r3287 r3288  
    11# -*- coding: utf-8 -*- 
    22 
    3 # First thing is to try to make sure the default charset is unicode, not ascii: 
    43import sys 
    54import locale 
    65 
     6# Do this up here, because we may be changing sys.getdefaultencoding: 
     7defLang, defCharset = locale.getlocale()  ## need to respect this, if set, IIUC 
     8if defLang is None: 
     9    defLang = locale.getdefaultlocale()[0] 
     10    if defLang is None: 
     11        defLang = "en" 
     12 
     13if defCharset is None: 
     14    defCharset = sys.getfilesystemencoding() 
     15    if defCharset is None: 
     16        defCharset = "utf-8" 
     17 
    718reload(sys) 
    8 sys.setdefaultencoding(locale.getdefaultlocale()[1]
     19sys.setdefaultencoding(defCharset
    920 
    1021import os 
    1122import gettext 
    1223import dabo 
     24 
    1325 
    1426_appInitialized = False 
     
    131143         
    132144 
    133 defLang, defCharset = locale.getdefaultlocale() 
     145defLang, defCharset = ("en", "utf-8") 
     146#defLang, defCharset = locale.getdefaultlocale() 
    134147 
    135 if defLang is None: 
    136   defLang = "en" 
    137 else: 
    138   defLang = defLang[:2] 
    139 if defCharset is None: 
    140   defCharset = "UTF-8" 
     148#if defLang is None: 
     149# defLang = "en" 
     150#else: 
     151# defLang = defLang[:2] 
     152#if defCharset is None: 
     153# defCharset = "UTF-8" 
    141154 
    142155setLanguage(domain="dabo") 
    143156 
    144157if __name__ == "__main__": 
    145     # this code is important for every non-unicode locale   
    146     import sys 
    147     import locale 
    148     reload(sys) 
    149     sys.setdefaultencoding(locale.getdefaultlocale()[1]) 
    150      
    151     print "user locale is ", locale.getdefaultlocale() 
    152     print "framework locale is ", defLang, defCharset 
    153     print _("Framework localization test") 
     158    print "user default locale:", locale.getdefaultlocale() 
     159    print "framework locale:", defLang, defCharset 
     160 
     161    for lan in ("en", "es"): 
     162        setLanguage(lan) 
     163        print "%s:" % lan, _("Framework localization test") 
     164