Package elisa :: Package core :: Package utils :: Module locale_helper
[hide private]
[frames] | no frames]

Source Code for Module elisa.core.utils.locale_helper

 1  # -*- coding: utf-8 -*- 
 2  # Elisa - Home multimedia server 
 3  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
 4  # All rights reserved. 
 5  # 
 6  # This file is available under one of two license agreements. 
 7  # 
 8  # This file is licensed under the GPL version 3. 
 9  # See "LICENSE.GPL" in the root of this distribution including a special 
10  # exception to use Elisa with Fluendo's plugins. 
11  # 
12  # The GPL part of Elisa is also available under a commercial licensing 
13  # agreement from Fluendo. 
14  # See "LICENSE.Elisa" in the root directory of this distribution package 
15  # for details on that license. 
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   
48 -def get_from_system_locale():
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
74 -def system_encoding():
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 #FIXME : must be dynamic 84 return 'iso8859-1' 85 86 return 'utf8'
87 88 #if __name__ == '__main__': 89 # print "Reading your locale...." 90 # three = get_from_system_locale() 91 # if three: 92 # print "In elisa it would be: '%s'" % three 93 # else: 94 # print "Your localisation '%s' could not be found. Please add it..." % \ 95 # ( locale.getdefaultlocale()[0]) 96