From 0d59c73ce3f5b569df6037436654c24f19c5e537 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 7 May 2017 21:11:29 +0200 Subject: Use glib to get the installation prefix on Windows (bzr r15675.1.1) --- src/main.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 3a7050f9b..c4fcb6589 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -680,19 +680,19 @@ main(int argc, char **argv) #endif #ifdef WIN32 - gchar *exedir = g_strdup(win32_getExePath().data()); - _win32_set_inkscape_env(exedir); + gchar *datadir = g_win32_get_package_installation_directory_of_module(NULL); + _win32_set_inkscape_env(datadir); # ifdef ENABLE_NLS // obtain short path to executable dir and pass it // to bindtextdomain (it doesn't understand UTF-8) - gchar *shortexedir = g_win32_locale_filename_from_utf8(exedir); - gchar *localepath = g_build_filename(shortexedir, PACKAGE_LOCALE_DIR, NULL); + 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(shortexedir); + g_free(shortdatadir); g_free(localepath); # endif - g_free(exedir); + g_free(datadir); // Don't touch the registry (works fine without it) for Inkscape Portable gchar const *val = g_getenv("INKSCAPE_PORTABLE_PROFILE_DIR"); -- cgit v1.2.3 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/CMakeLists.txt | 6 ++-- src/helper/gettext.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++++++ src/helper/gettext.h | 44 +++++++++++++++++++++++++ src/main.cpp | 38 +++------------------- 4 files changed, 136 insertions(+), 35 deletions(-) create mode 100644 src/helper/gettext.cpp create mode 100644 src/helper/gettext.h (limited to 'src') diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt index 92709e4e9..443648c5c 100644 --- a/src/helper/CMakeLists.txt +++ b/src/helper/CMakeLists.txt @@ -10,12 +10,13 @@ set(sp_marshal_SRC set(helper_SRC action.cpp - action-context.cpp + action-context.cpp geom.cpp geom-nodetype.cpp geom-pathstroke.cpp geom-pathvectorsatellites.cpp geom-satellite.cpp + gettext.cpp gnome-utils.cpp pixbuf-ops.cpp png-write.cpp @@ -30,13 +31,14 @@ set(helper_SRC # ------- # Headers action.h - action-context.h + action-context.h geom-curves.h geom-nodetype.h geom-pathstroke.h geom-pathvectorsatellites.h geom-satellite.h geom.h + gettext.h gnome-utils.h mathfns.h pixbuf-ops.h 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 diff --git a/src/helper/gettext.h b/src/helper/gettext.h new file mode 100644 index 000000000..2a072b9e0 --- /dev/null +++ b/src/helper/gettext.h @@ -0,0 +1,44 @@ +/** + * \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 . + */ + +#ifndef SEEN_GETTEXT_HELPER_H +#define SEEN_GETTEXT_HELPER_H + +namespace Inkscape { + void initialize_gettext(); +} + +#endif // SEEN_GETTEXT_HELPER_H + +/* + 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 diff --git a/src/main.cpp b/src/main.cpp index c4fcb6589..02562383a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,6 +80,7 @@ #include "debug/log-display-config.h" #include "helper/action-context.h" +#include "helper/gettext.h" #include "helper/png-write.h" #include @@ -679,19 +680,13 @@ main(int argc, char **argv) fpsetmask(fpgetmask() & ~(FP_X_DZ | FP_X_INV)); #endif +#ifdef ENABLE_NLS + Inkscape::initialize_gettext(); +#endif + #ifdef WIN32 gchar *datadir = g_win32_get_package_installation_directory_of_module(NULL); _win32_set_inkscape_env(datadir); - -# ifdef ENABLE_NLS - // 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); -# endif g_free(datadir); // Don't touch the registry (works fine without it) for Inkscape Portable @@ -705,29 +700,6 @@ main(int argc, char **argv) // see also https://bugzilla.gnome.org/show_bug.cgi?id=778791 g_setenv("GTK_CSD", "0", FALSE); #endif - -#ifdef ENABLE_NLS -# ifndef WIN32 -# 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); -#endif - set_extensions_env(); // Prevents errors like "Unable to wrap GdkPixbuf..." (in nr-filter-image.cpp for example) -- 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 ++++++++++++++++++++++++++++-- src/helper/gettext.h | 2 ++ src/main.cpp | 7 ++----- 3 files changed, 32 insertions(+), 7 deletions(-) (limited to 'src') 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()); +} } diff --git a/src/helper/gettext.h b/src/helper/gettext.h index 2a072b9e0..689bddbbb 100644 --- a/src/helper/gettext.h +++ b/src/helper/gettext.h @@ -28,6 +28,8 @@ namespace Inkscape { void initialize_gettext(); + void bind_textdomain_codeset_utf8(); + void bind_textdomain_codeset_console(); } #endif // SEEN_GETTEXT_HELPER_H diff --git a/src/main.cpp b/src/main.cpp index 02562383a..b2817fa97 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -857,10 +857,7 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) // temporarily switch gettext encoding to locale, so that help messages can be output properly - std::string charset; - Glib::get_charset(charset); - - bind_textdomain_codeset(GETTEXT_PACKAGE, charset.c_str()); + Inkscape::bind_textdomain_codeset_console(); poptContext ctx = poptGetContext(NULL, argc, argv, options, 0); poptSetOtherOptionHelp(ctx, _("[OPTIONS...] [FILE...]\n\nAvailable options:")); @@ -871,7 +868,7 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) poptFreeContext(ctx); // now switch gettext back to UTF-8 (for GUI) - bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + Inkscape::bind_textdomain_codeset_utf8(); // Now let's see if the file list still holds up if ( needToRecodeParams ) -- cgit v1.2.3 From f5ab987943d3d54291dfe9369b7cb9855ddb7d8f Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Mon, 8 May 2017 00:14:37 +0200 Subject: Properly handle ENABLE_NLS define (bzr r15675.1.4) --- src/main.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index b2817fa97..4c63402fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,8 +80,10 @@ #include "debug/log-display-config.h" #include "helper/action-context.h" -#include "helper/gettext.h" #include "helper/png-write.h" +#ifdef ENABLE_NLS +#include "helper/gettext.h" +#endif #include #include @@ -108,10 +110,6 @@ #include #include -#ifndef HAVE_BIND_TEXTDOMAIN_CODESET -#define bind_textdomain_codeset(p,c) -#endif - #include "main-cmdlineact.h" #include "main-cmdlinexact.h" #include "widgets/icon.h" @@ -851,13 +849,10 @@ static GSList *fixupFilenameEncoding( GSList* fl ) static int sp_common_main( int argc, char const **argv, GSList **flDest ) { - /// \todo fixme: Move these to some centralized location (Lauris) - //sp_object_type_register("sodipodi:namedview", SP_TYPE_NAMEDVIEW); - //sp_object_type_register("sodipodi:guide", SP_TYPE_GUIDE); - - +#ifdef ENABLE_NLS // temporarily switch gettext encoding to locale, so that help messages can be output properly Inkscape::bind_textdomain_codeset_console(); +#endif poptContext ctx = poptGetContext(NULL, argc, argv, options, 0); poptSetOtherOptionHelp(ctx, _("[OPTIONS...] [FILE...]\n\nAvailable options:")); @@ -866,9 +861,11 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) /* Collect own arguments */ GSList *fl = sp_process_args(ctx); poptFreeContext(ctx); - + +#ifdef ENABLE_NLS // now switch gettext back to UTF-8 (for GUI) Inkscape::bind_textdomain_codeset_utf8(); +#endif // Now let's see if the file list still holds up if ( needToRecodeParams ) -- cgit v1.2.3 From ee7eeb26f4841bf3aa7561c8c9ebcb775cc3dbd8 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Mon, 8 May 2017 01:04:02 +0200 Subject: Inkview: Fix localization (bzr r15675.1.5) --- src/inkview.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/inkview.cpp b/src/inkview.cpp index 4f8665a02..a7a6b6a78 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -34,7 +34,6 @@ #include #include -#include #include #include @@ -49,16 +48,18 @@ #include "preferences.h" #include +#include + #include "document.h" #include "svg-view.h" #include "svg-view-widget.h" #include "util/units.h" +#ifdef ENABLE_NLS +#include "helper/gettext.h" +#endif -#include "inkscape.h" -#ifndef HAVE_BIND_TEXTDOMAIN_CODESET -#define bind_textdomain_codeset(p,c) -#endif +#include "inkscape.h" #include "ui/icon-names.h" @@ -231,6 +232,7 @@ public: _entry_timer.set_short_name('t'); _entry_timer.set_long_name("timer"); _entry_timer.set_arg_description(_("NUM")); + _entry_timer.set_description(_("Reset timer:")); add_entry(_entry_timer, timer); // Entry for the remaining non-option arguments @@ -248,28 +250,23 @@ private: int main (int argc, char **argv) { +#ifdef ENABLE_NLS + Inkscape::initialize_gettext(); +#endif + Glib::OptionContext opt(_("Open SVG files")); InkviewOptionsGroup grp; opt.set_main_group(grp); - + // Prevents errors like "Unable to wrap GdkPixbuf..." (in nr-filter-image.cpp for example) Gtk::Main::init_gtkmm_internals(); Gtk::Main main_instance (argc, argv, opt); - bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - LIBXML_TEST_VERSION Inkscape::GC::init(); Inkscape::Preferences::get(); // ensure preferences are initialized -#ifdef lalaWITH_MODULES - g_warning ("Have to autoinit modules (lauris)"); - sp_modulesys_init(); -#endif /* WITH_MODULES */ - Inkscape::Application::create(argv[0], true); if(filenames.empty()) -- cgit v1.2.3