Commit f7579eab authored by Jehan's avatar Jehan
Browse files

libgimp: set_i18n() method of GimpPlugIn expects UTF-8 catalog directory.

Nothing was really clearly specified until now, which was kinda equivalent to
the string being in the OS encoding as used by GLib. Since this string will
usually be statically hardcoded in code (and not extracted from system), it's
just much easier to request UTF-8 for this specific case.
parent f5d2c536
Pipeline #484269 failed with stages
in 22 minutes and 18 seconds
......@@ -898,15 +898,17 @@ _gimp_plug_in_set_i18n (GimpPlugIn *plug_in,
}
else
{
gchar *utf8_catalog_dir = NULL;
use_gettext = GIMP_PLUG_IN_GET_CLASS (plug_in)->set_i18n (plug_in,
procedure_name,
gettext_domain,
catalog_dir);
&utf8_catalog_dir);
if (use_gettext)
{
gboolean reserved = FALSE;
if (! (*gettext_domain))
if (*gettext_domain == NULL)
{
*gettext_domain = g_strdup (plug_in->priv->translation_domain_name);
}
......@@ -919,17 +921,34 @@ _gimp_plug_in_set_i18n (GimpPlugIn *plug_in,
* set by the lib itself; devs must set NULL). See docs of
* set_i18n() method.
*/
if (*catalog_dir)
{
g_printerr ("[%s] Do not set a catalog directory with set_i18n() with reserved domain: %s\n",
procedure_name, *gettext_domain);
g_clear_pointer (catalog_dir, g_free);
}
if (utf8_catalog_dir != NULL)
g_printerr ("[%s] Do not set a catalog directory with set_i18n() with reserved domain: %s\n",
procedure_name, *gettext_domain);
*catalog_dir = g_strdup (gimp_locale_directory ());
reserved = TRUE;
}
if (utf8_catalog_dir != NULL && *catalog_dir == NULL)
{
GError *error = NULL;
/* The passed-on catalog directory is in UTF-8 because this is
* usually hardcoded (in which case it's easier to request a
* specific encoding, chosen at development time, rather than the
* "OS encoding", depending on runtime).
* But now we want to transform it to the encoding used for
* filenames by GLib.
*/
*catalog_dir = g_filename_from_utf8 (utf8_catalog_dir, -1, NULL, NULL, &error);
if (*catalog_dir == NULL)
g_printerr ("[%s] provided catalog directory is not proper UTF-8: %s\n",
procedure_name, error ? error->message : "(N/A)");
g_clear_error (&error);
}
if (*catalog_dir && ! reserved)
{
if (g_path_is_absolute (*catalog_dir))
......@@ -982,6 +1001,8 @@ _gimp_plug_in_set_i18n (GimpPlugIn *plug_in,
*catalog_dir = g_file_get_path (plug_in->priv->translation_domain_path);
}
}
g_clear_pointer (&utf8_catalog_dir, g_free);
}
if (use_gettext && ! g_file_test (*catalog_dir, G_FILE_TEST_IS_DIR))
......
......@@ -134,8 +134,8 @@ struct _GimpPlugInClass
* @gettext_domain: (out) (nullable): Gettext domain. If %NULL, it
* defaults to the plug-in name as determined by the
* directory the binary is called from.
* @catalog_dir: (out) (nullable): relative path to a subdirectory
* of the plug-in folder containing the compiled
* @catalog_dir: (out) (nullable) (type utf8): relative path to a
* subdirectory of the plug-in folder containing the compiled
* Gettext message catalogs. If %NULL, it defaults to
* "locale/".
*
......@@ -157,12 +157,12 @@ struct _GimpPlugInClass
* simply set the method to %NULL, or possibly implement this method
* to do something useful for your usage while returning %FALSE.
*
* If you wish to tweak the @gettext_domain or the @localedir, return
* %TRUE and allocate appropriate @gettext_domain and/or @localedir
* If you wish to tweak the @gettext_domain or the @catalog_dir, return
* %TRUE and allocate appropriate @gettext_domain and/or @catalog_dir
* (these use the default if set %NULL).
*
* Note that @localedir must be a relative path, subdirectory of the
* directory of `gimp_get_progname()`.
* Note that @catalog_dir must be a relative path, encoded as UTF-8,
* subdirectory of the directory of `gimp_get_progname()`.
* The domain names "gimp30-std-plug-ins", "gimp30-script-fu" and
* "gimp30-python" are reserved and can only be used with a %NULL
* @catalog_dir. These will use the translation catalogs installed for
......
Supports Markdown
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