From 6e0b1cc358cadb3bfefceb39acf613ac7450b978 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 7 May 2017 22:50:07 +0200 Subject: Move gettext initialization into separate function so it can be re-used (will come in handy in inkview) (bzr r15675.1.2) --- src/helper/gettext.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/helper/gettext.cpp (limited to 'src/helper/gettext.cpp') diff --git a/src/helper/gettext.cpp b/src/helper/gettext.cpp new file mode 100644 index 000000000..4fa8df7ae --- /dev/null +++ b/src/helper/gettext.cpp @@ -0,0 +1,83 @@ +/** + * \file + * \brief helper functions for gettext + *//* + * Authors: + * Eduard Braun + * + * Copyright 2017 Authors + * + * This file is part of Inkscape. + * + * Inkscape is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Inkscape is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Inkscape. If not, see . + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +namespace Inkscape { + +void initialize_gettext() { +#ifdef WIN32 + gchar *datadir = g_win32_get_package_installation_directory_of_module(NULL); + + // obtain short path to executable dir and pass it + // to bindtextdomain (it doesn't understand UTF-8) + gchar *shortdatadir = g_win32_locale_filename_from_utf8(datadir); + gchar *localepath = g_build_filename(shortdatadir, PACKAGE_LOCALE_DIR, NULL); + bindtextdomain(GETTEXT_PACKAGE, localepath); + g_free(shortdatadir); + g_free(localepath); + + g_free(datadir); + +#else +# ifdef ENABLE_BINRELOC + bindtextdomain(GETTEXT_PACKAGE, BR_LOCALEDIR("")); +# else + bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); + // needed by Python/Gettext + g_setenv("PACKAGE_LOCALE_DIR", PACKAGE_LOCALE_DIR, TRUE); +# endif +#endif + + // Allow the user to override the locale directory by setting + // the environment variable INKSCAPE_LOCALEDIR. + char const *inkscape_localedir = g_getenv("INKSCAPE_LOCALEDIR"); + if (inkscape_localedir != NULL) { + bindtextdomain(GETTEXT_PACKAGE, inkscape_localedir); + } + + // common setup + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + textdomain(GETTEXT_PACKAGE); +} + +} + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace .0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim:filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99: \ No newline at end of file -- cgit v1.2.3 From c91214d837562c6244053dfeaf99aa2d8b8deded Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Mon, 8 May 2017 00:11:49 +0200 Subject: Move functions for switching gettext charset to helper/gettext.h (bzr r15675.1.3) --- src/helper/gettext.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/helper/gettext.cpp') diff --git a/src/helper/gettext.cpp b/src/helper/gettext.cpp index 4fa8df7ae..0972d4e19 100644 --- a/src/helper/gettext.cpp +++ b/src/helper/gettext.cpp @@ -27,11 +27,17 @@ # include "config.h" #endif -#include -#include +#ifdef WIN32 +#include +#endif + +#include +#include +#include namespace Inkscape { +/** does all required gettext initialization and takes care of the respective locale directory paths */ void initialize_gettext() { #ifdef WIN32 gchar *datadir = g_win32_get_package_installation_directory_of_module(NULL); @@ -67,6 +73,26 @@ void initialize_gettext() { bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); } + +/** set gettext codeset to UTF8 */ +void bind_textdomain_codeset_utf8() { + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); +} + +/** set gettext codeset to codeset of the console + * - on *nix this is typically the current locale, + * - on Windows it has to be determined using GetConsoleOutputCP() */ +void bind_textdomain_codeset_console() { + std::string charset; + Glib::get_charset(charset); + + // TODO: does not work properly as we spawn a child process on Windows + // (inkscape.exe is not a console application and can never print directly to console) + //unsigned int test = GetConsoleOutputCP(); + //g_message("CP%u", test); + + bind_textdomain_codeset(GETTEXT_PACKAGE, charset.c_str()); +} } -- cgit v1.2.3 From e1097ab39decf853abbb6a934c47afa841445237 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Wed, 10 May 2017 02:21:03 +0200 Subject: Use UTF8 encoding for output on windows console. This avoids the misery and frustration of converting to the overly limited ANSI codepages and does not seem to cause any issues so far. (bzr r15682) --- src/helper/gettext.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/helper/gettext.cpp') diff --git a/src/helper/gettext.cpp b/src/helper/gettext.cpp index 0972d4e19..91dfdbcb8 100644 --- a/src/helper/gettext.cpp +++ b/src/helper/gettext.cpp @@ -49,9 +49,8 @@ void initialize_gettext() { bindtextdomain(GETTEXT_PACKAGE, localepath); g_free(shortdatadir); g_free(localepath); - - g_free(datadir); + g_free(datadir); #else # ifdef ENABLE_BINRELOC bindtextdomain(GETTEXT_PACKAGE, BR_LOCALEDIR("")); @@ -79,21 +78,23 @@ void bind_textdomain_codeset_utf8() { bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); } -/** set gettext codeset to codeset of the console +/** set gettext codeset to codeset of the system console * - on *nix this is typically the current locale, - * - on Windows it has to be determined using GetConsoleOutputCP() */ + * - on Windows we don't care and simply use UTF8 + * any conversion would need to happen in our console wrappers (see winconsole.cpp) anyway + * as we have no easy way of determining console encoding from inkscape/inkview.exe process; + * for now do something even easier - switch console encoding to UTF8 and be done with it! + * this also works nicely on MSYS consoles where UTF8 encoding is used by default, too */ void bind_textdomain_codeset_console() { +#ifdef WIN32 + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); +#else std::string charset; Glib::get_charset(charset); - - // TODO: does not work properly as we spawn a child process on Windows - // (inkscape.exe is not a console application and can never print directly to console) - //unsigned int test = GetConsoleOutputCP(); - //g_message("CP%u", test); - bind_textdomain_codeset(GETTEXT_PACKAGE, charset.c_str()); +#endif } - + } -- cgit v1.2.3