File: i18n.py

package info (click to toggle)
gnome-keysign 1.3.0-5.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,460 kB
  • sloc: python: 5,143; xml: 126; makefile: 33; sh: 16
file content (42 lines) | stat: -rw-r--r-- 1,240 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python

import gettext
import locale
import logging
import os

log = logging.getLogger(__name__)

APP = 'keysign'
# We have pretty much no idea what we're doing here.
# We want to be able to find the compiled message catalogues
# not only when the app has been installed, but also
# when it's being run from source.  Hence we're using
# a path relative to this file, hoping that it will cater
# for both use cases.  Feel free to improve.
DIR = os.path.join(os.path.dirname(__file__), 'locale')

## This is for C libraries, I think. I.e. not for pure python
## ones like us.  We do, however, need this for Gtk.Builder
## to load translations
try:
    locale.setlocale(locale.LC_ALL, '')
except locale.Error:
    log.exception("Cannot set locale")
locale.bindtextdomain(APP, DIR)
locale.textdomain(APP)
gettext.bindtextdomain(APP, DIR)
gettext.textdomain(APP)
lang = gettext.translation(APP, DIR, fallback=True)

## This seems to cause "_" to be installed into globals.
## Let's not do that to not confuse libraries that we include
# gettext.install(APP, DIR, unicode=1)


from locale import gettext as _

try:
    _ = lang.ugettext
except AttributeError:
    log.info("Cannot get ugettext from lang: %r", lang, exc_info=True)