Add ability to ask for addon translator without giving filename, ala our Glade API
svn: r14084
This commit is contained in:
parent
943dbc97b4
commit
3413cf0372
@ -31,6 +31,7 @@ Provide translation assistance
|
|||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
import gettext as translate
|
import gettext as translate
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -79,12 +80,14 @@ def get_localedomain():
|
|||||||
"""
|
"""
|
||||||
return LOCALEDOMAIN
|
return LOCALEDOMAIN
|
||||||
|
|
||||||
def get_addon_translator(filename, domain="addon"):
|
def get_addon_translator(filename=None, domain="addon"):
|
||||||
"""
|
"""
|
||||||
Get a translator for an addon.
|
Get a translator for an addon.
|
||||||
filename - with full path
|
|
||||||
domain - the name of the .mo file under the LANG/LC_MESSAGES dir
|
filename - filename of a file in directory with full path, or
|
||||||
returns - a gettext.translation object
|
None to get from running code
|
||||||
|
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:
|
The return object has the following properties and methods:
|
||||||
.gettext
|
.gettext
|
||||||
@ -101,6 +104,8 @@ def get_addon_translator(filename, domain="addon"):
|
|||||||
Assumes path/filename
|
Assumes path/filename
|
||||||
path/locale/LANG/LC_MESSAGES/addon.mo.
|
path/locale/LANG/LC_MESSAGES/addon.mo.
|
||||||
"""
|
"""
|
||||||
|
if filename is None:
|
||||||
|
filename = sys._getframe(1).f_code.co_filename
|
||||||
gramps_translator = translate.translation(LOCALEDOMAIN, LOCALEDIR,
|
gramps_translator = translate.translation(LOCALEDOMAIN, LOCALEDIR,
|
||||||
fallback=True)
|
fallback=True)
|
||||||
path = os.path.dirname(os.path.abspath(filename))
|
path = os.path.dirname(os.path.abspath(filename))
|
||||||
|
Loading…
Reference in New Issue
Block a user