diff options
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | data/epiphany.schemas.in | 2 | ||||
-rw-r--r-- | embed/mozilla/mozilla-notifiers.cpp | 115 | ||||
-rw-r--r-- | lib/ephy-langs.c | 138 | ||||
-rw-r--r-- | lib/ephy-langs.h | 10 | ||||
-rw-r--r-- | src/prefs-dialog.c | 56 |
6 files changed, 223 insertions, 110 deletions
@@ -1,5 +1,17 @@ 2004-11-07 Christian Persch <chpe@cvs.gnome.org> + * data/epiphany.schemas.in: + * embed/mozilla/mozilla-notifiers.cpp: + * lib/ephy-langs.c: (ephy_font_n_languages), (ephy_langs_sanitise), + (ephy_langs_append_languages), (ephy_langs_get_languages): + * lib/ephy-langs.h: + * src/prefs-dialog.c: (add_system_language_entry), + (setup_add_language_dialog), (create_language_section): + + Show language code in the string in languages editor. Fixes bug #115355. + +2004-11-07 Christian Persch <chpe@cvs.gnome.org> + * lib/widgets/ephy-zoom-control.c: (ephy_zoom_control_init), (set_combo_tooltip), (combo_realized), (ephy_zoom_control_set_tooltip): diff --git a/data/epiphany.schemas.in b/data/epiphany.schemas.in index ed72f722f..b3282a896 100644 --- a/data/epiphany.schemas.in +++ b/data/epiphany.schemas.in @@ -258,7 +258,7 @@ <owner>epiphany</owner> <type>list</type> <list_type>string</list_type> - <default>[system,en]</default> + <default>[]</default> <locale name="C"> <short>Languages</short> <long>Preferred languages, two letter codes.</long> diff --git a/embed/mozilla/mozilla-notifiers.cpp b/embed/mozilla/mozilla-notifiers.cpp index f8c324f2d..9bc057f14 100644 --- a/embed/mozilla/mozilla-notifiers.cpp +++ b/embed/mozilla/mozilla-notifiers.cpp @@ -33,6 +33,7 @@ #include "ephy-langs.h" #include "ephy-debug.h" +#include <glib/gi18n.h> #include <stdio.h> #include <string.h> #include <locale.h> @@ -44,8 +45,6 @@ #include <nsEmbedString.h> #include <nsIPrefService.h> #include <nsIServiceManager.h> -/* we don't use glib/gi18n.h here because we need gnome_i18n_get_language_list() */ -#include <libgnome/gnome-i18n.h> #ifdef ALLOW_PRIVATE_API #include <nsIProtocolProxyService.h> @@ -696,118 +695,46 @@ mozilla_allow_popups_notifier(GConfClient *client, mozilla_prefs_set_boolean ("dom.disable_open_during_load", !value); } -static char * -get_system_language () -{ - const GList *sys_langs; - const char *lang; - - /** - * This is a comma separated list of language ranges, as specified - * by RFC 2616, 14.4. - * Always include the basic language code last. - * - * Examples: - * "pt" translation: "pt" - * "pt_BR" translation: "pt-br,pt" - * "zh_CN" translation: "zh-cn,zh" - * "zh_HK" translation: "zh-hk,zh" or maybe "zh-hk,zh-tw,zh" - */ - lang = _("system-language"); - - if (strncmp (lang, "system-language", 15) != 0) - { - /* the l10n has it */ - return g_strdup (lang); - } - - sys_langs = gnome_i18n_get_language_list ("LC_MESSAGES"); - - if (sys_langs) - { - lang = (char *)sys_langs->data; - - /* FIXME this probably need to be smarter */ - /* FIXME this can be up to 8 chars, not just 2 */ - if (strcmp (lang, "C") != 0) - { - return g_strndup (lang, 2); - } - } - - /* fallback to english */ - return g_strdup ("en"); -} - static void mozilla_language_notifier(GConfClient *client, guint cnxn_id, GConfEntry *entry, EphyEmbedSingle *single) { - GSList *languages, *l, *ulist = NULL; - GString *result; + GArray *array; + GSList *languages, *l; + char **langs; + char *list; languages = eel_gconf_get_string_list (CONF_RENDERING_LANGUAGE); - result = g_string_new (""); - - /* substitute the system language */ - l = g_slist_find_custom (languages, "system", (GCompareFunc) strcmp); - if (l != NULL) - { - char *sys_lang; - int index; - - index = g_slist_position (languages, l); - g_free (l->data); - languages = g_slist_delete_link (languages, l); + array = g_array_new (TRUE, FALSE, sizeof (char *)); - sys_lang = get_system_language (); - - if (sys_lang) - { - char **s; - int i = 0; - - s = g_strsplit (sys_lang, ",", -1); - while (s[i] != NULL) - { - languages = g_slist_insert (languages, g_strdup (s[i]), index); - - index ++; - i++; - } - - g_strfreev (s); - g_free (sys_lang); - } - } - - /* now make a list of unique entries */ for (l = languages; l != NULL; l = l->next) { - if (g_slist_find_custom (ulist, l->data, (GCompareFunc) strcmp) == NULL) + if (strcmp ((char *) l->data, "system") == 0) + { + ephy_langs_append_languages (array); + g_free (l->data); + } + else { - ulist = g_slist_prepend (ulist, l->data); + g_array_append_val (array, l->data); } } - ulist = g_slist_reverse (ulist); - for (l = ulist; l != NULL; l = l->next) - { - g_string_append (result, (char *)l->data); + g_slist_free (languages); - if (l->next) g_string_append (result, ","); - } + ephy_langs_sanitise (array); - mozilla_prefs_set_string ("intl.accept_languages", result->str); + langs = (char **) g_array_free (array, FALSE); - g_string_free (result, TRUE); + list = g_strjoinv (",", langs); - g_slist_foreach (languages, (GFunc) g_free, NULL); - g_slist_free (languages); - g_slist_free (ulist); + mozilla_prefs_set_string ("intl.accept_languages", list); + + g_strfreev (langs); + g_free (list); } static void diff --git a/lib/ephy-langs.c b/lib/ephy-langs.c index ff05c34e1..bf86010bf 100644 --- a/lib/ephy-langs.c +++ b/lib/ephy-langs.c @@ -24,6 +24,8 @@ #include <glib/gi18n.h> +#include <string.h> + static const EphyFontsLanguageInfo font_languages [] = { { N_("Arabic"), "ar" }, @@ -57,3 +59,139 @@ ephy_font_n_languages (void) { return n_font_languages; } + +/* sanitise the languages list according to the rules for HTTP accept-language + * in RFC 2616, Sect. 14.4 + */ +void +ephy_langs_sanitise (GArray *array) +{ + char *lang1, *lang2; + int i, j; + + /* if we have 'xy-ab' in list but not 'xy', append 'xy' */ + for (i = 0; i < array->len; i++) + { + gboolean found = FALSE; + char *dash, *prefix; + + lang1 = (char *) g_array_index (array,char *, i); + + dash = strchr (lang1, '-'); + if (dash == NULL) continue; + + for (j = i + 1; j < array->len; j++) + { + lang2 = (char *) g_array_index (array, char *, j); + if (strchr (lang2, '-') == NULL && + g_str_has_prefix (lang1, lang2)) + { + found = TRUE; + } + } + + if (found == FALSE) + { + prefix = g_strndup (lang1, dash - lang1); + g_array_append_val (array, prefix); + } + } + + /* uniquify */ + for (i = 0; i < array->len - 1; i++) + { + for (j = array->len - 1; j > i; j--) + { + lang1 = (char *) g_array_index (array,char *, i); + lang2 = (char *) g_array_index (array, char *, j); + + if (strcmp (lang1, lang2) == 0) + { + g_array_remove_index (array, j); + g_free (lang2); + } + } + } + + /* move 'xy' code behind all 'xy-ab' codes */ + for (i = array->len - 2; i >= 0; i--) + { + for (j = array->len - 1; j > i; j--) + { + lang1 = (char *) g_array_index (array, char *, i); + lang2 = (char *) g_array_index (array, char *, j); + + if (strchr (lang1, '-') == NULL && + strchr (lang2, '-') != NULL && + g_str_has_prefix (lang2, lang1)) + { + g_array_insert_val (array, j + 1, lang1); + g_array_remove_index (array, i); + break; + } + } + } +} + +void +ephy_langs_append_languages (GArray *array) +{ + const char * const * languages; + const char *system_lang; + char *lang; + int i; + + /** + * This is a comma separated list of language ranges, as specified + * by RFC 2616, 14.4. + * Always include the basic language code last. + * + * Examples: + * "pt" translation: "pt" + * "pt_BR" translation: "pt-br,pt" + * "zh_CN" translation: "zh-cn,zh" + * "zh_HK" translation: "zh-hk,zh" or maybe "zh-hk,zh-tw,zh" + */ + system_lang = _("system-language"); + + /* FIXME: use system_language when given, instead of g_get_language_names () ? */ + languages = g_get_language_names (); + g_return_if_fail (languages != NULL); + + /* FIXME: maybe just use the first, instead of all of them? */ + for (i = 0; languages[i] != NULL; i++) + { + + if (strstr (languages[i], ".") == 0 && + strstr (languages[i], "@") == 0 && + strcmp (languages[i], "C") != 0) + { + /* change to lowercase and '_' to '-' */ + lang = g_strdelimit (g_ascii_strdown + (languages[i], -1), "_", '-'); + + g_array_append_val (array, lang); + } + } + + /* Fallback: add "en" if list is empty */ + if (array->len == 0) + { + lang = g_strdup ("en"); + g_array_append_val (array, lang); + } +} + +char ** +ephy_langs_get_languages (void) +{ + GArray *array; + + array = g_array_new (TRUE, FALSE, sizeof (char *)); + + ephy_langs_append_languages (array); + + ephy_langs_sanitise (array); + + return (char **) g_array_free (array, FALSE); +} diff --git a/lib/ephy-langs.h b/lib/ephy-langs.h index 4715801f4..baefdd78d 100644 --- a/lib/ephy-langs.h +++ b/lib/ephy-langs.h @@ -32,9 +32,15 @@ typedef struct char *code; } EphyFontsLanguageInfo; -const EphyFontsLanguageInfo *ephy_font_languages (void); +const EphyFontsLanguageInfo *ephy_font_languages (void); -guint ephy_font_n_languages (void); +guint ephy_font_n_languages (void); + +void ephy_langs_append_languages (GArray *array); + +void ephy_langs_sanitise (GArray *array); + +char **ephy_langs_get_languages (void); G_END_DECLS diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c index 06d3cb1f0..9fdf34a73 100644 --- a/src/prefs-dialog.c +++ b/src/prefs-dialog.c @@ -94,14 +94,6 @@ struct } languages [] = { - /** - * please translate like this: "<your language> (System setting)" - * Examples: - * "de" translation: "Deutsch (Systemeinstellung)" - * "en_AU" translation: "English, Australia (System setting)" or - * "Australian English (System setting)" - */ - { N_("System language"), "system" }, { N_("Afrikaans"), "ak" }, { N_("Albanian"), "sq" }, { N_("Arabic"), "ar" }, @@ -777,6 +769,34 @@ add_lang_dialog_response_cb (GtkWidget *widget, g_object_unref (dialog); } +static void +add_system_language_entry (GtkListStore *store) +{ + GtkTreeIter iter; + char **sys_langs; + char *system, *text; + int n_sys_langs; + + sys_langs = ephy_langs_get_languages (); + n_sys_langs = g_strv_length (sys_langs); + + system = g_strjoinv (", ", sys_langs); + + text = g_strdup_printf + (ngettext (_("System language [%s]"), + _("System languages [%s]"), n_sys_langs), system); + + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + COL_LANG_NAME, text, + COL_LANG_CODE, "system", + -1); + + g_strfreev (sys_langs); + g_free (system); + g_free (text); +} + static EphyDialog * setup_add_language_dialog (PrefsDialog *pd) { @@ -817,6 +837,8 @@ setup_add_language_dialog (PrefsDialog *pd) -1); } + add_system_language_entry (store); + sortmodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store)); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sortmodel), COL_LANG_NAME, GTK_SORT_ASCENDING); @@ -1053,11 +1075,19 @@ create_language_section (EphyDialog *dialog) /* code isn't in stock list */ if (i == n_languages) { - char *text; - - text = g_strdup_printf (_("Custom [%s]"), code); - language_editor_add (pd, code, text); - g_free (text); + if (strcmp (code, "system") != 0) + { + char *text; + + text = g_strdup_printf (_("Custom [%s]"), code); + + language_editor_add (pd, code, text); + g_free (text); + } + else + { + add_system_language_entry (store); + } } else { |