util/TranslationCatalogs.py
author Laurent Bessard
Tue, 11 Jun 2013 23:08:06 +0200
changeset 1246 101625efb1c1
parent 817 1a3cc2065216
child 1511 91538d0c242c
permissions -rw-r--r--
Rewrite LDElementDialog
815
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
     1
#!/usr/bin/env python
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
     3
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
     4
import os 
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
     5
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
     6
import wx
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
     7
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
     8
# Get the default language
817
1a3cc2065216 Update chinese and german translation catalogs
laurent
parents: 815
diff changeset
     9
langid = wx.LANGUAGE_DEFAULT
815
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    10
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    11
# Define locale for wx
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    12
locale = wx.Locale(langid)
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    13
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    14
def GetDomain(path):
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    15
    for name in os.listdir(path):
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    16
        filepath = os.path.join(path, name)
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    17
        basename, fileext = os.path.splitext(name)
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    18
        if os.path.isdir(filepath):
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    19
            result = GetDomain(filepath)
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    20
            if result is not None:
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    21
                return result
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    22
        elif fileext == ".mo":
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    23
            return basename
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    24
    return None
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    25
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    26
def AddCatalog(locale_dir):
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    27
    if os.path.exists(locale_dir) and os.path.isdir(locale_dir):
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    28
        domain = GetDomain(locale_dir)
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    29
        if domain is not None:
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    30
            locale.AddCatalogLookupPathPrefix(locale_dir)
e4f24593a758 Adding support for extending internationalization to extensions
laurent
parents:
diff changeset
    31
            locale.AddCatalog(domain)