From 99101d2166d29e8e12f486ed5bb19c8a2ece9950 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Fri, 13 Aug 2010 03:55:54 +0000 Subject: [PATCH] Force an addon translation to be in a given language(s) svn: r15718 --- src/TransUtils.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/TransUtils.py b/src/TransUtils.py index dfa81f0a2..310b78afb 100644 --- a/src/TransUtils.py +++ b/src/TransUtils.py @@ -197,15 +197,19 @@ def get_localedomain(): """ return LOCALEDOMAIN -def get_addon_translator(filename=None, domain="addon"): +def get_addon_translator(filename=None, domain="addon", languages=None): """ Get a translator for an addon. filename - filename of a file in directory with full path, or None to get from running code domain - the name of the .mo file under the LANG/LC_MESSAGES dir + languages - a list of languages to force returns - a gettext.translation object + Example: + _ = get_addon_translator(languages=["fr_BE.utf8"]).gettext + The return object has the following properties and methods: .gettext .info @@ -226,8 +230,13 @@ def get_addon_translator(filename=None, domain="addon"): gramps_translator = gettext.translation(LOCALEDOMAIN, LOCALEDIR, fallback=True) path = os.path.dirname(os.path.abspath(filename)) - addon_translator = gettext.translation(domain, os.path.join(path,"locale"), - fallback=True) + if languages: + addon_translator = gettext.translation(domain, os.path.join(path,"locale"), + languages=languages, + fallback=True) + else: + addon_translator = gettext.translation(domain, os.path.join(path,"locale"), + fallback=True) gramps_translator.add_fallback(addon_translator) return gramps_translator # with a language fallback