From 46083b1e7deaf5a323a86f94bf64924f63b59d9b Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sun, 19 May 2013 02:46:05 +0200 Subject: Internationalisation --- src/sdtui.c | 33 +++++++++++++-------------------- src/stardict.c | 30 ++++++++++++++++-------------- 2 files changed, 29 insertions(+), 34 deletions(-) (limited to 'src') 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 #include #include +#include #include #include @@ -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 #include +#include #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; } -- cgit v1.2.3-70-g09d2