implement gettext localization for python

make gnc_path_get_localedir() and GETTEXT_PACKAGE available for python
to access locales. Import gettext module to provide _ as translator
method. Provide null _-method returning english text in case of missing gettext.
Make a lot of messages translatable by adding _-method. Include python
files to create .pot-files.
This commit is contained in:
c-holtermann
2020-02-29 16:16:05 +01:00
parent 890637b2dc
commit 41dc6ddbe2
4 changed files with 33 additions and 2 deletions

View File

@@ -28,7 +28,8 @@
# @author Jeff Green, ParIT Worker Co-operative <jeff@parit.ca>
# @ingroup python_bindings
import gnucash.gnucash_core_c as gnucash_core_c
from gnucash import gnucash_core_c
from gnucash import _sw_core_utils
from gnucash.function_class import \
ClassFromFunctions, extract_attributes_with_prefix, \
@@ -46,6 +47,24 @@ from gnucash.gnucash_core_c import gncInvoiceLookup, gncInvoiceGetInvoiceFromTxn
gnc_numeric_create, double_to_gnc_numeric, string_to_gnc_numeric, \
gnc_numeric_to_string
try:
import gettext
# install gettext for _-function, needs path to locales
_localedir = _sw_core_utils.gnc_path_get_localedir()
_translation = gettext.translation(_sw_core_utils.GETTEXT_PACKAGE, _localedir)
_ = _translation.gettext
except:
print("\nProblem importing gettext!")
import traceback
import sys
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback)
print()
def _(s):
"""Null translator function, gettext not available"""
return s
class GnuCashCoreClass(ClassFromFunctions):
_module = gnucash_core_c