Download this file

i18n.py    36 lines (30 with data), 1.0 kB

 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
# -*- coding: utf-8 -*-
__all__ = ['_', 'C_', 'ngettext']
program = 'radiotray'
import locale
LC_ALL = locale.setlocale(locale.LC_ALL, '')
try:
import gettext
from gettext import gettext as _, ngettext
gettext.install(program, unicode=True)
gettext.textdomain(program)
locale.textdomain(program)
def C_(ctx, s):
"""Provide qualified translatable strings via context.
Taken from gnome-games.
"""
translated = gettext.gettext('%s\x04%s' % (ctx, s))
if '\x04' in translated:
# no translation found, return input string
return s
return translated
import __builtin__
__builtin__.__dict__['ngettext'] = ngettext
__builtin__.__dict__['C_'] = C_
except ImportError:
import sys
print >> sys.stderr, ("You don't have gettext module, no " \
"internationalization will be used.")
import __builtin__
__builtin__.__dict__['_'] = lambda x: x
__builtin__.__dict__['ngettext'] = lambda x, y, n: (n == 1) and x or y