summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEduard Braun <eduard.braun2@gmx.de>2017-05-08 19:09:32 +0000
committerEduard Braun <eduard.braun2@gmx.de>2017-05-08 19:09:32 +0000
commitdbffb900837a0c14e70fc9942b6d44fd74ae69d8 (patch)
treedd1a0fd24776d5ea4de127d6c3b3d8b518aff408 /src
parentFix typo in POTFILES.in (diff)
parentInkview: Fix localization (diff)
downloadinkscape-dbffb900837a0c14e70fc9942b6d44fd74ae69d8.tar.gz
inkscape-dbffb900837a0c14e70fc9942b6d44fd74ae69d8.zip
Move gettext initialization to separate function and re-use it in inkview (localization was broken)
(bzr r15676)
Diffstat (limited to 'src')
-rw-r--r--src/helper/CMakeLists.txt6
-rw-r--r--src/helper/gettext.cpp109
-rw-r--r--src/helper/gettext.h46
-rw-r--r--src/inkview.cpp27
-rw-r--r--src/main.cpp68
5 files changed, 188 insertions, 68 deletions
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..0972d4e19
--- /dev/null
+++ b/src/helper/gettext.cpp
@@ -0,0 +1,109 @@
+/**
+ * \file
+ * \brief helper functions for gettext
+ *//*
+ * Authors:
+ * Eduard Braun <eduard.braun2@gmx.de>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+#include <string>
+#include <glibmm.h>
+#include <glibmm/i18n.h>
+
+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);
+
+ // 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);
+}
+
+/** 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());
+}
+
+}
+
+
+/*
+ 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..689bddbbb
--- /dev/null
+++ b/src/helper/gettext.h
@@ -0,0 +1,46 @@
+/**
+ * \file
+ * \brief helper functions for gettext
+ *//*
+ * Authors:
+ * Eduard Braun <eduard.braun2@gmx.de>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SEEN_GETTEXT_HELPER_H
+#define SEEN_GETTEXT_HELPER_H
+
+namespace Inkscape {
+ void initialize_gettext();
+ void bind_textdomain_codeset_utf8();
+ void bind_textdomain_codeset_console();
+}
+
+#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/inkview.cpp b/src/inkview.cpp
index 4f8665a02..a7a6b6a78 100644
--- a/src/inkview.cpp
+++ b/src/inkview.cpp
@@ -34,7 +34,6 @@
#include <sys/stat.h>
#include <locale.h>
-#include <glibmm/optionentry.h>
#include <gtkmm/applicationwindow.h>
#include <gtkmm/button.h>
@@ -49,16 +48,18 @@
#include "preferences.h"
#include <glibmm/i18n.h>
+#include <glibmm/optionentry.h>
+
#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())
diff --git a/src/main.cpp b/src/main.cpp
index 3a7050f9b..4c63402fb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -81,6 +81,9 @@
#include "helper/action-context.h"
#include "helper/png-write.h"
+#ifdef ENABLE_NLS
+#include "helper/gettext.h"
+#endif
#include <extension/extension.h>
#include <extension/db.h>
@@ -107,10 +110,6 @@
#include <gtkmm/main.h>
#include <gtkmm/window.h>
-#ifndef HAVE_BIND_TEXTDOMAIN_CODESET
-#define bind_textdomain_codeset(p,c)
-#endif
-
#include "main-cmdlineact.h"
#include "main-cmdlinexact.h"
#include "widgets/icon.h"
@@ -679,20 +678,14 @@ main(int argc, char **argv)
fpsetmask(fpgetmask() & ~(FP_X_DZ | FP_X_INV));
#endif
+#ifdef ENABLE_NLS
+ Inkscape::initialize_gettext();
+#endif
+
#ifdef WIN32
- gchar *exedir = g_strdup(win32_getExePath().data());
- _win32_set_inkscape_env(exedir);
-
-# 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);
- bindtextdomain(GETTEXT_PACKAGE, localepath);
- g_free(shortexedir);
- g_free(localepath);
-# endif
- g_free(exedir);
+ gchar *datadir = g_win32_get_package_installation_directory_of_module(NULL);
+ _win32_set_inkscape_env(datadir);
+ g_free(datadir);
// Don't touch the registry (works fine without it) for Inkscape Portable
gchar const *val = g_getenv("INKSCAPE_PORTABLE_PROFILE_DIR");
@@ -705,29 +698,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)
@@ -879,16 +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
- std::string charset;
- Glib::get_charset(charset);
-
- bind_textdomain_codeset(GETTEXT_PACKAGE, charset.c_str());
+ Inkscape::bind_textdomain_codeset_console();
+#endif
poptContext ctx = poptGetContext(NULL, argc, argv, options, 0);
poptSetOtherOptionHelp(ctx, _("[OPTIONS...] [FILE...]\n\nAvailable options:"));
@@ -897,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)
- bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+ Inkscape::bind_textdomain_codeset_utf8();
+#endif
// Now let's see if the file list still holds up
if ( needToRecodeParams )