~nataliabidart/software-center/lost-in-translation

« back to all changes in this revision

Viewing changes to softwarecenter/i18n.py

  • Committer: Kiwinote
  • Date: 2012-03-15 22:36:31 UTC
  • mfrom: (2867 trunk)
  • mto: This revision was merged to the branch mainline in revision 2881.
  • Revision ID: kiwinote@gmail.com-20120315223631-lvea6t5sydpkkqni
mergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
FALLBACK = "en"
26
26
# those languages need the full language-code, the other ones
27
27
# can be abbreved
28
 
FULL = ["pt_BR", 
 
28
FULL = ["pt_BR",
29
29
        "zh_CN", "zh_TW"]
30
30
 
 
31
 
31
32
def init_locale():
32
33
    try:
33
34
        locale.setlocale(locale.LC_ALL, "")
52
53
        return [get_language()]
53
54
    return langs
54
55
 
 
56
 
55
57
def get_language():
56
58
    """Helper that returns the current language
57
59
    """
58
60
    try:
59
 
        language = locale.getdefaultlocale(('LANGUAGE','LANG','LC_CTYPE','LC_ALL'))[0]
 
61
        language = locale.getdefaultlocale(
 
62
            ('LANGUAGE', 'LANG', 'LC_CTYPE', 'LC_ALL'))[0]
60
63
    except Exception as e:
61
64
        LOG.warn("Failed to get language: '%s'" % e)
62
65
        language = "C"
67
70
        return language
68
71
    return language.split("_")[0]
69
72
 
 
73
 
70
74
def langcode_to_name(langcode):
71
75
    import xml.etree.ElementTree
72
76
    from gettext import dgettext
73
77
    for iso in ["iso_639_3", "iso_639"]:
74
 
        path = os.path.join("/usr/share/xml/iso-codes/", iso+".xml")
 
78
        path = os.path.join("/usr/share/xml/iso-codes/", iso + ".xml")
75
79
        if os.path.exists(path):
76
80
            root = xml.etree.ElementTree.parse(path)
77
81
            xpath = ".//%s_entry[@part1_code='%s']" % (iso, langcode)
79
83
            if match is not None:
80
84
                return dgettext(iso, match.attrib["name"])
81
85
    return langcode
82