Commit f6dcde1e authored by Jehan's avatar Jehan

Bug 576910: Show 'Language' setting languages in native language

The trick works by temporarily resetting the current locale to localize
each language label in its own lang.
One exception is English that is equivalent to the "C" code, and we make
also some special exception for Chinese where there are very different
variant depending on the region.
I also ensure the "System Language" string is translated in whatever
language is the system actually set to.
parent f885085b
......@@ -67,6 +67,10 @@ static void iso_codes_parser_end_element (GMarkupParseContext *context,
static void iso_codes_parser_start_unknown (IsoCodesParser *parser);
static void iso_codes_parser_end_unknown (IsoCodesParser *parser);
static void gimp_language_store_self_l10n (GimpLanguageStore *store,
const gchar *lang,
const gchar *code);
static void
iso_codes_parser_init (void)
......@@ -160,11 +164,58 @@ iso_codes_parser_entry (IsoCodesParser *parser,
values++;
}
/* This is a hack for some special exception.
* It seems localization won't work for the base language "zh". Probably because
* written locale dialect are too different. So we have to be accurate and localize
* separately each Chinese dialect we support.
*
* There was unfortunately no cleaner way to achieve this since there is no standardized
* link between regions in iso-3166 and base languages in iso-639, which would allow
* automatization for generating locale dialects codes.
*/
if (g_strcmp0 (code, "zh") == 0)
{
gimp_language_store_self_l10n (parser->store, "Chinese", "zh_CN");
gimp_language_store_self_l10n (parser->store, "Chinese", "zh_TW");
gimp_language_store_self_l10n (parser->store, "Chinese", "zh_HK");
}
else
gimp_language_store_self_l10n (parser->store, lang, code);
}
/* If possible, we want to localize a language in itself.
* If it fails, fallback to the currently selected language, then to system lang.
* Only fallback to C (en_US) as a last resort.
*/
static void
gimp_language_store_self_l10n (GimpLanguageStore *store,
const gchar *lang,
const gchar *code)
{
if (lang && *lang && code && *code)
{
const gchar *semicolon;
const gchar *current_lang = g_getenv ("LANGUAGE");
/* English does not need localization. */
if (g_strcmp0 (code, "en") != 0)
{
gchar *temp_lang;
lang = dgettext ("iso_639", lang);
if (current_lang)
temp_lang = g_strdup_printf ("%s:%s:%s", code, current_lang, setlocale (LC_ALL, NULL));
else
temp_lang = g_strdup (code);
/* Temporarily change the localization language. */
g_setenv ("LANGUAGE", temp_lang, TRUE);
setlocale (LC_ALL, "");
lang = dgettext ("iso_639", lang);
g_setenv ("LANGUAGE", current_lang, TRUE);
setlocale (LC_ALL, "");
g_free (temp_lang);
}
/* there might be several language names; use the first one */
semicolon = strchr (lang, ';');
......@@ -173,12 +224,12 @@ iso_codes_parser_entry (IsoCodesParser *parser,
{
gchar *first = g_strndup (lang, semicolon - lang);
gimp_language_store_add (parser->store, first, code);
gimp_language_store_add (store, first, code);
g_free (first);
}
else
{
gimp_language_store_add (parser->store, lang, code);
gimp_language_store_add (store, lang, code);
}
}
}
......
......@@ -83,7 +83,8 @@ gimp_translation_store_init (GimpTranslationStore *store)
static void
gimp_translation_store_constructed (GObject *object)
{
GimpTranslationStore *store = GIMP_TRANSLATION_STORE (object);
const gchar *current_lang = g_getenv ("LANGUAGE");
GimpTranslationStore *store = GIMP_TRANSLATION_STORE (object);
gchar *label;
G_OBJECT_CLASS (parent_class)->constructed (object);
......@@ -94,11 +95,20 @@ gimp_translation_store_constructed (GObject *object)
g_hash_table_unref (store->map);
store->map = NULL;
/* add special entries for system locale and for "C" */
/* add special entries for system locale and for "C".
* We want the system locale to be localized in itself. */
g_setenv ("LANGUAGE", setlocale (LC_ALL, NULL), TRUE);
setlocale (LC_ALL, "");
label = g_strdup_printf ("%s [%s]", _("System Language"),
setlocale (LC_ALL, NULL));
g_setenv ("LANGUAGE", current_lang, TRUE);
setlocale (LC_ALL, "");
GIMP_LANGUAGE_STORE_CLASS (parent_class)->add (GIMP_LANGUAGE_STORE (store),
_("System Language"),
label,
NULL);
label = g_strdup_printf ("%s [%s]", _("English"), "en_US");
g_free (label);
label = g_strdup_printf ("%s [%s]", "English", "en_US");
GIMP_LANGUAGE_STORE_CLASS (parent_class)->add (GIMP_LANGUAGE_STORE (store),
label, "en_US");
g_free (label);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment