Changeset 155:08f1f0a4dd9a


Ignore:
Timestamp:
05/05/12 12:16:30 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Enhanced language handling to run the program in the proper environment for gettext

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • runmlx.bat

    r30 r155  
    55set PYTHONPATH=%scriptdir%\src;%PYTHONPATH%
    66
    7 python.exe -m runmlx
     7python.exe -m runmlx %1 %2 %3 %4 %5 %6 %7 %8 %9
  • src/mlx/config.py

    r149 r155  
    345345        """Get the option name for the given message type level."""
    346346        return const.messageType2string(messageType)
    347        
     347
     348    def setupLocale(self):
     349        """Setup the locale based on the language set.
     350
     351        Return True if a specific language was set, False otherwise."""
     352        import locale
     353        if self._language:
     354            print "Setting up locale for", self._language
     355            os.environ["LANGUAGE"] = self._language
     356            langAndEncoding = self._language + "." + locale.getpreferredencoding()
     357            print langAndEncoding
     358            os.environ["LANG"] = langAndEncoding
     359            os.environ["LC_MESSAGES"] = langAndEncoding
     360            os.environ["LC_COLLATE"] = langAndEncoding
     361            os.environ["LC_CTYPE"] = langAndEncoding
     362            return True
     363        else:
     364            return False
     365
    348366    def getLanguage(self):
    349367        """Get the language to be used."""
  • src/mlx/i18n.py

    r151 r155  
    11# Internationalization support
    22# -*- coding: utf-8 -*-
     3
     4#------------------------------------------------------------------------------
     5
     6import locale
    37
    48#------------------------------------------------------------------------------
  • src/mlx/mlx.py

    r133 r155  
    77import os
    88import sys
    9 
    10 if os.name=="nt":
    11     import win32api
    129
    1310#--------------------------------------------------------------------------------------
     
    2522#--------------------------------------------------------------------------------------
    2623
     24def restart(args = []):
     25    """Restart the program with the given arguments."""
     26    print "Restarting with args", args
     27    programPath = os.path.join(os.path.dirname(sys.argv[0]),
     28                               "runmlx.exe" if os.name=="nt" else "runmlx.sh")
     29    if os.name=="nt":
     30        import win32api
     31        try:
     32            programPath = win32api.GetShortPathName(programPath)
     33        except:
     34            programPath = os.path.join(os.path.dirname(sys.argv[0]),
     35                                       "runmlx.bat")
     36            programPath = win32api.GetShortPathName(programPath)
     37
     38    args = [programPath] + args
     39
     40    os.execv(programPath, args)   
     41
     42#--------------------------------------------------------------------------------------
     43
    2744def main():
    2845    """The main operation of the program."""
     
    3148    config = Config()
    3249    config.load()
     50
     51    if (len(sys.argv)<=1 or sys.argv[1]!="usedeflang") and config.setupLocale():
     52        restart(["usedeflang"])
    3353
    3454    setLanguage(config.getLanguage())
     
    5474
    5575    if gui.toRestart:
    56         programPath = os.path.join(os.path.dirname(sys.argv[0]),
    57                                    "runmlx.exe" if os.name=="nt" else "runmlx.sh")
    58         if os.name=="nt":
    59             programPath = win32api.GetShortPathName(programPath)
    60 
    61         os.execl(programPath, programPath)
     76        restart()
    6277
    6378#--------------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.