From 8bef6bcb1745f93a4c7a96baaaa5bfdc072144a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Fri, 18 Oct 2019 19:29:55 +0200 Subject: [PATCH] First inits for translations --- CMakeLists.txt | 9 +++++++++ main.c | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4412d17..7bd759c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,15 @@ pkg_check_modules(CAIRO REQUIRED cairo) add_compile_options(-Wall -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter) +IF(CMAKE_BUILD_TYPE STREQUAL "Debug") + message("${Yellow}Debug mode for translations used!${ColorReset}") + add_definitions(-DGETTEXT_PACKAGE=\"gds-render\" -DLOCALEDATADIR=\"/usr/share\") +else(CMAKE_BUILD_TYPE STREQUAL "Debug") + message("Global locale directory used. Make sure files in /usr/share/locale are available") + add_definitions(-DGETTEXT_PACKAGE=\"gds-render\" -DLOCALEDATADIR=\"/usr/share\") +ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") + + add_subdirectory(resources) add_subdirectory(doxygen) add_subdirectory(version) diff --git a/main.c b/main.c index b1a333f..87280fb 100644 --- a/main.c +++ b/main.c @@ -23,9 +23,13 @@ * @author Mario Hüttel */ + + #include #include #include +#include +#include #include #include @@ -91,8 +95,8 @@ static void app_about(GSimpleAction *action, GVariant *parameter, gpointer user_ (void)parameter; GString *comment_text; - comment_text = g_string_new("gds-render is a free tool for rendering GDS2 layout files into vector graphics."); - g_string_append_printf(comment_text, "\n\nFull git commit: %s", _app_git_commit); + comment_text = g_string_new(_("gds-render is a free tool for rendering GDS2 layout files into vector graphics.")); + g_string_append_printf(comment_text, _("\n\nFull git commit: %s"), _app_git_commit); builder = gtk_builder_new_from_resource("/gui/about.glade"); dialog = GTK_DIALOG(gtk_builder_get_object(builder, "about-dialog")); @@ -111,7 +115,7 @@ static void app_about(GSimpleAction *action, GVariant *parameter, gpointer user_ /* Pixbuf is now owned by about dialog. Unref */ g_object_unref(logo_buf); } else if (error) { - fprintf(stderr, "Logo could not be displayed: %s\n", error->message); + fprintf(stderr, _("Logo could not be displayed: %s\n"), error->message); g_error_free(error); } @@ -193,6 +197,10 @@ static int start_gui(int argc, char **argv) GMenu *m_quit; GMenu *m_about; + bindtextdomain(GETTEXT_PACKAGE, LOCALEDATADIR "/locale"); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + textdomain(GETTEXT_PACKAGE); + /* * Generate version dependent application id * This allows running the application in different versions at the same time. @@ -208,7 +216,7 @@ static int start_gui(int argc, char **argv) if (g_application_get_is_remote(G_APPLICATION(gapp)) == TRUE) { g_application_activate(G_APPLICATION(gapp)); - printf("There is already an open instance. Will open second window in that instance.\n"); + printf(_("There is already an open instance. Will open second window in that instance.\n")); return 0; }