diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2011-02-12 02:07:39 +0100 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2011-02-12 18:40:16 +0100 |
commit | 9a217e97c8852bda5a7fdf1cad41da769f013fef (patch) | |
tree | f6dd0ae78fccb0333ebef238dfea04311d487266 | |
parent | 68e6e4a7e8e5a217f6288e23ec50290835988f37 (diff) | |
download | logdiag-9a217e97c8852bda5a7fdf1cad41da769f013fef.tar.gz logdiag-9a217e97c8852bda5a7fdf1cad41da769f013fef.tar.xz logdiag-9a217e97c8852bda5a7fdf1cad41da769f013fef.zip |
Change the way translations are done.
* Require gettext-tools to build.
* Depend on libintl on Win32.
-rw-r--r-- | CMakeLists.txt | 39 | ||||
-rw-r--r-- | Win32Depends.cmake | 6 | ||||
-rw-r--r-- | cmake/FindGettext.cmake | 14 | ||||
-rw-r--r-- | cmake/FindLibIntl.cmake | 38 | ||||
-rw-r--r-- | config.h.in | 19 | ||||
-rwxr-xr-x | po/make-template.sh | 2 | ||||
-rw-r--r-- | src/ld-window-main.c | 72 | ||||
-rw-r--r-- | src/logdiag.c | 3 |
8 files changed, 120 insertions, 73 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index cf9bfc1..5ed6cee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,14 +94,16 @@ find_package (Lua51 REQUIRED) find_package (JsonGlib REQUIRED) # Localization -find_package (Gettext) -if (GETTEXT_FOUND) - set (HAVE_GETTEXT true) - file (GLOB project_TRANSLATIONS ${CMAKE_CURRENT_SOURCE_DIR}/po/*.po) - GETTEXT_CREATE_TRANSLATIONS ( - ${CMAKE_CURRENT_SOURCE_DIR}/po/${CMAKE_PROJECT_NAME}.pot - ALL ${project_TRANSLATIONS}) -endif (GETTEXT_FOUND) +find_package (Gettext REQUIRED) +file (GLOB project_PO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/po/*.po) +GETTEXT_CREATE_TRANSLATIONS ( + ${CMAKE_CURRENT_SOURCE_DIR}/po/${CMAKE_PROJECT_NAME}.pot + ALL ${project_PO_FILES}) + +foreach (file ${project_PO_FILES}) + get_filename_component (translation "${file}" NAME_WE) + list (APPEND project_TRANSLATIONS "${translation}") +endforeach (file) # Documentation # TODO: Add pregenerated docs to the tree @@ -218,6 +220,11 @@ include_directories (${GTK2_INCLUDE_DIRS} set (logdiag_LIBS ${GTK2_LIBRARIES} ${JSON_GLIB_LIBRARIES} ${LUA_LIBRARIES}) +if (WIN32) + find_package (LibIntl REQUIRED) + list (APPEND logdiag_LIBS ${LIBINTL_LIBRARIES}) +endif (WIN32) + # Build the library add_library (liblogdiag STATIC ${liblogdiag_SOURCES} ${liblogdiag_HEADERS}) set_target_properties (liblogdiag PROPERTIES OUTPUT_NAME logdiag) @@ -258,7 +265,8 @@ if (WIN32) install (DIRECTORY ${WIN32_DEPENDS_PATH}/bin/ DESTINATION . - FILES_MATCHING PATTERN "*.dll") + FILES_MATCHING PATTERN "*.dll" + PATTERN "libgettext*" EXCLUDE) install (DIRECTORY ${WIN32_DEPENDS_PATH}/etc/ DESTINATION etc) @@ -268,9 +276,20 @@ if (WIN32) ${WIN32_DEPENDS_PATH}/lib/gdk-pixbuf-2.0 DESTINATION lib) install (DIRECTORY - ${WIN32_DEPENDS_PATH}/share/locale ${WIN32_DEPENDS_PATH}/share/themes DESTINATION share) + + # Avoid partial translations + file (GLOB locales ${WIN32_DEPENDS_PATH}/share/locale/*) + foreach (locale ${locales}) + get_filename_component (translation ${locale} NAME) + list (FIND project_TRANSLATIONS ${translation} translation_found) + if (translation_found GREATER -1) + install (DIRECTORY + ${WIN32_DEPENDS_PATH}/share/locale/${translation} + DESTINATION share/locale) + endif (translation_found GREATER -1) + endforeach (locale) else (WIN32) install (TARGETS logdiag DESTINATION bin) install (FILES share/logdiag.desktop DESTINATION share/applications) diff --git a/Win32Depends.cmake b/Win32Depends.cmake index cab4ee5..7c1f38e 100644 --- a/Win32Depends.cmake +++ b/Win32Depends.cmake @@ -44,7 +44,8 @@ set (pkg_gtk_urls "${pkg_gtk_root}/librsvg/2.32/svg-gdk-pixbuf-loader_2.32.1-1_win32.zip" "${pkg_gtk_root}/libcroco/0.6/libcroco_0.6.2-1_win32.zip" "${pkg_gtk_root}/dependencies/libxml2_2.7.7-1_win32.zip" - "${pkg_gtk_root}/dependencies/libxml2-dev_2.7.7-1_win32.zip") + "${pkg_gtk_root}/dependencies/libxml2-dev_2.7.7-1_win32.zip" + "${pkg_gtk_root}/dependencies/gettext-tools-0.17.zip") set (pkg_gtk_md5 "a545c0ca1e6a312701d42a18e49572af" "2c712a8d7a652363241c0967098515db" @@ -52,7 +53,8 @@ set (pkg_gtk_md5 "bf4e34f1f175b88430159d33e01d0c49" "2d90c71404be0de4e5f3259f63a3e278" "bd6b3d8c35e06a00937db65887c6e287" - "b6f59b70eef0992df37f8db891d4b283") + "b6f59b70eef0992df37f8db891d4b283" + "09baff956ebd1c391c7f71e9bd768edd") set (pkg_opensuse_root "http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_Factory/noarch") set (pkg_opensuse_urls diff --git a/cmake/FindGettext.cmake b/cmake/FindGettext.cmake index 4f8e6fb..d2e3c95 100644 --- a/cmake/FindGettext.cmake +++ b/cmake/FindGettext.cmake @@ -14,7 +14,7 @@ #============================================================================= # Copyright 2007-2009 Kitware, Inc. -# Copyright 2010 Přemysl Janouch +# Copyright 2010-2011 Přemysl Janouch # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: @@ -41,7 +41,6 @@ #============================================================================= find_program (GETTEXT_MSGMERGE_EXECUTABLE msgmerge) - find_program (GETTEXT_MSGFMT_EXECUTABLE msgfmt) macro (GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg) @@ -93,13 +92,8 @@ macro (GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg) DEPENDS ${_gmoFiles}) endmacro (GETTEXT_CREATE_TRANSLATIONS) -if (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE) - set (GETTEXT_FOUND TRUE) -else (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE) - set (GETTEXT_FOUND FALSE) - if (GetText_REQUIRED) - message (FATAL_ERROR "GetText not found") - endif (GetText_REQUIRED) -endif (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE) +include (FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS (Gettext DEFAULT_MSG + GETTEXT_MSGMERGE_EXECUTABLE GETTEXT_MSGFMT_EXECUTABLE) diff --git a/cmake/FindLibIntl.cmake b/cmake/FindLibIntl.cmake new file mode 100644 index 0000000..49fee79 --- /dev/null +++ b/cmake/FindLibIntl.cmake @@ -0,0 +1,38 @@ +# - Find libintl +# This module looks for libintl. +# This module defines the following values: +# LIBINTL_FOUND +# LIBINTL_LIBRARIES + +#============================================================================= +# Copyright Přemysl Janouch 2011 +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +# OF SUCH DAMAGE. +#============================================================================= + +find_library (LIBINTL_LIBRARIES intl) + +include (FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS (LibIntl DEFAULT_MSG LIBINTL_LIBRARIES) + +mark_as_advanced (LIBINTL_LIBRARIES) + diff --git a/config.h.in b/config.h.in index 5ebdc87..0cc98c6 100644 --- a/config.h.in +++ b/config.h.in @@ -25,22 +25,15 @@ #cmakedefine HAVE_SANE___RESTRICT #cmakedefine HAVE_RESTRICT -#cmakedefine HAVE_GETTEXT +#include <glib/gi18n.h> -#define Q_(s) (s) -#ifdef HAVE_GETTEXT - #include <locale.h> - #include <libintl.h> - #define _(s) gettext(s) - #define N_(s1, s2, n) ngettext(s1, s2, n) - - #define GETTEXT_DOMAIN "${PROJECT_NAME}" +#define GETTEXT_DOMAIN "${PROJECT_NAME}" +#ifdef _WIN32 + #define GETTEXT_DIRNAME "share/locale" +#else #define GETTEXT_DIRNAME "${CMAKE_INSTALL_PREFIX}/share/locale" -#else /* ! HAVE_GETTEXT */ - #define _(s) (s) - #define N_(s1, s2, n) ((n) == 1 ? (s1) : (s2)) -#endif /* ! HAVE_GETTEXT */ +#endif #ifndef HAVE_SANE___RESTRICT diff --git a/po/make-template.sh b/po/make-template.sh index f76a620..272c583 100755 --- a/po/make-template.sh +++ b/po/make-template.sh @@ -30,7 +30,7 @@ if [ "$MAJOR" != "" ]; then fi # Finally make the template -xgettext -LC -k_ -kN_:1,2 -kG_ $SOURCES -o "$PACKAGE".pot \ +xgettext -LC -k_ -kN_ $SOURCES -o "$PACKAGE".pot \ --package-name="$PACKAGE" --package-version="$VERSION" \ --copyright-holder="Přemysl Janouch" diff --git a/src/ld-window-main.c b/src/ld-window-main.c index 0c671ed..463f2ef 100644 --- a/src/ld-window-main.c +++ b/src/ld-window-main.c @@ -110,61 +110,61 @@ static void on_action_normal_size (GtkAction *action, LdWindowMain *self); /* Actions for menus, toolbars, accelerators. */ static GtkActionEntry wm_action_entries[] = { - {"FileMenu", NULL, Q_("_File"), NULL, NULL, NULL}, - {"New", GTK_STOCK_NEW, Q_("_New"), "<Ctrl>N", - Q_("Create a new diagram"), + {"FileMenu", NULL, N_("_File"), NULL, NULL, NULL}, + {"New", GTK_STOCK_NEW, N_("_New"), "<Ctrl>N", + N_("Create a new diagram"), G_CALLBACK (on_action_new)}, - {"Open", GTK_STOCK_OPEN, Q_("_Open..."), "<Ctrl>O", - Q_("Open a diagram"), + {"Open", GTK_STOCK_OPEN, N_("_Open..."), "<Ctrl>O", + N_("Open a diagram"), G_CALLBACK (on_action_open)}, - {"Save", GTK_STOCK_SAVE, Q_("_Save"), "<Ctrl>S", - Q_("Save the current diagram"), + {"Save", GTK_STOCK_SAVE, N_("_Save"), "<Ctrl>S", + N_("Save the current diagram"), G_CALLBACK (on_action_save)}, - {"SaveAs", GTK_STOCK_SAVE_AS, Q_("Save _As..."), "<Shift><Ctrl>S", - Q_("Save the current diagram with another name"), + {"SaveAs", GTK_STOCK_SAVE_AS, N_("Save _As..."), "<Shift><Ctrl>S", + N_("Save the current diagram with another name"), G_CALLBACK (on_action_save_as)}, /* - * {"Export", NULL, Q_("_Export"), NULL, - * Q_("Export the diagram"), + * {"Export", NULL, N_("_Export"), NULL, + * N_("Export the diagram"), * NULL}, */ - {"Quit", GTK_STOCK_QUIT, Q_("_Quit"), "<Ctrl>Q", - Q_("Quit the application"), + {"Quit", GTK_STOCK_QUIT, N_("_Quit"), "<Ctrl>Q", + N_("Quit the application"), G_CALLBACK (on_action_quit)}, - {"EditMenu", NULL, Q_("_Edit"), NULL, NULL, NULL}, - {"Undo", GTK_STOCK_UNDO, Q_("_Undo"), "<Ctrl>Z", - Q_("Undo the last action"), + {"EditMenu", NULL, N_("_Edit"), NULL, NULL, NULL}, + {"Undo", GTK_STOCK_UNDO, N_("_Undo"), "<Ctrl>Z", + N_("Undo the last action"), G_CALLBACK (on_action_undo)}, - {"Redo", GTK_STOCK_REDO, Q_("_Redo"), "<Shift><Ctrl>Z", - Q_("Redo the last undone action"), + {"Redo", GTK_STOCK_REDO, N_("_Redo"), "<Shift><Ctrl>Z", + N_("Redo the last undone action"), G_CALLBACK (on_action_redo)}, /* - * {"Cut", GTK_STOCK_CUT, Q_("Cu_t"), "<Ctrl>X", NULL, NULL}, - * {"Copy", GTK_STOCK_COPY, Q_("_Copy"), "<Ctrl>C", NULL, NULL}, - * {"Paste", GTK_STOCK_PASTE, Q_("_Paste"), "<Ctrl>V", NULL, NULL}, + * {"Cut", GTK_STOCK_CUT, N_("Cu_t"), "<Ctrl>X", NULL, NULL}, + * {"Copy", GTK_STOCK_COPY, N_("_Copy"), "<Ctrl>C", NULL, NULL}, + * {"Paste", GTK_STOCK_PASTE, N_("_Paste"), "<Ctrl>V", NULL, NULL}, */ - {"Delete", GTK_STOCK_DELETE, Q_("_Delete"), "Delete", - Q_("Delete the contents of the selection"), + {"Delete", GTK_STOCK_DELETE, N_("_Delete"), "Delete", + N_("Delete the contents of the selection"), G_CALLBACK (on_action_delete)}, - {"SelectAll", GTK_STOCK_SELECT_ALL, Q_("Select _All"), "<Ctrl>A", - Q_("Select all objects in the diagram"), + {"SelectAll", GTK_STOCK_SELECT_ALL, N_("Select _All"), "<Ctrl>A", + N_("Select all objects in the diagram"), G_CALLBACK (on_action_select_all)}, - {"ViewMenu", NULL, Q_("_View"), NULL, NULL, NULL}, - {"ZoomIn", GTK_STOCK_ZOOM_IN, Q_("_Zoom In"), "<Ctrl>plus", - Q_("Zoom into the diagram"), + {"ViewMenu", NULL, N_("_View"), NULL, NULL, NULL}, + {"ZoomIn", GTK_STOCK_ZOOM_IN, N_("_Zoom In"), "<Ctrl>plus", + N_("Zoom into the diagram"), G_CALLBACK (on_action_zoom_in)}, - {"ZoomOut", GTK_STOCK_ZOOM_OUT, Q_("Zoom _Out"), "<Ctrl>minus", - Q_("Zoom out of the diagram"), + {"ZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<Ctrl>minus", + N_("Zoom out of the diagram"), G_CALLBACK (on_action_zoom_out)}, - {"NormalSize", GTK_STOCK_ZOOM_100, Q_("_Normal Size"), "<Ctrl>0", - Q_("Reset zoom level back to the default"), + {"NormalSize", GTK_STOCK_ZOOM_100, N_("_Normal Size"), "<Ctrl>0", + N_("Reset zoom level back to the default"), G_CALLBACK (on_action_normal_size)}, - {"HelpMenu", NULL, Q_("_Help"), NULL, NULL, NULL}, - {"About", GTK_STOCK_ABOUT, Q_("_About"), NULL, - Q_("Show a dialog about this application"), + {"HelpMenu", NULL, N_("_Help"), NULL, NULL, NULL}, + {"About", GTK_STOCK_ABOUT, N_("_About"), NULL, + N_("Show a dialog about this application"), G_CALLBACK (on_action_about)} }; @@ -216,6 +216,8 @@ ld_window_main_init (LdWindowMain *self) G_CALLBACK (on_ui_proxy_disconnected), self); priv->action_group = gtk_action_group_new ("MainActions"); + gtk_action_group_set_translation_domain + (priv->action_group, GETTEXT_DOMAIN); gtk_action_group_add_actions (priv->action_group, wm_action_entries, G_N_ELEMENTS (wm_action_entries), self); gtk_ui_manager_insert_action_group (priv->ui_manager, diff --git a/src/logdiag.c b/src/logdiag.c index 20783b1..8191d7f 100644 --- a/src/logdiag.c +++ b/src/logdiag.c @@ -9,6 +9,7 @@ */ #include <gtk/gtk.h> +#include <locale.h> #include "config.h" @@ -20,13 +21,11 @@ main (int argc, char *argv[]) { GtkWidget *wnd; -#ifdef HAVE_GETTEXT setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_DOMAIN, GETTEXT_DIRNAME); bind_textdomain_codeset (GETTEXT_DOMAIN, "UTF-8"); textdomain (GETTEXT_DOMAIN); -#endif /* For custom command line arguments, see: * http://git.gnome.org/browse/glade3/tree/src/main.c |