From 99974213058c2507b9c6ed8526e1bd518f36c921 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 25 Nov 2007 12:10:11 +0000 Subject: [PATCH] Switched completely to standard gettext. We used to use our own implementation of the gettext functions so that the user could switch langauges on the fly. However, that doesn't work with Glade and it wasn't very useful anyway, so it has all been removed. One visible change is that e.g. "LANG=fr rox -n" no longer works. You have to use the full string (e.g. "LANG=fr_FR.utf8 rox -n"). --- ROX-Filer/Options.xml | 33 ---------- ROX-Filer/src/Makefile.in | 4 +- ROX-Filer/src/config.h.in | 8 ++- ROX-Filer/src/i18n.c | 133 +++++++-------------------------------- ROX-Filer/src/po/make-mo | 14 +---- ROX-Filer/src/rox_gettext.c | 149 -------------------------------------------- ROX-Filer/src/rox_gettext.h | 8 --- 7 files changed, 33 insertions(+), 316 deletions(-) delete mode 100644 ROX-Filer/src/rox_gettext.c delete mode 100644 ROX-Filer/src/rox_gettext.h diff --git a/ROX-Filer/Options.xml b/ROX-Filer/Options.xml index c7d10b5b..7d3c67f5 100644 --- a/ROX-Filer/Options.xml +++ b/ROX-Filer/Options.xml @@ -1,38 +1,5 @@ -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/ROX-Filer/src/Makefile.in b/ROX-Filer/src/Makefile.in index 4a292853..e4568652 100644 --- a/ROX-Filer/src/Makefile.in +++ b/ROX-Filer/src/Makefile.in @@ -26,7 +26,7 @@ SRCS = abox.c action.c appinfo.c appmenu.c bind.c bookmarks.c \ gtksavebox.c \ gui_support.c i18n.c icon.c infobox.c log.c main.c menu.c minibuffer.c\ modechange.c mount.c options.c panel.c pinboard.c pixmaps.c \ - remote.c rox_gettext.c run.c sc.c session.c support.c \ + remote.c run.c sc.c session.c support.c \ tasklist.c toolbar.c type.c usericons.c view_collection.c \ view_details.c view_iface.c wrapped.c xml.c xtypes.c \ xdgmime.c xdgmimeglob.c xdgmimeint.c xdgmimemagic.c xdgmimeparent.c xdgmimealias.c xdgmimecache.c @@ -37,7 +37,7 @@ OBJECTS = abox.o action.o appinfo.o appmenu.o bind.o bookmarks.o \ gtksavebox.o \ gui_support.o i18n.o icon.o infobox.o log.o main.o menu.o minibuffer.o\ modechange.o mount.o options.o panel.o pinboard.o pixmaps.o \ - remote.o rox_gettext.o run.o sc.o session.o support.o \ + remote.o run.o sc.o session.o support.o \ tasklist.o toolbar.o type.o usericons.o view_collection.o \ view_details.o view_iface.o wrapped.o xml.o xtypes.o \ xdgmime.o xdgmimeglob.o xdgmimeint.o xdgmimemagic.o xdgmimeparent.o xdgmimealias.o xdgmimecache.o diff --git a/ROX-Filer/src/config.h.in b/ROX-Filer/src/config.h.in index 6a8772ac..d5bbc01e 100644 --- a/ROX-Filer/src/config.h.in +++ b/ROX-Filer/src/config.h.in @@ -46,8 +46,12 @@ #include "my_vfs.h" -#include "rox_gettext.h" -#define _(String) rox_gettext(String) +#ifdef HAVE_LIBINTL_H +# include +# define _(String) dgettext("ROX-Filer", String) +#else +# define _(String) (String) +#endif /* Short for gettext_noop() - marks a string as translatable without * actually translating it at that point. Used by xgettext. */ diff --git a/ROX-Filer/src/i18n.c b/ROX-Filer/src/i18n.c index 03390ea4..1fe6f560 100644 --- a/ROX-Filer/src/i18n.c +++ b/ROX-Filer/src/i18n.c @@ -43,15 +43,6 @@ /* Two/five-char country_territory code, or NULL */ char *current_lang = NULL; -static Option o_translation; - -static GtkWidget *i18n_message = NULL; - -/* Static Prototypes */ -static void set_trans(const guchar *lang); -static void trans_changed(void); -static GList *build_i18n_message(Option *option, xmlNode *node, guchar *label); - /**************************************************************** * EXTERNAL INTERFACE * ****************************************************************/ @@ -60,20 +51,36 @@ static GList *build_i18n_message(Option *option, xmlNode *node, guchar *label); /* Set things up for internationalisation */ void i18n_init(void) { + const char *lang; + + gtk_set_locale(); + #ifdef HAVE_LIBINTL_H gchar *path = g_strdup_printf("%s/Messages", app_dir); bindtextdomain("ROX-Filer", path); g_free(path); #endif - gtk_set_locale(); - option_add_string(&o_translation, "i18n_translation", "From LANG"); - set_trans(o_translation.value); - o_translation.has_changed = FALSE; /* Prevent warning about saving */ + /* This is a hang-over from when we did translations ourselves. + * Maybe we can get this info from the gettext library? + */ + lang = getenv("LANG"); + if (lang) + { + const char *end; - option_add_notify(trans_changed); + /* Extract the language code from the locale name. + * language[_territory][.codeset][@modifier] + */ - option_register_widget("i18n-message", build_i18n_message); + end = strchr(lang, '.'); + if (!end) + end = strchr(lang, '@'); + if (end) + current_lang = g_strndup(lang, end - lang); + else + current_lang = g_strdup(lang); + } } /* These two stolen from dia :-). @@ -159,99 +166,3 @@ void free_translated_entries(GtkItemFactoryEntry *entries, gint n) g_free(entries[i].path); g_free(entries); } - - -/**************************************************************** - * INTERNAL FUNCTIONS * - ****************************************************************/ - -static void trans_changed(void) -{ - if (!o_translation.has_changed) - return; - - set_trans(o_translation.value); - - if (i18n_message) - gtk_label_set_text(GTK_LABEL(i18n_message), MESSAGE); -} - -/* Load the 'Messages/.gmo' translation. - * Special values 'None' and 'From LANG' are also allowed. - */ -static void set_trans(const guchar *lang) -{ - guchar *path; - gchar *lang2; - - g_return_if_fail(lang != NULL); - - rox_clear_translation(); - - null_g_free(¤t_lang); - - if (strcmp(lang, "None") == 0) - return; - else if (strcmp(lang, "From LANG") == 0) - { - const guchar *end; - - lang = getenv("LANG"); - if (!lang) - return; - /* Extract the language code from the locale name. - * language[_territory][.codeset][@modifier] - */ - - end = strchr(lang, '.'); - if (!end) - end = strchr(lang, '@'); - if (end) - lang2 = g_strndup(lang, end - lang); - else - lang2 = g_strdup(lang); - } - else - lang2 = g_strdup(lang); - - current_lang = lang2; - - path = g_strdup_printf("%s/Messages/%s.gmo", app_dir, current_lang); - if (!file_exists(path) && strchr(current_lang, '_')) - { - /* Try again without the territory */ - strcpy(strrchr(path, '_'), ".gmo"); - } - - if (file_exists(path)) - rox_add_translations(path); - g_free(path); -} - -static GList *build_i18n_message(Option *option, xmlNode *node, guchar *label) -{ - GtkWidget *hbox, *image, *align; - - g_return_val_if_fail(option == NULL, NULL); - g_return_val_if_fail(label == NULL, NULL); - g_return_val_if_fail(i18n_message == NULL, NULL); - - i18n_message = gtk_label_new(MESSAGE); - g_signal_connect(i18n_message, "destroy", - G_CALLBACK(gtk_widget_destroyed), &i18n_message); - - gtk_misc_set_alignment(GTK_MISC(i18n_message), 0, 0.5); - gtk_label_set_justify(GTK_LABEL(i18n_message), GTK_JUSTIFY_LEFT); - gtk_label_set_line_wrap(GTK_LABEL(i18n_message), TRUE); - - hbox = gtk_hbox_new(FALSE, 4); - image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_INFO, - GTK_ICON_SIZE_BUTTON); - align = gtk_alignment_new(0, 0, 0, 0); - - gtk_container_add(GTK_CONTAINER(align), image); - gtk_box_pack_start(GTK_BOX(hbox), align, FALSE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(hbox), i18n_message, FALSE, TRUE, 0); - - return g_list_append(NULL, hbox); -} diff --git a/ROX-Filer/src/po/make-mo b/ROX-Filer/src/po/make-mo index b796b025..e616f48e 100755 --- a/ROX-Filer/src/po/make-mo +++ b/ROX-Filer/src/po/make-mo @@ -9,8 +9,9 @@ HERE fi OUT_DIR=../../Messages -LOCALE_DIR=$OUT_DIR/$1/LC_MESSAGES -OUT=$OUT_DIR/$1.gmo +LOCALE_DIR="$OUT_DIR/$1/LC_MESSAGES" +OUT="$LOCALE_DIR/ROX-Filer.mo" +mkdir -p "$LOCALE_DIR" # This code converts to UTF-8 format. Needed by Gtk+-2.0 at # least, and may help with other versions. @@ -19,12 +20,3 @@ echo Using charset \'$charset\' iconv -f $charset -t utf-8 $1.po | \ sed 's/; charset=\(.*\)\\n"/; charset=utf-8\\n"/' | \ msgfmt --statistics - -o $OUT && echo Created file $OUT OK - -# Create the $APP_DIR/Messages//LC_MESSAGES/ROX-Filer.mo link -# (or remove it when the translation (.gmo) is not available) -if [ -f "$OUT" ]; then - mkdir -p "$LOCALE_DIR" - ln -sf "../../$1.gmo" "$LOCALE_DIR/ROX-Filer.mo" -else - rm -f "$LOCALE_DIR/ROX-Filer.mo" -fi diff --git a/ROX-Filer/src/rox_gettext.c b/ROX-Filer/src/rox_gettext.c deleted file mode 100644 index a68fcd5b..00000000 --- a/ROX-Filer/src/rox_gettext.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * ROX-Filer, filer for the ROX desktop project - * Copyright (C) 2006, Thomas Leonard and others (see changelog for details). - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* This is a reimplementation of the GNU gettext function, because not everyone - * has GNU gettext. - */ - -#include "config.h" - -#include - -#include "global.h" - -#include "gui_support.h" - -static GHashTable *translate = NULL; - -/* Returns the 32 bit number at 'addr'. - * Reverse the byte order of 'number' iff 'swap' is TRUE. - */ -#define WORD(addr) word(addr, swap) - -/* Static prototypes */ -static guint32 word(char *addr, gboolean swap); - - -/**************************************************************** - * EXTERNAL INTERFACE * - ****************************************************************/ - -/* Returns a pointer to a static, nul-terminated, string which - * is the translation of 'from' (or 'from' itself if there is - * no translation). - */ -const char *rox_gettext(const char *from) -{ - char *retval; - - if (!translate || !from || !*from) - return from; - - retval = g_hash_table_lookup(translate, from); - - return retval ? retval : from; -} - -void rox_clear_translation(void) -{ - if (translate) - { - g_hash_table_destroy(translate); - translate = NULL; - } -} - -/* Read in this .gmo format file; all translations found override - * any existing translations for future calls to rox_gettext(). - */ -void rox_add_translations(const char *path) -{ - guint32 magic; - char *data, *from_base, *to_base; - gsize size; - gboolean swap; /* TRUE => reverse byte-order of ints */ - int n, n_total; - GError *error = NULL; - - if (!g_file_get_contents(path, &data, &size, &error)) - { - delayed_error("%s", error ? error->message : path); - g_error_free(error); - return; - } - - if (size < 20) - { - delayed_error(_("Invalid .gmo translation file " - "(too short): %s"), path); - goto out; - } - - magic = *((guint *) data); - - if (magic == 0x950412de) - swap = FALSE; - else if (magic == 0xde120495) - swap = TRUE; - else - { - delayed_error(_("Invalid .gmo translation file " - "(GNU magic number not found): %s"), - path); - goto out; - } - - if (WORD(data + 4) != 0) - g_warning("rox_add_translations: expected format revision 0"); - - if (!translate) - { - translate = g_hash_table_new_full(g_str_hash, g_str_equal, - g_free, g_free); - } - - n_total = WORD(data + 8); - from_base = data + WORD(data + 12); - to_base = data + WORD(data + 16); - - for (n = 0; n < n_total; n++) - { - char *from = data + WORD(from_base + (n << 3) + 4); - char *to = data + WORD(to_base + (n << 3) + 4); - - g_hash_table_insert(translate, g_strdup(from), g_strdup(to)); - } - -out: - g_free(data); -} - -/**************************************************************** - * INTERNAL FUNCTIONS * - ****************************************************************/ - -static guint32 word(char *addr, gboolean swap) -{ - guint32 val = *((guint32 *) addr); - - if (swap) - return GUINT32_SWAP_LE_BE(val); - else - return val; -} diff --git a/ROX-Filer/src/rox_gettext.h b/ROX-Filer/src/rox_gettext.h deleted file mode 100644 index 76cd7e85..00000000 --- a/ROX-Filer/src/rox_gettext.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * ROX-Filer, filer for the ROX desktop project - * By Thomas Leonard, . - */ - -const char *rox_gettext(const char *from); -void rox_add_translations(const char *path); -void rox_clear_translation(void); -- 2.11.4.GIT