Added a function to get a translation with fallback for addons
svn: r13475
This commit is contained in:
@ -73,6 +73,25 @@ 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'):
|
||||||
|
"""
|
||||||
|
Get a translator for an addon.
|
||||||
|
Assumes filename_dir/locale/LANG/LC_MESSAGES/addon.mo.
|
||||||
|
"""
|
||||||
|
import locale
|
||||||
|
LANG = locale.getlocale()[0]
|
||||||
|
path = os.path.dirname(os.path.abspath(filename))
|
||||||
|
trans = Translator(LANG)
|
||||||
|
try:
|
||||||
|
fallback = gettext.translation(domain,
|
||||||
|
os.path.join(path, "locale"),
|
||||||
|
languages=[LANG])
|
||||||
|
trans.trans.add_fallback(fallback)
|
||||||
|
except:
|
||||||
|
print ("WARN: can't add local '%s' addon translation for '%s'." %
|
||||||
|
(filename, LANG))
|
||||||
|
return trans
|
||||||
|
|
||||||
def get_available_translations():
|
def get_available_translations():
|
||||||
"""
|
"""
|
||||||
Get a list of available translations.
|
Get a list of available translations.
|
||||||
|
Reference in New Issue
Block a user