/[thuban]/branches/WIP-pyshapelib-bramz/test/localessupport.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/test/localessupport.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2693 - (hide annotations)
Fri Sep 15 08:49:51 2006 UTC (18 years, 5 months ago) by bernhard
Original Path: trunk/thuban/test/localessupport.py
File MIME type: text/x-python
File size: 1592 byte(s)
Adding localessupport.py, support code for setting locales.

1 bernhard 2693 # Copyright (C) 2006 by Intevation GmbH
2     # Author(s):
3     # Bernhard Reiter <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with the software for details.
7    
8     """Support code for setting locales."""
9    
10     __version__ = "$Revision: $"
11     # $Id: xmlsupport.py 1683 2003-08-28 15:20:57Z bh $
12    
13     import locale
14     from locale import LC_NUMERIC, getlocale, setlocale, localeconv
15    
16     _verbose = 0
17    
18     def setdecimalcommalocale():
19     """Find and set LC_NUMERIC locale that uses comma as decimal_point.
20    
21     Return the previous locale to be able to set the previous LC_NUMERIC.
22     This can be "(None, None)" or None if none was found.
23     """
24    
25     encodings = [".UTF-8", "@euro"]
26     locales = ["de_DE", "fr_FR", "fr_BE"]
27    
28     oldlocale = getlocale(LC_NUMERIC)
29    
30     tries = []
31     for l in locales:
32     for e in encodings:
33     tries.append(l + e)
34    
35     for t in tries:
36     try:
37     if _verbose > 0:
38     print "trying", repr(t)
39     setlocale(LC_NUMERIC,t)
40     except locale.Error:
41     continue
42     break
43    
44     # did we find one?
45     if localeconv()['decimal_point'] == ",":
46     return oldlocale
47    
48     setlocale(LC_NUMERIC,oldlocale)
49     return None
50    
51     if __name__ == "__main__":
52     # test and print result
53     print "Searching for LC_NUMERIC locale with comma as decimal_point ..."
54     _verbose = 1
55     oldlocale = setdecimalcommalocale()
56     if oldlocale == None:
57     print "none found."
58     else:
59     print "found: ",
60     print getlocale(LC_NUMERIC)
61     setlocale(LC_NUMERIC,oldlocale)

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26