a b/rdpl2stream/lib/i18n.py
1
# -*- coding: utf-8 -*-
2
3
__all__ = ['_', 'C_', 'ngettext']
4
5
program = 'radiotray'
6
7
import locale
8
LC_ALL = locale.setlocale(locale.LC_ALL, '')
9
10
try:
11
    import gettext
12
    from gettext import gettext as _, ngettext
13
    gettext.install(program, unicode=True)
14
    gettext.textdomain(program)
15
    locale.textdomain(program)
16
17
    def C_(ctx, s):
18
        """Provide qualified translatable strings via context.
19
            Taken from gnome-games.
20
        """
21
        translated = gettext.gettext('%s\x04%s' % (ctx, s))
22
        if '\x04' in translated:
23
            # no translation found, return input string
24
            return s
25
        return translated
26
    import __builtin__
27
    __builtin__.__dict__['ngettext'] = ngettext
28
    __builtin__.__dict__['C_'] = C_
29
except ImportError:
30
    import sys
31
    print >> sys.stderr, ("You don't have gettext module, no " \
32
        "internationalization will be used.")
33
    import __builtin__
34
    __builtin__.__dict__['_'] = lambda x: x
35
    __builtin__.__dict__['ngettext'] = lambda x, y, n: (n == 1) and x or y