Change the way translations are done.

* Require gettext-tools to build.
* Depend on libintl on Win32.
This commit is contained in:
Přemysl Eric Janouch 2011-02-12 02:07:39 +01:00
parent 68e6e4a7e8
commit 9a217e97c8
8 changed files with 120 additions and 73 deletions

View File

@ -94,14 +94,16 @@ find_package (Lua51 REQUIRED)
find_package (JsonGlib REQUIRED) find_package (JsonGlib REQUIRED)
# Localization # Localization
find_package (Gettext) find_package (Gettext REQUIRED)
if (GETTEXT_FOUND) file (GLOB project_PO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/po/*.po)
set (HAVE_GETTEXT true) GETTEXT_CREATE_TRANSLATIONS (
file (GLOB project_TRANSLATIONS ${CMAKE_CURRENT_SOURCE_DIR}/po/*.po) ${CMAKE_CURRENT_SOURCE_DIR}/po/${CMAKE_PROJECT_NAME}.pot
GETTEXT_CREATE_TRANSLATIONS ( ALL ${project_PO_FILES})
${CMAKE_CURRENT_SOURCE_DIR}/po/${CMAKE_PROJECT_NAME}.pot
ALL ${project_TRANSLATIONS}) foreach (file ${project_PO_FILES})
endif (GETTEXT_FOUND) get_filename_component (translation "${file}" NAME_WE)
list (APPEND project_TRANSLATIONS "${translation}")
endforeach (file)
# Documentation # Documentation
# TODO: Add pregenerated docs to the tree # TODO: Add pregenerated docs to the tree
@ -218,6 +220,11 @@ include_directories (${GTK2_INCLUDE_DIRS}
set (logdiag_LIBS ${GTK2_LIBRARIES} set (logdiag_LIBS ${GTK2_LIBRARIES}
${JSON_GLIB_LIBRARIES} ${LUA_LIBRARIES}) ${JSON_GLIB_LIBRARIES} ${LUA_LIBRARIES})
if (WIN32)
find_package (LibIntl REQUIRED)
list (APPEND logdiag_LIBS ${LIBINTL_LIBRARIES})
endif (WIN32)
# Build the library # Build the library
add_library (liblogdiag STATIC ${liblogdiag_SOURCES} ${liblogdiag_HEADERS}) add_library (liblogdiag STATIC ${liblogdiag_SOURCES} ${liblogdiag_HEADERS})
set_target_properties (liblogdiag PROPERTIES OUTPUT_NAME logdiag) set_target_properties (liblogdiag PROPERTIES OUTPUT_NAME logdiag)
@ -258,7 +265,8 @@ if (WIN32)
install (DIRECTORY install (DIRECTORY
${WIN32_DEPENDS_PATH}/bin/ ${WIN32_DEPENDS_PATH}/bin/
DESTINATION . DESTINATION .
FILES_MATCHING PATTERN "*.dll") FILES_MATCHING PATTERN "*.dll"
PATTERN "libgettext*" EXCLUDE)
install (DIRECTORY install (DIRECTORY
${WIN32_DEPENDS_PATH}/etc/ ${WIN32_DEPENDS_PATH}/etc/
DESTINATION etc) DESTINATION etc)
@ -268,9 +276,20 @@ if (WIN32)
${WIN32_DEPENDS_PATH}/lib/gdk-pixbuf-2.0 ${WIN32_DEPENDS_PATH}/lib/gdk-pixbuf-2.0
DESTINATION lib) DESTINATION lib)
install (DIRECTORY install (DIRECTORY
${WIN32_DEPENDS_PATH}/share/locale
${WIN32_DEPENDS_PATH}/share/themes ${WIN32_DEPENDS_PATH}/share/themes
DESTINATION share) 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) else (WIN32)
install (TARGETS logdiag DESTINATION bin) install (TARGETS logdiag DESTINATION bin)
install (FILES share/logdiag.desktop DESTINATION share/applications) install (FILES share/logdiag.desktop DESTINATION share/applications)

View File

@ -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}/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}/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_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 set (pkg_gtk_md5
"a545c0ca1e6a312701d42a18e49572af" "a545c0ca1e6a312701d42a18e49572af"
"2c712a8d7a652363241c0967098515db" "2c712a8d7a652363241c0967098515db"
@ -52,7 +53,8 @@ set (pkg_gtk_md5
"bf4e34f1f175b88430159d33e01d0c49" "bf4e34f1f175b88430159d33e01d0c49"
"2d90c71404be0de4e5f3259f63a3e278" "2d90c71404be0de4e5f3259f63a3e278"
"bd6b3d8c35e06a00937db65887c6e287" "bd6b3d8c35e06a00937db65887c6e287"
"b6f59b70eef0992df37f8db891d4b283") "b6f59b70eef0992df37f8db891d4b283"
"09baff956ebd1c391c7f71e9bd768edd")
set (pkg_opensuse_root "http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_Factory/noarch") set (pkg_opensuse_root "http://download.opensuse.org/repositories/windows:/mingw:/win32/openSUSE_Factory/noarch")
set (pkg_opensuse_urls set (pkg_opensuse_urls

View File

@ -14,7 +14,7 @@
#============================================================================= #=============================================================================
# Copyright 2007-2009 Kitware, Inc. # 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 # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met: # modification, are permitted provided that the following conditions are met:
@ -41,7 +41,6 @@
#============================================================================= #=============================================================================
find_program (GETTEXT_MSGMERGE_EXECUTABLE msgmerge) find_program (GETTEXT_MSGMERGE_EXECUTABLE msgmerge)
find_program (GETTEXT_MSGFMT_EXECUTABLE msgfmt) find_program (GETTEXT_MSGFMT_EXECUTABLE msgfmt)
macro (GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg) macro (GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg)
@ -93,13 +92,8 @@ macro (GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg)
DEPENDS ${_gmoFiles}) DEPENDS ${_gmoFiles})
endmacro (GETTEXT_CREATE_TRANSLATIONS) endmacro (GETTEXT_CREATE_TRANSLATIONS)
if (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE) include (FindPackageHandleStandardArgs)
set (GETTEXT_FOUND TRUE) FIND_PACKAGE_HANDLE_STANDARD_ARGS (Gettext DEFAULT_MSG
else (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE) GETTEXT_MSGMERGE_EXECUTABLE 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)

38
cmake/FindLibIntl.cmake Normal file
View File

@ -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)

View File

@ -25,22 +25,15 @@
#cmakedefine HAVE_SANE___RESTRICT #cmakedefine HAVE_SANE___RESTRICT
#cmakedefine HAVE_RESTRICT #cmakedefine HAVE_RESTRICT
#cmakedefine HAVE_GETTEXT
#include <glib/gi18n.h>
#define Q_(s) (s) #define GETTEXT_DOMAIN "${PROJECT_NAME}"
#ifdef HAVE_GETTEXT #ifdef _WIN32
#include <locale.h> #define GETTEXT_DIRNAME "share/locale"
#include <libintl.h> #else
#define _(s) gettext(s)
#define N_(s1, s2, n) ngettext(s1, s2, n)
#define GETTEXT_DOMAIN "${PROJECT_NAME}"
#define GETTEXT_DIRNAME "${CMAKE_INSTALL_PREFIX}/share/locale" #define GETTEXT_DIRNAME "${CMAKE_INSTALL_PREFIX}/share/locale"
#else /* ! HAVE_GETTEXT */ #endif
#define _(s) (s)
#define N_(s1, s2, n) ((n) == 1 ? (s1) : (s2))
#endif /* ! HAVE_GETTEXT */
#ifndef HAVE_SANE___RESTRICT #ifndef HAVE_SANE___RESTRICT

View File

@ -30,7 +30,7 @@ if [ "$MAJOR" != "" ]; then
fi fi
# Finally make the template # 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" \ --package-name="$PACKAGE" --package-version="$VERSION" \
--copyright-holder="Přemysl Janouch" --copyright-holder="Přemysl Janouch"

View File

@ -110,61 +110,61 @@ static void on_action_normal_size (GtkAction *action, LdWindowMain *self);
/* Actions for menus, toolbars, accelerators. */ /* Actions for menus, toolbars, accelerators. */
static GtkActionEntry wm_action_entries[] = static GtkActionEntry wm_action_entries[] =
{ {
{"FileMenu", NULL, Q_("_File"), NULL, NULL, NULL}, {"FileMenu", NULL, N_("_File"), NULL, NULL, NULL},
{"New", GTK_STOCK_NEW, Q_("_New"), "<Ctrl>N", {"New", GTK_STOCK_NEW, N_("_New"), "<Ctrl>N",
Q_("Create a new diagram"), N_("Create a new diagram"),
G_CALLBACK (on_action_new)}, G_CALLBACK (on_action_new)},
{"Open", GTK_STOCK_OPEN, Q_("_Open..."), "<Ctrl>O", {"Open", GTK_STOCK_OPEN, N_("_Open..."), "<Ctrl>O",
Q_("Open a diagram"), N_("Open a diagram"),
G_CALLBACK (on_action_open)}, G_CALLBACK (on_action_open)},
{"Save", GTK_STOCK_SAVE, Q_("_Save"), "<Ctrl>S", {"Save", GTK_STOCK_SAVE, N_("_Save"), "<Ctrl>S",
Q_("Save the current diagram"), N_("Save the current diagram"),
G_CALLBACK (on_action_save)}, G_CALLBACK (on_action_save)},
{"SaveAs", GTK_STOCK_SAVE_AS, Q_("Save _As..."), "<Shift><Ctrl>S", {"SaveAs", GTK_STOCK_SAVE_AS, N_("Save _As..."), "<Shift><Ctrl>S",
Q_("Save the current diagram with another name"), N_("Save the current diagram with another name"),
G_CALLBACK (on_action_save_as)}, G_CALLBACK (on_action_save_as)},
/* /*
* {"Export", NULL, Q_("_Export"), NULL, * {"Export", NULL, N_("_Export"), NULL,
* Q_("Export the diagram"), * N_("Export the diagram"),
* NULL}, * NULL},
*/ */
{"Quit", GTK_STOCK_QUIT, Q_("_Quit"), "<Ctrl>Q", {"Quit", GTK_STOCK_QUIT, N_("_Quit"), "<Ctrl>Q",
Q_("Quit the application"), N_("Quit the application"),
G_CALLBACK (on_action_quit)}, G_CALLBACK (on_action_quit)},
{"EditMenu", NULL, Q_("_Edit"), NULL, NULL, NULL}, {"EditMenu", NULL, N_("_Edit"), NULL, NULL, NULL},
{"Undo", GTK_STOCK_UNDO, Q_("_Undo"), "<Ctrl>Z", {"Undo", GTK_STOCK_UNDO, N_("_Undo"), "<Ctrl>Z",
Q_("Undo the last action"), N_("Undo the last action"),
G_CALLBACK (on_action_undo)}, G_CALLBACK (on_action_undo)},
{"Redo", GTK_STOCK_REDO, Q_("_Redo"), "<Shift><Ctrl>Z", {"Redo", GTK_STOCK_REDO, N_("_Redo"), "<Shift><Ctrl>Z",
Q_("Redo the last undone action"), N_("Redo the last undone action"),
G_CALLBACK (on_action_redo)}, G_CALLBACK (on_action_redo)},
/* /*
* {"Cut", GTK_STOCK_CUT, Q_("Cu_t"), "<Ctrl>X", NULL, NULL}, * {"Cut", GTK_STOCK_CUT, N_("Cu_t"), "<Ctrl>X", NULL, NULL},
* {"Copy", GTK_STOCK_COPY, Q_("_Copy"), "<Ctrl>C", NULL, NULL}, * {"Copy", GTK_STOCK_COPY, N_("_Copy"), "<Ctrl>C", NULL, NULL},
* {"Paste", GTK_STOCK_PASTE, Q_("_Paste"), "<Ctrl>V", NULL, NULL}, * {"Paste", GTK_STOCK_PASTE, N_("_Paste"), "<Ctrl>V", NULL, NULL},
*/ */
{"Delete", GTK_STOCK_DELETE, Q_("_Delete"), "Delete", {"Delete", GTK_STOCK_DELETE, N_("_Delete"), "Delete",
Q_("Delete the contents of the selection"), N_("Delete the contents of the selection"),
G_CALLBACK (on_action_delete)}, G_CALLBACK (on_action_delete)},
{"SelectAll", GTK_STOCK_SELECT_ALL, Q_("Select _All"), "<Ctrl>A", {"SelectAll", GTK_STOCK_SELECT_ALL, N_("Select _All"), "<Ctrl>A",
Q_("Select all objects in the diagram"), N_("Select all objects in the diagram"),
G_CALLBACK (on_action_select_all)}, G_CALLBACK (on_action_select_all)},
{"ViewMenu", NULL, Q_("_View"), NULL, NULL, NULL}, {"ViewMenu", NULL, N_("_View"), NULL, NULL, NULL},
{"ZoomIn", GTK_STOCK_ZOOM_IN, Q_("_Zoom In"), "<Ctrl>plus", {"ZoomIn", GTK_STOCK_ZOOM_IN, N_("_Zoom In"), "<Ctrl>plus",
Q_("Zoom into the diagram"), N_("Zoom into the diagram"),
G_CALLBACK (on_action_zoom_in)}, G_CALLBACK (on_action_zoom_in)},
{"ZoomOut", GTK_STOCK_ZOOM_OUT, Q_("Zoom _Out"), "<Ctrl>minus", {"ZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<Ctrl>minus",
Q_("Zoom out of the diagram"), N_("Zoom out of the diagram"),
G_CALLBACK (on_action_zoom_out)}, G_CALLBACK (on_action_zoom_out)},
{"NormalSize", GTK_STOCK_ZOOM_100, Q_("_Normal Size"), "<Ctrl>0", {"NormalSize", GTK_STOCK_ZOOM_100, N_("_Normal Size"), "<Ctrl>0",
Q_("Reset zoom level back to the default"), N_("Reset zoom level back to the default"),
G_CALLBACK (on_action_normal_size)}, G_CALLBACK (on_action_normal_size)},
{"HelpMenu", NULL, Q_("_Help"), NULL, NULL, NULL}, {"HelpMenu", NULL, N_("_Help"), NULL, NULL, NULL},
{"About", GTK_STOCK_ABOUT, Q_("_About"), NULL, {"About", GTK_STOCK_ABOUT, N_("_About"), NULL,
Q_("Show a dialog about this application"), N_("Show a dialog about this application"),
G_CALLBACK (on_action_about)} G_CALLBACK (on_action_about)}
}; };
@ -216,6 +216,8 @@ ld_window_main_init (LdWindowMain *self)
G_CALLBACK (on_ui_proxy_disconnected), self); G_CALLBACK (on_ui_proxy_disconnected), self);
priv->action_group = gtk_action_group_new ("MainActions"); 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, gtk_action_group_add_actions (priv->action_group, wm_action_entries,
G_N_ELEMENTS (wm_action_entries), self); G_N_ELEMENTS (wm_action_entries), self);
gtk_ui_manager_insert_action_group (priv->ui_manager, gtk_ui_manager_insert_action_group (priv->ui_manager,

View File

@ -9,6 +9,7 @@
*/ */
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <locale.h>
#include "config.h" #include "config.h"
@ -20,13 +21,11 @@ main (int argc, char *argv[])
{ {
GtkWidget *wnd; GtkWidget *wnd;
#ifdef HAVE_GETTEXT
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_DOMAIN, GETTEXT_DIRNAME); bindtextdomain (GETTEXT_DOMAIN, GETTEXT_DIRNAME);
bind_textdomain_codeset (GETTEXT_DOMAIN, "UTF-8"); bind_textdomain_codeset (GETTEXT_DOMAIN, "UTF-8");
textdomain (GETTEXT_DOMAIN); textdomain (GETTEXT_DOMAIN);
#endif
/* For custom command line arguments, see: /* For custom command line arguments, see:
* http://git.gnome.org/browse/glade3/tree/src/main.c * http://git.gnome.org/browse/glade3/tree/src/main.c