Show
Ignore:
Timestamp:
11/12/06 17:16:49 (17 years ago)
Author:
jerome
Message:

Simplified i18n and l10n stuff by removing code used with Python<2.3 => not supported anymore.
Fixed it for working in CGI scripts as expected (better with Python 2.4 and higher).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/tool.py

    r3050 r3055  
    130130         
    131131        # locale stuff 
    132         self.defaultToCLocale = 0 
    133         try : 
    134             locale.setlocale(locale.LC_ALL, lang) 
     132        try : 
     133            locale.setlocale(locale.LC_ALL, (lang, charset)) 
    135134        except (locale.Error, IOError) : 
    136             # locale.setlocale(locale.LC_ALL, "C") 
    137             self.defaultToCLocale = 1 
    138         try : 
    139             gettext.install("pykota") 
     135            locale.setlocale(locale.LC_ALL, None) 
     136        (self.language, self.charset) = locale.getlocale() 
     137        self.language = self.language or "C" 
     138        self.charset = self.charset or locale.getpreferredencoding() 
     139         
     140        # translation stuff 
     141        try : 
     142            try : 
     143                trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)], codeset=self.charset) 
     144            except TypeError : # Python <2.4 
     145                trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)]) 
     146            trans.install() 
    140147        except : 
    141148            gettext.NullTranslations().install() 
    142              
    143         # Finds the correct charset 
    144         self.localecharset = sys.getfilesystemencoding() 
    145         if self.localecharset is None : 
    146             try : 
    147                 try : 
    148                     self.localecharset = locale.getpreferredencoding() 
    149                 except AttributeError :     
    150                     try : 
    151                         self.localecharset = locale.getlocale()[1] 
    152                         self.localecharset = self.localecharset or locale.getdefaultlocale()[1] 
    153                     except ValueError :     
    154                         pass        # Unknown locale, strange... 
    155             except locale.Error :             
    156                 pass 
    157         self.charset = charset or self.localecharset or "UTF-8" 
    158149     
    159150        # pykota specific stuff 
     
    189180        self.softwareJobPrice = 0.0 
    190181         
    191         if self.defaultToCLocale : 
    192             self.printInfo("Incorrect locale settings. PyKota falls back to the default locale.", "warn") 
    193182        if environHome : 
    194183            self.printInfo("PYKOTA_HOME environment variable is set. Configuration files were searched in %s" % confdir, "info") 
     
    197186                self.printInfo("The 'pykota' system account is missing. Configuration files were searched in %s instead." % confdir, "warn") 
    198187         
    199         self.logdebug("Charset detected from locale settings : %s" % self.localecharset) 
     188        self.logdebug("Language in use : %s" % self.language) 
    200189        self.logdebug("Charset in use : %s" % self.charset) 
     190         
    201191        arguments = " ".join(['"%s"' % arg for arg in sys.argv]) 
    202192        self.logdebug("Command line arguments : %s" % arguments) 
     
    237227                self.logdebug(_("Regained priviledges. Now running as root.")) 
    238228                self.privdropped = 0 
    239          
    240     def getCharset(self) :     
    241         """Returns the charset in use.""" 
    242         return self.charset 
    243229         
    244230    def UTF8ToUserCharset(self, text) :