Force an addon translation to be in a given language(s)
svn: r15718
This commit is contained in:
parent
534fac7b93
commit
99101d2166
@ -197,15 +197,19 @@ def get_localedomain():
|
|||||||
"""
|
"""
|
||||||
return 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.
|
Get a translator for an addon.
|
||||||
|
|
||||||
filename - filename of a file in directory with full path, or
|
filename - filename of a file in directory with full path, or
|
||||||
None to get from running code
|
None to get from running code
|
||||||
domain - the name of the .mo file under the LANG/LC_MESSAGES dir
|
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
|
returns - a gettext.translation object
|
||||||
|
|
||||||
|
Example:
|
||||||
|
_ = get_addon_translator(languages=["fr_BE.utf8"]).gettext
|
||||||
|
|
||||||
The return object has the following properties and methods:
|
The return object has the following properties and methods:
|
||||||
.gettext
|
.gettext
|
||||||
.info
|
.info
|
||||||
@ -226,8 +230,13 @@ def get_addon_translator(filename=None, domain="addon"):
|
|||||||
gramps_translator = gettext.translation(LOCALEDOMAIN, LOCALEDIR,
|
gramps_translator = gettext.translation(LOCALEDOMAIN, LOCALEDIR,
|
||||||
fallback=True)
|
fallback=True)
|
||||||
path = os.path.dirname(os.path.abspath(filename))
|
path = os.path.dirname(os.path.abspath(filename))
|
||||||
addon_translator = gettext.translation(domain, os.path.join(path,"locale"),
|
if languages:
|
||||||
fallback=True)
|
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)
|
gramps_translator.add_fallback(addon_translator)
|
||||||
return gramps_translator # with a language fallback
|
return gramps_translator # with a language fallback
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user