File: create_locale.py

package info (click to toggle)
workrave 1.10.54-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,004 kB
  • sloc: cpp: 46,596; ansic: 9,760; sh: 2,754; javascript: 1,935; makefile: 1,452; python: 973; xml: 672; objc: 455; perl: 113; cs: 70; sed: 16
file content (75 lines) | stat: -rw-r--r-- 1,580 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# LoclaeInfo.py (c) 2006 Canonical, released under the GPL
#
# a helper class to get locale info

import string
import re            
import subprocess
import gettext

from gettext import gettext as _
from xml.etree.ElementTree import ElementTree

languages = {}
countries = {}

et = ElementTree(file = "/usr/share/xml/iso-codes/iso_639.xml")
it = et.getiterator('iso_639_entry')
for elm in it:
    lang = elm.attrib["name"]
    if elm.attrib.has_key("iso_639_1_code"):
        code = elm.attrib["iso_639_1_code"]
    else:
        code = elm.attrib["iso_639_2T_code"]

    languages[code] = lang

et = ElementTree(file="/usr/share/xml/iso-codes/iso_3166.xml")
it = et.getiterator('iso_3166_entry')
for elm in it:
    if elm.attrib.has_key("common_name"):
        descr = elm.attrib["common_name"]
    else:
        descr = elm.attrib["name"]

    if elm.attrib.has_key("alpha_2_code"):
        code = elm.attrib["alpha_2_code"]
    else:
        code = elm.attrib["alpha_3_code"]

    countries[code] = descr

print "struct language_t"
print "{"
print "   const char *code;"
print "   const char *lang;"
print "} languages []= "
print "{"

keys = languages.keys()
keys.sort();

for k in keys:
    txt = "{ \"%s\", \"%s\" }," % (k, languages[k])
    print txt.encode('utf-8')

print "};"
print

print "struct country_t"
print "{"
print "   const char *code;"
print "   const char *country;"
print "} countries []= "
print "{"


keys = countries.keys()
keys.sort();

for k in keys:
    txt = "{ \"%s\", \"%s\" }," % (k, countries[k])
    print txt.encode('utf-8')

    
print "};"