Fixes translation problem for addons

svn: r13499
This commit is contained in:
Doug Blank 2009-11-04 23:20:35 +00:00
parent 811463d770
commit be9c8df643

View File

@ -73,27 +73,35 @@ def setup_gettext():
#used sometimes: #used sometimes:
#gettext.install(LOCALEDOMAIN, LOCALEDIR, unicode=1) #gettext.install(LOCALEDOMAIN, LOCALEDIR, unicode=1)
def get_addon_translator(filename, domain='addon'): def get_addon_translator(filename, domain="addon"):
""" """
Get a translator for an addon. Get a translator for an addon.
Assumes filename_dir/locale/LANG/LC_MESSAGES/addon.mo. filename - with full path
domain - the name of the .mo file under the LANG/LC_MESSAGES dir
returns - a gettext.translation object
The return object has the following properties and methods:
.gettext
.info
.lgettext
.lngettext
.ngettext
.output_charset
.plural
.set_output_charset
.ugettext
.ungettext
Assumes path/filename
path/locale/LANG/LC_MESSAGES/addon.mo.
""" """
import locale gramps_translator = gettext.translation(LOCALEDOMAIN, LOCALEDIR,
LANG = locale.getlocale()[0] or "en" fallback=True)
path = os.path.dirname(os.path.abspath(filename)) path = os.path.dirname(os.path.abspath(filename))
trans = Translator(LANG) addon_translator = gettext.translation(domain, os.path.join(path,"locale"),
try: fallback=True)
fallback = gettext.translation(domain, gramps_translator.add_fallback(addon_translator)
os.path.join(path, "locale"), return gramps_translator # with a language fallback
languages=[LANG])
trans.trans.add_fallback(fallback)
except:
pass
# FIXME: perhaps give some feedback when you need it
#if LANG and not LANG.startswith("en"):
# print ("WARN: can't add local '%s' addon translation for '%s'." %
# (filename, LANG))
return trans
def get_available_translations(): def get_available_translations():
""" """