lang.py :  » UML » Python-UML-Tool » pyut-1.4.0 » src » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » UML » Python UML Tool 
Python UML Tool » pyut 1.4.0 » src » lang.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
__author__  = "Laurent Burgbacher <lb@alawa.ch>"
__version__ = "$Revision: 1.14 $"
__date__    = "2001-07-29"
# Check wxLocale ?

from PyutPreferences import *
import gettext
#from wxPython.wx import wxLocale, wxGetTranslation, wxLANGUAGE_POLISH
import wx 

# Don't know why yet. If not import here, throw a system exception later !
import zlib 

# Constants
DEFAULT_LANG = "en"
LANGUAGES = {
        DEFAULT_LANG: ("English", wx.LANGUAGE_ENGLISH),
        "da": ("Danish", wx.LANGUAGE_DANISH),
        "de": ("Deutsch", wx.LANGUAGE_GERMAN),
        "eo": ("Esperanto",wx.LANGUAGE_ESPERANTO),
        "es": ("Spanish", wx.LANGUAGE_SPANISH),
        "fr": ("Francais", wx.LANGUAGE_FRENCH),
        "id": ("Indonesian",wx.LANGUAGE_INDONESIAN),
        "pl": ("Polish", wx.LANGUAGE_POLISH),
        "ci": ("chinese-utf8", wx.LANGUAGE_CHINESE_TRADITIONAL),
        }

def importLanguage():
    # Get language from preferences
    prefs = PyutPreferences()
    language = prefs['I18N']

    # Set default language?
    if language not in LANGUAGES:
        # Use default language
        language = DEFAULT_LANG

    # Set language for all application
    print "Installing language <", language, ">"
    try:
        # Latest test 20050308
        #langid=wx.LANGUAGE_CHINESE_TRADITIONAL
        wxLangID = LANGUAGES[language][1]
        domain="Pyut"
        localedir="." #"./locale"
        #print "langid=", wxLangID

        method=0
        if method==0:
            # Possibility to load all languages, then do an install on fly
            tr = gettext.translation(domain, localedir, languages=[language])
            tr.install(unicode=True)
            #gettext.install(domain, localedir, unicode=True)
        elif method==1:

            # Set locale for wxWidget
            loc = wx.Locale(wxLangID)
            loc.AddCatalogLookupPathPrefix(localedir)
            loc.AddCatalog(domain)

            # Set up python's gettext
            print "Encoding name is ", loc.GetCanonicalName()
            mytrans = gettext.translation(domain, localedir, 
                    [loc.GetCanonicalName()], fallback=True)
            mytrans.install(unicode=True)
            #import __builtin__
            #__builtin__.__dict__['_'] = lambda x:wx.GetTranslation(x).encode("UTF-8")
            #__builtin__.__dict__['_'] = wx.GetTranslation
            #print "importL=", _("Untitled.put")
            


            #gettext.install('Pyut', '.', unicode=True)
            #trad = gettext.translation("Pyut", ".", [language])
            #trad.install()
            #loc = wx.Locale(wx.LANGUAGE_CHINESE_TRADITIONAL)
            #loc.setLocale(locale.LC_ALL, 'ci')
            #gettext.translation("Pyut", ".", [language]).install()
            



            #gettext.translation("Pyut", ".", languages=[language]).install()

            #loc = wxLocale(wxLANGUAGE_POLISH)
            #loc.AddCatalog("pl/LC_MESSAGES/Pyut.mo")
            #print wxGetTranslation("Untitled.put")
            #_ = wxGetTranslation
            #import __builtin__
            #__builtin__.__dict__['_'] = _
    except:
        # If there has been a problem with i18n
        print "Warning: problem with gettext, i18n not used"
        import sys, traceback
        errMsg ="The following error occured : %s" % str(sys.exc_info()[1])
        errMsg += "\n\n---------------------------\n"
        if sys.exc_info()[0] is not None:
            errMsg += "Error : %s" % sys.exc_info()[0] + "\n"
        if sys.exc_info()[1] is not None:
            errMsg += "Msg   : %s" % sys.exc_info()[1] + "\n"
        if sys.exc_info()[2] is not None:
            errMsg += "Trace :\n"
            for el in traceback.extract_tb(sys.exc_info()[2]): 
                errMsg = errMsg + str(el) + "\n"
        print errMsg

        # Redefining '_' function
        def _(string):
            return unicode(string)

        ## Put function '_' in globals (builtin)
        import __builtin__
        __builtin__.__dict__['_'] = _
importLanguage()
#print "**************"
#print _("Untitled.put")
#print wx.GetTranslation("Untitled.put")
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.