Added a function to get a translation with fallback for addons

svn: r13475
This commit is contained in:
Doug Blank 2009-11-01 14:26:21 +00:00
parent c43c3beba0
commit 0dc707ef7c

View File

@ -73,6 +73,25 @@ def setup_gettext():
#used sometimes:
#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():
"""
Get a list of available translations.