mirror of https://github.com/GNOME/gimp.git
app, plug-ins: move the locale processing code in the core.
The colon-separated list used in the plugin originally comes from gimp_help_get_locales() anyway. My previous code was using different lists of locales in different places, which was inconsistent.
This commit is contained in:
parent
65e8521402
commit
08e8c0e4f8
|
@ -592,11 +592,92 @@ static gchar *
|
|||
gimp_help_get_locales (Gimp *gimp)
|
||||
{
|
||||
GimpGuiConfig *config = GIMP_GUI_CONFIG (gimp->config);
|
||||
gchar **names;
|
||||
gchar *locales = NULL;
|
||||
GList *locales_list = NULL;
|
||||
GList *iter;
|
||||
gint i;
|
||||
|
||||
if (config->help_locales && strlen (config->help_locales))
|
||||
return g_strdup (config->help_locales);
|
||||
|
||||
return g_strjoinv (":", (gchar **) g_get_language_names ());
|
||||
/* Process locales. */
|
||||
names = (gchar **) g_get_language_names ();
|
||||
for (i = 0; names[i]; i++)
|
||||
{
|
||||
gchar *locale = g_strdup (names[i]);
|
||||
gchar *c;
|
||||
|
||||
/* We don't care about encoding in context of our help system. */
|
||||
c = strchr (locale, '.');
|
||||
if (c)
|
||||
*c = '\0';
|
||||
/* We don't care about variants as well. */
|
||||
c = strchr (locale, '@');
|
||||
if (c)
|
||||
*c = '\0';
|
||||
/* Apparently some systems (i.e. Windows) would return a value as
|
||||
* IETF language tag, which is a different format from POSIX
|
||||
* locale; especially it would separate the lang and the region
|
||||
* with an hyphen instead of an underscore.
|
||||
* Actually the difference is much deeper, and IETF language tags
|
||||
* can have extended language subtags, a script subtag, variants,
|
||||
* moreover using different codes.
|
||||
* We'd actually need to look into this in details (TODO).
|
||||
* this dirty hack should do for easy translation at least (like
|
||||
* "en-GB" -> "en_GB).
|
||||
* Cf. bug 777754.
|
||||
*/
|
||||
c = strchr (locale, '-');
|
||||
if (c)
|
||||
*c = '_';
|
||||
if (locale && *locale &&
|
||||
! g_list_find_custom (locales_list, locale,
|
||||
(GCompareFunc) g_strcmp0))
|
||||
{
|
||||
gchar *base;
|
||||
|
||||
/* Adding this locale. */
|
||||
locales_list = g_list_prepend (locales_list, locale);
|
||||
|
||||
/* Adding the base language as well. */
|
||||
base = strdup (locale);
|
||||
c = strchr (base, '_');
|
||||
if (c)
|
||||
*c = '\0';
|
||||
if (base && *base &&
|
||||
! g_list_find_custom (locales_list, base,
|
||||
(GCompareFunc) g_strcmp0))
|
||||
{
|
||||
locales_list = g_list_prepend (locales_list, base);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_free (base);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Avoid duplicates. */
|
||||
g_free (locale);
|
||||
}
|
||||
}
|
||||
locales_list = g_list_reverse (locales_list);
|
||||
|
||||
/* Finally generate the colon-separated value. */
|
||||
if (locales_list)
|
||||
{
|
||||
locales = g_strdup (locales_list->data);
|
||||
for (iter = locales_list->next; iter; iter = iter->next)
|
||||
{
|
||||
gchar *temp = locales;
|
||||
locales = g_strconcat (temp, ":", iter->data, NULL);
|
||||
g_free (temp);
|
||||
}
|
||||
}
|
||||
g_list_free_full (locales_list, g_free);
|
||||
|
||||
return locales;
|
||||
}
|
||||
|
||||
static GFile *
|
||||
|
|
|
@ -125,62 +125,7 @@ gimp_help_parse_locales (const gchar *help_locales)
|
|||
for (p = strchr (s, ':'); p; p = strchr (s, ':'))
|
||||
{
|
||||
gchar *new = g_strndup (s, p - s);
|
||||
gchar *c;
|
||||
|
||||
/* After a dot is displayed the optional encoding.
|
||||
* We don't care in context of our help system.
|
||||
*/
|
||||
c = strchr (new, '.');
|
||||
if (c)
|
||||
*c = '\0';
|
||||
/* We don't care about variants as well. */
|
||||
c = strchr (new, '@');
|
||||
if (c)
|
||||
*c = '\0';
|
||||
/* Apparently some systems (i.e. Windows) would return a value as
|
||||
* IETF language tag, which is a different format from POSIX
|
||||
* locale; especially it would separate the lang and the region
|
||||
* with an hyphen instead of an underscore.
|
||||
* Actually the difference is much deeper, and IETF language tags
|
||||
* can have extended language subtags, a script subtag, variants,
|
||||
* moreover using different codes.
|
||||
* We'd actually need to look into this in details (TODO).
|
||||
* this dirty hack should do for easy translation at least (like
|
||||
* "en-GB" -> "en_GB).
|
||||
*/
|
||||
c = strchr (new, '-');
|
||||
if (c)
|
||||
*c = '_';
|
||||
if (new && *new &&
|
||||
! g_list_find_custom (locales, new,
|
||||
(GCompareFunc) g_strcmp0))
|
||||
{
|
||||
gchar *base;
|
||||
|
||||
/* Adding this locale. */
|
||||
locales = g_list_append (locales, new);
|
||||
|
||||
/* Adding the base language as well. */
|
||||
base = strdup (new);
|
||||
c = strchr (base, '_');
|
||||
if (c)
|
||||
*c = '\0';
|
||||
if (base && *base &&
|
||||
! g_list_find_custom (locales, base,
|
||||
(GCompareFunc) g_strcmp0))
|
||||
{
|
||||
locales = g_list_append (locales, base);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_free (base);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_free (new);
|
||||
}
|
||||
|
||||
s = p + 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue