| 1 |
# vim:set et sts=4 sw=4: |
| 2 |
# |
| 3 |
# ibus - The Input Bus |
| 4 |
# |
| 5 |
# Copyright(c) 2007-2015 Peng Huang <[email protected]> |
| 6 |
# Copyright(c) 2012-2021 Takao Fujiwara <[email protected]> |
| 7 |
# Copyright(c) 2007-2015 Google, Inc. |
| 8 |
# Copyright(c) 2012-2021 Red Hat, Inc. |
| 9 |
# |
| 10 |
# This library is free software; you can redistribute it and/or |
| 11 |
# modify it under the terms of the GNU Lesser General Public |
| 12 |
# License as published by the Free Software Foundation; either |
| 13 |
# version 2.1 of the License, or (at your option) any later version. |
| 14 |
# |
| 15 |
# This library is distributed in the hope that it will be useful, |
| 16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 |
# Lesser General Public License for more details. |
| 19 |
# |
| 20 |
# You should have received a copy of the GNU Lesser General Public |
| 21 |
# License along with this library; if not, write to the Free Software |
| 22 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 23 |
# USA |
| 24 |
|
| 25 |
import locale |
| 26 |
import gettext |
| 27 |
import os |
| 28 |
import sys |
| 29 |
|
| 30 |
DOMAINNAME = "ibus10" |
| 31 |
|
| 32 |
_ = lambda a: gettext.dgettext(DOMAINNAME, a) |
| 33 |
N_ = lambda a: a |
| 34 |
|
| 35 |
PY3K = sys.version_info >= (3, 0) |
| 36 |
LOCALEDIR = os.getenv("IBUS_LOCALEDIR") |
| 37 |
|
| 38 |
def init_textdomain(domainname): |
| 39 |
if domainname == '': |
| 40 |
return |
| 41 |
# Python's locale module doesn't provide all methods on some |
| 42 |
# operating systems like FreeBSD |
| 43 |
try: |
| 44 |
locale.bindtextdomain(domainname, LOCALEDIR) |
| 45 |
locale.bind_textdomain_codeset(domainname, 'UTF-8') |
| 46 |
except AttributeError: |
| 47 |
pass |
| 48 |
gettext.bindtextdomain(domainname, LOCALEDIR) |
| 49 |
# https://docs.python.org/3/library/gettext.html#gettext.lgettext |
| 50 |
if not PY3K: |
| 51 |
gettext.bind_textdomain_codeset(domainname, 'UTF-8') |
| 52 |
|
| 53 |
def gettext_engine_longname(engine): |
| 54 |
name = engine.get_name() |
| 55 |
if (name.startswith('xkb:')): |
| 56 |
return gettext.dgettext('xkeyboard-config', engine.get_longname()) |
| 57 |
textdomain = engine.get_textdomain() |
| 58 |
if textdomain == '': |
| 59 |
return engine.get_longname() |
| 60 |
return gettext.dgettext(textdomain, engine.get_longname()) |
| 61 |
|
| 62 |
def gettext_engine_description(engine): |
| 63 |
name = engine.get_name() |
| 64 |
if (name.startswith('xkb:')): |
| 65 |
return gettext.dgettext('xkeyboard-config', engine.get_description()) |
| 66 |
textdomain = engine.get_textdomain() |
| 67 |
if textdomain == '': |
| 68 |
return engine.get_description() |
| 69 |
return gettext.dgettext(textdomain, engine.get_description()) |