File: gtcache.py

package info (click to toggle)
democracyplayer 0.9.1-1.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 20,876 kB
  • ctags: 6,313
  • sloc: python: 36,830; cpp: 1,038; ansic: 286; xml: 257; sh: 71; makefile: 30
file content (42 lines) | stat: -rw-r--r-- 1,084 bytes parent folder | download
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
# Caching gettext functions

import gettext as _gt
import locale
import config
import prefs
import platformutils
import os

_gtcache = None

def init():
    global _gtcache
    _gtcache = {}
    if not platformutils.localeInitialized:
        raise Exception, "locale not initialized"
    locale.setlocale(locale.LC_ALL, '')

    _gt.bindtextdomain("democracyplayer", config.get(prefs.GETTEXT_PATHNAME))
    _gt.textdomain("democracyplayer")
    _gt.bind_textdomain_codeset("democracyplayer","UTF-8")

def gettext(text):
    try:
        return _gtcache[text]
    except KeyError:
        out = _gt.gettext(text).decode('utf-8')
        _gtcache[text] = out
        return out
    except TypeError:
        print "DTV: WARNING: gettext not initialized for string \"%s\"" % text
        import traceback
        traceback.print_stack()
        return text

def ngettext(text1, text2, count):
    try:
        return _gtcache[(text1,text2,count)]
    except:
        out = _gt.ngettext(text1, text2, count).decode('utf-8')
        _gtcache[(text1,text2,count)] = out
        return out