util/TranslationCatalogs.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 22 Apr 2016 17:02:18 +0300
changeset 1501 d917c209529d
parent 817 1a3cc2065216
child 1511 91538d0c242c
permissions -rw-r--r--
fix Traceback if search icon on library panel is clicked, when no
category/item is selected in the library.

The problem is here, that if nothing is selected method GetSelection()
returns root item, that doesn't have any python data associated with it.
This issue seems to be wx3.0 specified, because it doesn't exist
with wx2.8 on Windows.
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)