summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEduard Braun <eduard.braun2@gmx.de>2017-05-07 22:11:49 +0000
committerEduard Braun <eduard.braun2@gmx.de>2017-05-07 22:11:49 +0000
commitc91214d837562c6244053dfeaf99aa2d8b8deded (patch)
tree1b3ddeb21999267f66f959406cb0c88f5e24b0bd /src
parentMove gettext initialization into separate function so it can be re-used (will... (diff)
downloadinkscape-c91214d837562c6244053dfeaf99aa2d8b8deded.tar.gz
inkscape-c91214d837562c6244053dfeaf99aa2d8b8deded.zip
Move functions for switching gettext charset to helper/gettext.h
(bzr r15675.1.3)
Diffstat (limited to 'src')
-rw-r--r--src/helper/gettext.cpp30
-rw-r--r--src/helper/gettext.h2
-rw-r--r--src/main.cpp7
3 files changed, 32 insertions, 7 deletions
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 <glib.h>
-#include <glib/gi18n.h>
+#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);
@@ -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 )