gnucash master: Fix translations using boost::locale::translate

Geert Janssens gjanssens at
Tue Jun 9 17:07:16 EDT 2020

Updated	 via (commit)
	from (commit)

commit 69a04be353c3fe5d58c1ec29bc2cdf1fd02410a9
Author: Geert Janssens <geert at>
Date:   Tue Jun 9 22:58:01 2020 +0200

    Fix translations using boost::locale::translate
    This requires a std::locale generated from a boost::locale::generator
    The examples already in our code base used the wrong message_path while
    creating the generator and as a result our message catalogs weren't found.
    As with the std::locale I have added code to create a locale via
    boost::locale only once instead of having each c++ file redo the work.
    This code expects a message_path to set for the boost generator.
    An earlier attempt queried for this path directly from within
    gnc-locale-utils using gnc_get_locale_dir (from gnc-path.h).
    That however broke several c++ tests depending on gnc_locale_utils as those
    then also needed to be linked against gnc-path.o. I couldn't get the linker
    to do this properly so I worked around it for now by splitting the boost_locale
    functionality in two steps:
    - an initializer step that takes the messages_path as a string and will
      generate the locale
    - a getter to get the locale.
    The initializer should only be run once, and before the getter is called.
    It won't hurt though if the initializer is called more often.
    If the getter is called before the initializer it will still
    generate a std::locale but without setting a messages_path. It will then
    also log a warning explaining translations may not be properly found.

Summary of changes:
 gnucash/gnucash-core-app.cpp                       |  7 ++--
 gnucash/gnucash.cpp                                |  4 +-
 .../csv-imp/assistant-csv-trans-import.cpp         |  2 +-
 libgnucash/core-utils/gnc-filepath-utils.cpp       |  2 +-
 libgnucash/core-utils/gnc-locale-utils.cpp         | 46 ++++++++++++++++++++++
 libgnucash/core-utils/gnc-locale-utils.hpp         | 27 +++++++++++++
 6 files changed, 81 insertions(+), 7 deletions(-)

More information about the gnucash-patches mailing list