1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 Contains locale helper functions
19 """
20
21 __maintainer__ = 'Benjamin Kampmann <benjamin@fluendo.com>'
22
23 import locale, platform
24
25
26 """
27 This is a dictionary pointing the locales to their three letter language
28 codes. The key could be the a locale (like 'DE_de') or a two-letter code (like
29 'de'). If the first thing is found it is used, the two-letter code is a
30 fallback.
31
32 For more informations about the 2- and 3-letter language codes, take a look
33 at this:
34 http://en.wikipedia.org/wiki/ISO-639#Alpha-2_code_space
35 http://www.sil.org/iso639-3/codes.asp
36 """
37 locales_to_iso = {
38 'de' : 'deu',
39 'fr' : 'fra',
40 'es' : 'spa',
41 'ca' : 'cat',
42 'pl' : 'pol',
43 'it' : 'ita',
44 }
45
46
47
49 """
50 Get the system locale and look it up as a elisa-locale. If the locale
51 could not be wrapped, nothing is returned
52
53 @rtype: string or None
54 @return: a three letter language code
55 """
56
57 loc = locale.getdefaultlocale()[0]
58
59 if loc is None:
60 return None
61
62 if locales_to_iso.has_key(loc):
63 return locales_to_iso[loc]
64
65 splitter = loc.rfind('_')
66 if splitter != -1:
67 two_letter = loc[:splitter]
68
69 if locales_to_iso.has_key(two_letter):
70 return locales_to_iso[two_letter]
71
72 return None
73
75 """
76 Get the encoding used by the system
77
78 @rtype: string
79 @return: the encoding used by the system
80 """
81
82 if platform.system() == 'Windows':
83
84 return 'iso8859-1'
85
86 return 'utf8'
87
88
89
90
91
92
93
94
95
96