aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2013-05-19 02:46:05 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2013-05-19 05:04:37 +0200
commit46083b1e7deaf5a323a86f94bf64924f63b59d9b (patch)
tree049184049e4a9e7ce6b71f1169eef35fca74b591
parentc430b6d7f89deaee45eaee350ef88a440b34cb29 (diff)
downloadtdv-46083b1e7deaf5a323a86f94bf64924f63b59d9b.tar.gz
tdv-46083b1e7deaf5a323a86f94bf64924f63b59d9b.tar.xz
tdv-46083b1e7deaf5a323a86f94bf64924f63b59d9b.zip
Internationalisation
-rw-r--r--CMakeLists.txt7
-rw-r--r--config.h.in3
-rwxr-xr-xpo/make-template.sh47
-rw-r--r--po/sdtui.pot110
-rw-r--r--src/sdtui.c33
-rw-r--r--src/stardict.c30
6 files changed, 196 insertions, 34 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fe93d77..e83ddc1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,6 +23,13 @@ pkg_check_modules (dependencies REQUIRED ncursesw glib-2.0 gio-2.0 pango)
include_directories (${dependencies_INCLUDE_DIRS})
+# Localization
+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})
+
# Project source files
set (project_common_sources
src/generator.c
diff --git a/config.h.in b/config.h.in
index 79bf191..adc32d8 100644
--- a/config.h.in
+++ b/config.h.in
@@ -5,5 +5,8 @@
#define PROJECT_VERSION "${project_VERSION}"
#define PROJECT_URL "${project_URL}"
+#define GETTEXT_PACKAGE PROJECT_NAME
+#define GETTEXT_DIRNAME "${CMAKE_INSTALL_PREFIX}/share/locale"
+
#endif /* ! CONFIG_H */
diff --git a/po/make-template.sh b/po/make-template.sh
new file mode 100755
index 0000000..d34c8d0
--- /dev/null
+++ b/po/make-template.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# This shell script generates the translation template.
+#
+# The reason for this not being inside CMakeLists.txt
+# is that the translator should not need to run the whole
+# configuration process just to get this single stupid file.
+
+# Get the directory this script resides in so that the user
+# doesn't have to run the script from there
+DIR=$(dirname $0)
+
+# Collect source files
+SOURCES=$(echo $DIR/../src/*.c)
+
+# Get the package name from CMakeLists.txt
+PACKAGE=$(sed -n '/^[ \t]*project[ \t]*([ \t]*\([^ \t)]\{1,\}\).*).*/{s//\1/p;q}' \
+ $DIR/../CMakeLists.txt)
+
+# Get the package version from CMakeLists.txt
+EXP_BEG='/^[ \t]*set[ \t]*([ \t]*project_VERSION_'
+EXP_END='[ \t]\{1,\}"\{0,1\}\([^)"]\{1,\}\)"\{0,1\}).*/{s//\1/p;q}'
+
+MAJOR=$(sed -n "${EXP_BEG}MAJOR${EXP_END}" $DIR/../CMakeLists.txt)
+MINOR=$(sed -n "${EXP_BEG}MINOR${EXP_END}" $DIR/../CMakeLists.txt)
+PATCH=$(sed -n "${EXP_BEG}PATCH${EXP_END}" $DIR/../CMakeLists.txt)
+
+if [ "$MAJOR" != "" ]; then
+ VERSION=$MAJOR
+ if [ "$MINOR" != "" ]; then
+ VERSION=$VERSION.$MINOR
+ if [ "$PATCH" != "" ]; then
+ VERSION=$VERSION.$PATCH
+ fi
+ fi
+fi
+
+if [ -z "$PACKAGE" -o -z "$VERSION" ]; then
+ echo "Failed to get information from CMakeLists.txt"
+ exit 1
+fi
+
+# Finally make the template
+xgettext -LC -k_ -kN_ $SOURCES -o "$DIR/$PACKAGE.pot" \
+ --package-name="$PACKAGE" --package-version="$VERSION" \
+ --copyright-holder="Přemysl Janouch" \
+ --msgid-bugs-address="https://github.com/pjanouch/$PACKAGE/issues"
+
diff --git a/po/sdtui.pot b/po/sdtui.pot
new file mode 100644
index 0000000..7e71091
--- /dev/null
+++ b/po/sdtui.pot
@@ -0,0 +1,110 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) 2013 Přemysl Janouch
+# This file is distributed under the same license as the sdtui package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: sdtui 0.1.0\n"
+"Report-Msgid-Bugs-To: https://github.com/pjanouch/sdtui/issues\n"
+"POT-Creation-Date: 2013-05-19 04:58+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: ../src/sdtui.c:230
+msgid "error in entry"
+msgstr ""
+
+#: ../src/sdtui.c:249
+msgid "no usable field found"
+msgstr ""
+
+#: ../src/sdtui.c:295
+msgid "Error loading dictionary"
+msgstr ""
+
+#: ../src/sdtui.c:308
+msgid "Search"
+msgstr ""
+
+#: ../src/sdtui.c:440
+msgid "Terminal UI for StarDict dictionaries"
+msgstr ""
+
+#: ../src/sdtui.c:443
+msgid "Type to search"
+msgstr ""
+
+#: ../src/sdtui.c:1054
+msgid "Output version information and exit"
+msgstr ""
+
+#: ../src/sdtui.c:1067
+msgid "dictionary.ifo - StarDict terminal UI"
+msgstr ""
+
+#: ../src/sdtui.c:1072
+msgid "Error"
+msgstr ""
+
+#: ../src/sdtui.c:1072
+msgid "option parsing failed"
+msgstr ""
+
+#: ../src/stardict.c:136
+msgid "invalid header format"
+msgstr ""
+
+#: ../src/stardict.c:268
+msgid "version not specified"
+msgstr ""
+
+#: ../src/stardict.c:279
+msgid "invalid version"
+msgstr ""
+
+#: ../src/stardict.c:294
+msgid "unknown key, ignoring"
+msgstr ""
+
+#: ../src/stardict.c:311
+msgid "invalid integer"
+msgstr ""
+
+#: ../src/stardict.c:321
+msgid "option format error"
+msgstr ""
+
+#: ../src/stardict.c:331
+msgid "no book name specified"
+msgstr ""
+
+#: ../src/stardict.c:337
+msgid "word count not specified"
+msgstr ""
+
+#: ../src/stardict.c:343
+msgid "index file size not specified"
+msgstr ""
+
+#: ../src/stardict.c:352
+msgid "invalid index offset bits"
+msgstr ""
+
+#: ../src/stardict.c:679
+msgid "cannot find .idx file"
+msgstr ""
+
+#: ../src/stardict.c:702
+msgid "cannot find .dict file"
+msgstr ""
+
+#: ../src/stardict.c:861 ../src/stardict.c:886
+msgid "invalid data entry"
+msgstr ""
diff --git a/src/sdtui.c b/src/sdtui.c
index 9ac7e71..2bf08e6 100644
--- a/src/sdtui.c
+++ b/src/sdtui.c
@@ -31,6 +31,7 @@
#include <gio/gio.h>
#include <pango/pango.h>
#include <ncurses.h>
+#include <glib/gi18n.h>
#include <unistd.h>
#include <poll.h>
@@ -75,8 +76,6 @@ typedef enum {
KEY_ALT_RIGHT //!< Alt + Right arrow
} ExtraKeyCode; //!< Translated key codes above KEY_MAX
-#define _(x) x /**< Fake gettext, for now. */
-
// --- Utilities ---------------------------------------------------------------
static int
@@ -293,7 +292,7 @@ app_init (Application *self, const gchar *filename)
self->dict = stardict_dict_new (filename, &error);
if (!self->dict)
{
- g_printerr ("Error loading dictionary: %s\n", error->message);
+ g_printerr ("%s: %s\n", _("Error loading dictionary"), error->message);
exit (EXIT_FAILURE);
}
@@ -306,11 +305,7 @@ app_init (Application *self, const gchar *filename)
self->entries = g_ptr_array_new_with_free_func
((GDestroyNotify) view_entry_free);
- gchar *search_label = g_strdup_printf ("%s: ", _("Search"));
- self->search_label = g_locale_to_utf8 (search_label, -1, NULL, NULL, NULL);
- g_free (search_label);
-
- g_assert (self->search_label != NULL);
+ self->search_label = g_strdup_printf ("%s: ", _("Search"));
self->input = g_array_new (TRUE, FALSE, sizeof (gunichar));
self->input_pos = 0;
@@ -439,23 +434,16 @@ app_show_message (Application *self, const gchar *lines[], gsize len)
static void
app_show_help (Application *self)
{
- gchar *description = g_locale_to_utf8
- (_("Terminal UI for StarDict dictionaries"), -1, NULL, NULL, NULL);
- gchar *type_to_search = g_locale_to_utf8
- (_("Type to search"), -1, NULL, NULL, NULL);
-
const gchar *lines[] =
{
PROJECT_NAME " " PROJECT_VERSION,
- description,
+ _("Terminal UI for StarDict dictionaries"),
"Copyright (c) 2013, Přemysl Janouch",
"",
- type_to_search
+ _("Type to search")
};
app_show_message (self, lines, G_N_ELEMENTS (lines));
- g_free (description);
- g_free (type_to_search);
}
/** Redraw the dictionary view. */
@@ -1063,17 +1051,22 @@ G_GNUC_END_IGNORE_DEPRECATIONS
{
{ "version", 0, G_OPTION_FLAG_IN_MAIN,
G_OPTION_ARG_NONE, &show_version,
- "Output version information and exit", NULL },
+ N_("Output version information and exit"), NULL },
{ NULL }
};
if (!setlocale (LC_ALL, ""))
abort ();
+ bindtextdomain (GETTEXT_PACKAGE, GETTEXT_DIRNAME);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
GError *error = NULL;
GOptionContext *ctx = g_option_context_new
- ("dictionary.ifo - StarDict terminal UI");
- g_option_context_add_main_entries (ctx, entries, NULL);
+ (N_("dictionary.ifo - StarDict terminal UI"));
+ g_option_context_add_main_entries (ctx, entries, GETTEXT_PACKAGE);
+ g_option_context_set_translation_domain (ctx, GETTEXT_PACKAGE);
if (!g_option_context_parse (ctx, &argc, &argv, &error))
{
g_printerr ("%s: %s: %s\n", _("Error"), _("option parsing failed"),
diff --git a/src/stardict.c b/src/stardict.c
index 5361c5e..4e3f5bd 100644
--- a/src/stardict.c
+++ b/src/stardict.c
@@ -25,6 +25,7 @@
#include <glib.h>
#include <gio/gio.h>
+#include <glib/gi18n.h>
#include "stardict.h"
#include "stardict-private.h"
@@ -132,7 +133,7 @@ ifo_reader_init (IfoReader *ir, const gchar *path, GError **error)
|| strncmp (contents, first_line, sizeof first_line - 1))
{
g_set_error (error, STARDICT_ERROR, STARDICT_ERROR_INVALID_DATA,
- "%s: invalid header format", path);
+ "%s: %s", path, _("invalid header format"));
return FALSE;
}
@@ -264,7 +265,7 @@ load_ifo (StardictInfo *sti, const gchar *path, GError **error)
if (ifo_reader_read (&ir) != 1 || strcmp (ir.key, "version"))
{
g_set_error (error, STARDICT_ERROR, STARDICT_ERROR_INVALID_DATA,
- "%s: version not specified", path);
+ "%s: %s", path, _("version not specified"));
goto error;
}
@@ -275,7 +276,7 @@ load_ifo (StardictInfo *sti, const gchar *path, GError **error)
else
{
g_set_error (error, STARDICT_ERROR, STARDICT_ERROR_INVALID_DATA,
- "%s: invalid version: %s", path, ir.value);
+ "%s: %s: %s", path, _("invalid version"), ir.value);
goto error;
}
@@ -290,7 +291,7 @@ load_ifo (StardictInfo *sti, const gchar *path, GError **error)
if (i == _stardict_ifo_keys_length)
{
g_set_error (error, STARDICT_ERROR, STARDICT_ERROR_INVALID_DATA,
- "%s: unknown key, ignoring: %s", path, ir.key);
+ "%s: %s: %s", path, _("unknown key, ignoring"), ir.key);
continue;
}
@@ -307,7 +308,7 @@ load_ifo (StardictInfo *sti, const gchar *path, GError **error)
if (*end)
{
g_set_error (error, STARDICT_ERROR, STARDICT_ERROR_INVALID_DATA,
- "%s: invalid integer", path);
+ "%s: %s", path, _("invalid integer"));
goto error;
}
@@ -317,7 +318,7 @@ load_ifo (StardictInfo *sti, const gchar *path, GError **error)
if (ret == -1)
{
g_set_error (error, STARDICT_ERROR, STARDICT_ERROR_INVALID_DATA,
- "%s: option format error", path);
+ "%s: %s", path, _("option format error"));
goto error;
}
@@ -327,19 +328,19 @@ load_ifo (StardictInfo *sti, const gchar *path, GError **error)
if (!sti->book_name || !*sti->book_name)
{
g_set_error (error, STARDICT_ERROR, STARDICT_ERROR_INVALID_DATA,
- "%s: no book name specified\n", path);
+ "%s: %s", path, _("no book name specified"));
ret_val = FALSE;
}
if (!sti->word_count)
{
g_set_error (error, STARDICT_ERROR, STARDICT_ERROR_INVALID_DATA,
- "%s: word count not specified\n", path);
+ "%s: %s", path, _("word count not specified"));
ret_val = FALSE;
}
if (!sti->idx_filesize)
{
g_set_error (error, STARDICT_ERROR, STARDICT_ERROR_INVALID_DATA,
- "%s: .idx file size not specified\n", path);
+ "%s: %s", path, _("index file size not specified"));
ret_val = FALSE;
}
@@ -348,7 +349,8 @@ load_ifo (StardictInfo *sti, const gchar *path, GError **error)
else if (sti->idx_offset_bits != 32 && sti->idx_offset_bits != 64)
{
g_set_error (error, STARDICT_ERROR, STARDICT_ERROR_INVALID_DATA,
- "%s: wrong index offset bits: %lu\n", path, sti->idx_offset_bits);
+ "%s: %s: %lu", path, _("invalid index offset bits"),
+ sti->idx_offset_bits);
ret_val = FALSE;
}
@@ -674,7 +676,7 @@ stardict_dict_new_from_info (StardictInfo *sdi, GError **error)
else
{
g_set_error (error, STARDICT_ERROR, STARDICT_ERROR_FILE_NOT_FOUND,
- "%s: cannot find index file", sdi->path);
+ "%s: %s", sdi->path, _("cannot find .idx file"));
}
}
g_free (base_idx);
@@ -697,7 +699,7 @@ stardict_dict_new_from_info (StardictInfo *sdi, GError **error)
else
{
g_set_error (error, STARDICT_ERROR, STARDICT_ERROR_FILE_NOT_FOUND,
- "%s: cannot find dict file", sdi->path);
+ "%s: %s", sdi->path, _("cannot find .dict file"));
}
}
g_free (base_dict);
@@ -856,7 +858,7 @@ read_entries (const gchar *entry, gsize entry_size, GError **error)
error:
g_set_error (error, STARDICT_ERROR, STARDICT_ERROR_INVALID_DATA,
- "invalid data entry");
+ _("invalid data entry"));
g_list_free_full (result, (GDestroyNotify) stardict_entry_field_free);
return NULL;
}
@@ -881,7 +883,7 @@ read_entries_sts (const gchar *entry, gsize entry_size,
error:
g_set_error (error, STARDICT_ERROR, STARDICT_ERROR_INVALID_DATA,
- "invalid data entry");
+ _("invalid data entry"));
g_list_free_full (result, (GDestroyNotify) stardict_entry_field_free);
return NULL;
}