~ubuntu-branches/ubuntu/lucid/prewikka/lucid

« back to all changes in this revision

Viewing changes to prewikka/locale.py

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Chifflier
  • Date: 2007-05-22 09:50:33 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070522095033-0jr7zmkf91bl1ymp
Tags: 0.9.11-1
New upstream release (add internationalization support)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 PreludeIDS Technologies. All Rights Reserved.
2
 
# Author: Yoann Vandoorselaere <yoann.v@prelude-ids.com>
3
 
#
4
 
# This file is part of the Prewikka program.
5
 
#
6
 
# This program is free software; you can redistribute it and/or modify
7
 
# it under the terms of the GNU General Public License as published by
8
 
# the Free Software Foundation; either version 2, or (at your option)
9
 
# any later version.
10
 
#
11
 
# This program is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
# GNU General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with this program; see the file COPYING.  If not, write to
18
 
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19
 
 
20
 
import siteconfig, gettext, __builtin__
21
 
 
22
 
 
23
 
try: 
24
 
    import threading    
25
 
 
26
 
except ImportError:
27
 
    _lock = None
28
 
    currentThread = lambda: "none"
29
 
 
30
 
else:
31
 
    _lock = threading.Lock()
32
 
    currentThread = threading.currentThread
33
 
 
34
 
 
35
 
_all_locale = { }
36
 
_localized_thread = { }    
37
 
 
38
 
 
39
 
def _safeGettext(s):
40
 
    if _localized_thread.has_key(currentThread()):
41
 
        return _localized_thread[currentThread()].gettext(s)
42
 
    else:
43
 
        return s
44
 
    
45
 
 
46
 
def setLocale(lang):
47
 
    if _lock:
48
 
        _lock.acquire()
49
 
    
50
 
    if not _all_locale.has_key(lang):
51
 
        _all_locale[lang] = gettext.translation("prewikka", siteconfig.locale_dir, languages=[lang])
52
 
            
53
 
    if _lock:
54
 
        _lock.release()
55
 
            
56
 
    _localized_thread[currentThread()] = _all_locale[lang]
57
 
   
58
 
        
59
 
gettext.install("prewikka", siteconfig.locale_dir)
60
 
__builtin__._ = _safeGettext