mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Merge Christoph Holterman's python-gettext-localize into master.
This commit is contained in:
commit
5091d7a670
@ -57,6 +57,12 @@ gchar * gnc_path_get_scmdir(void);
|
||||
%newobject gnc_path_get_reportsdir;
|
||||
gchar * gnc_path_get_reportsdir(void);
|
||||
|
||||
%newobject gnc_path_get_localedir;
|
||||
gchar * gnc_path_get_localedir(void);
|
||||
|
||||
/* Name of our gettext-domain (defined in config.h) */
|
||||
%constant char* GETTEXT_PACKAGE = GETTEXT_PACKAGE;
|
||||
|
||||
%newobject gnc_path_get_stdreportsdir;
|
||||
gchar * gnc_path_get_stdreportsdir(void);
|
||||
|
||||
|
@ -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,27 @@ 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
|
||||
|
||||
_localedir = _sw_core_utils.gnc_path_get_localedir()
|
||||
gettext.install(_sw_core_utils.GETTEXT_PACKAGE, _localedir)
|
||||
except:
|
||||
print()
|
||||
print("Problem 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
|
||||
|
||||
import builtins
|
||||
builtins.__dict__['_'] = _
|
||||
|
||||
class GnuCashCoreClass(ClassFromFunctions):
|
||||
_module = gnucash_core_c
|
||||
|
||||
|
@ -16,6 +16,7 @@ endif()
|
||||
|
||||
set(test_python_bindings_DATA
|
||||
runTests.py.in
|
||||
test_gettext.py
|
||||
test_account.py
|
||||
test_book.py
|
||||
test_business.py
|
||||
|
@ -5,6 +5,7 @@ import os
|
||||
|
||||
os.environ["GNC_UNINSTALLED"] = "1"
|
||||
|
||||
from test_gettext import TestGettext
|
||||
from test_session import TestSession
|
||||
from test_book import TestBook
|
||||
from test_account import TestAccount
|
||||
|
19
bindings/python/tests/test_gettext.py
Normal file
19
bindings/python/tests/test_gettext.py
Normal file
@ -0,0 +1,19 @@
|
||||
# test gettext
|
||||
#
|
||||
# @date 2020-04-08
|
||||
# @author Christoph Holtermann <mail@c-holtermann.net>
|
||||
|
||||
from unittest import TestCase, main
|
||||
import gnucash
|
||||
from gnucash import _sw_core_utils
|
||||
|
||||
|
||||
class TestGettext(TestCase):
|
||||
def test_import_gettext(self):
|
||||
import gettext
|
||||
|
||||
def test_get_localedir(self):
|
||||
_localedir = _sw_core_utils.gnc_path_get_localedir()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -1,16 +1,21 @@
|
||||
import sys
|
||||
from gnucash import *
|
||||
from gnucash import _sw_app_utils
|
||||
from gnucash import _sw_core_utils
|
||||
from gnucash._sw_core_utils import gnc_prefs_is_extra_enabled, gnc_prefs_is_debugging_enabled
|
||||
from gi import require_version
|
||||
require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
import os
|
||||
|
||||
sys.path.append(os.path.dirname(__file__))
|
||||
|
||||
# output file location if gnucash has been started with
|
||||
# gnucash --extra
|
||||
if gnc_prefs_is_extra_enabled():
|
||||
print("Python shell init file: %s" % (__file__))
|
||||
print("\n" + "The following string should appear translated in your preferred language:" + "\n")
|
||||
print("\n" + _("Welcome to GnuCash") +"\n")
|
||||
|
||||
# Importing the console class causes SIGTTOU to be thrown if GnuCash is
|
||||
# started in the background. This causes a hang if it is not handled,
|
||||
@ -95,7 +100,7 @@ class Console (cons.Console):
|
||||
def quit (self):
|
||||
""" quit """
|
||||
|
||||
self.write("\nHave a nice day !\n")
|
||||
self.write("\n" + _("Have a nice day!") + "\n")
|
||||
return super(Console, self).quit()
|
||||
|
||||
|
||||
@ -104,9 +109,14 @@ class Console (cons.Console):
|
||||
# shelltype can either be "python" or "ipython" (the latter is not yet fully functional)
|
||||
if False:
|
||||
shelltype = "python"
|
||||
title = "gnucash "+shelltype+" shell"
|
||||
if shelltype=="python":
|
||||
shelltypeName = "Python"
|
||||
else:
|
||||
shelltypeName = "IPython"
|
||||
banner_style = 'title'
|
||||
banner = "Welcome to "+title+"!\n"
|
||||
# TRANSLATORS: %s is either Python or IPython
|
||||
banner = _("Welcome to GnuCash %s Shell") % shelltypeName
|
||||
console = Console(argv = [], shelltype = shelltype, banner = [[banner, banner_style]], size = 100)
|
||||
|
||||
window = Gtk.Window(type = Gtk.WindowType.TOPLEVEL)
|
||||
window.set_position(Gtk.WindowPosition.CENTER)
|
||||
|
@ -75,7 +75,7 @@ function(make_gnucash_potfiles)
|
||||
${CMAKE_SOURCE_DIR}/*.glade ${CMAKE_SOURCE_DIR}/*.desktop.in.in
|
||||
${CMAKE_SOURCE_DIR}/*.gschema.xml.in ${CMAKE_SOURCE_DIR}/*.appdata.xml.in.in
|
||||
${CMAKE_SOURCE_DIR}/*.keys.in ${CMAKE_SOURCE_DIR}/*.scm
|
||||
${CMAKE_SOURCE_DIR}/*/qofbookslots.h
|
||||
${CMAKE_SOURCE_DIR}/*.py ${CMAKE_SOURCE_DIR}/*/qofbookslots.h
|
||||
${CMAKE_SOURCE_DIR}/*/gnc-commodity.h
|
||||
)
|
||||
|
||||
|
@ -12,6 +12,28 @@ bindings/guile/gnc-kvp-guile.cpp
|
||||
bindings/guile/gnc-module.scm
|
||||
bindings/guile/gnc-numeric.scm
|
||||
bindings/guile/utilities.scm
|
||||
bindings/python/app_utils.py
|
||||
bindings/python/example_scripts/account_analysis.py
|
||||
bindings/python/example_scripts/change_tax_code.py
|
||||
bindings/python/example_scripts/gnc_convenience.py
|
||||
bindings/python/example_scripts/gncinvoicefkt.py
|
||||
bindings/python/example_scripts/gncinvoice_jinja.py
|
||||
bindings/python/example_scripts/latex_invoices.py
|
||||
bindings/python/example_scripts/new_book_with_opening_balances.py
|
||||
bindings/python/example_scripts/price_database_example.py
|
||||
bindings/python/example_scripts/quotes_historic.py
|
||||
bindings/python/example_scripts/rest-api/gnucash_rest.py
|
||||
bindings/python/example_scripts/rest-api/gnucash_simple.py
|
||||
bindings/python/example_scripts/simple_book.py
|
||||
bindings/python/example_scripts/simple_business_create.py
|
||||
bindings/python/example_scripts/simple_invoice_insert.py
|
||||
bindings/python/example_scripts/simple_session.py
|
||||
bindings/python/example_scripts/simple_sqlite_create.py
|
||||
bindings/python/example_scripts/str_methods.py
|
||||
bindings/python/function_class.py
|
||||
bindings/python/gnucash_business.py
|
||||
bindings/python/gnucash_core.py
|
||||
bindings/python/__init__.py
|
||||
borrowed/goffice/go-charmap-sel.c
|
||||
borrowed/goffice/go-glib-extras.c
|
||||
borrowed/goffice/go-optionmenu.c
|
||||
@ -350,6 +372,13 @@ gnucash/import-export/qif-imp/qif-utils.scm
|
||||
gnucash/import-export/qif-imp/string.scm
|
||||
gnucash/price-quotes.scm
|
||||
gnucash/python/gncmod-python.c
|
||||
gnucash/python/init.py
|
||||
gnucash/python/pycons/console.py
|
||||
gnucash/python/pycons/__init__.py
|
||||
gnucash/python/pycons/ishell.py
|
||||
gnucash/python/pycons/setup.py
|
||||
gnucash/python/pycons/shell.py
|
||||
gnucash/python/pycons/simple_plot.py
|
||||
gnucash/register/ledger-core/gncEntryLedger.c
|
||||
gnucash/register/ledger-core/gncEntryLedgerControl.c
|
||||
gnucash/register/ledger-core/gncEntryLedgerDisplay.c
|
||||
|
Loading…
Reference in New Issue
Block a user