I hesitated a lot whether we should just drop the whole localization of
plug-ins' label and description (blurb) within the core. Actually the
commit messages I wrote a few days ago were moving towards this logic.
It really looks to me like plug-in localization can happen fully within
plug-in themselves. As far as I can see, the only advantage which the
current logic has theoretically is that if we needed, we have access to
both the original strings and their translations (e.g. it could be
useful for text search). Nevertheless I am not sure if we will ever make
use of this, and this is limited cases as all filters turned GEGL ops
don't have such ability anyway.
Nevertheless since previous contributors clearly put quite a lot of work
on this code of localizing the plug-in's label and description within
the main binary, I want to give myself a little more time to think and
study the whole thing because doing anything rash.
In the meantime, what changes is that by default now, a plug-in without
a local gettext catalog is simply not localized. In particular, the core
process doesn't try to localize it using the default catalog, a.k.a.
GETTEXT_PACKAGE"-std-plug-ins" ("gimp30-std-plug-ins"). It just doesn't
make sense and the worst which could happen would be to get unexpected
and wrong translations.
Now by default, plug-ins will try to find a catalog in their main
folder, named as this folder. If it fails to find it, a message is
printed to stderr and localization is disabled (rather than falling back
to a default catalog). It is up to plug-in developers to either install
a catalog, or implement set_i18n() to give the right catalog, folder, or
disable localization with gettext, as handled by libgimp.
189 lines
5.3 KiB
C
189 lines
5.3 KiB
C
/* GIMP - The GNU Image Manipulation Program
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
*
|
|
* gimppluginmanager-locale-domain.c
|
|
*
|
|
* 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 3 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, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <gio/gio.h>
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
#include "plug-in-types.h"
|
|
|
|
#include "gimppluginmanager.h"
|
|
#include "gimppluginmanager-locale-domain.h"
|
|
|
|
|
|
#define STD_PLUG_INS_LOCALE_DOMAIN GETTEXT_PACKAGE "-std-plug-ins"
|
|
|
|
|
|
typedef struct _GimpPlugInLocaleDomain GimpPlugInLocaleDomain;
|
|
|
|
struct _GimpPlugInLocaleDomain
|
|
{
|
|
GFile *file;
|
|
gchar *domain_name;
|
|
gchar *domain_path;
|
|
};
|
|
|
|
|
|
void
|
|
gimp_plug_in_manager_locale_domain_exit (GimpPlugInManager *manager)
|
|
{
|
|
GSList *list;
|
|
|
|
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
|
|
|
|
for (list = manager->locale_domains; list; list = list->next)
|
|
{
|
|
GimpPlugInLocaleDomain *domain = list->data;
|
|
|
|
g_object_unref (domain->file);
|
|
g_free (domain->domain_name);
|
|
g_free (domain->domain_path);
|
|
g_slice_free (GimpPlugInLocaleDomain, domain);
|
|
}
|
|
|
|
g_slist_free (manager->locale_domains);
|
|
manager->locale_domains = NULL;
|
|
}
|
|
|
|
void
|
|
gimp_plug_in_manager_add_locale_domain (GimpPlugInManager *manager,
|
|
GFile *file,
|
|
const gchar *domain_name,
|
|
const gchar *domain_path)
|
|
{
|
|
GimpPlugInLocaleDomain *domain;
|
|
|
|
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
|
|
g_return_if_fail (G_IS_FILE (file));
|
|
g_return_if_fail (domain_name != NULL);
|
|
|
|
domain = g_slice_new (GimpPlugInLocaleDomain);
|
|
|
|
domain->file = g_object_ref (file);
|
|
domain->domain_name = g_strdup (domain_name);
|
|
domain->domain_path = g_strdup (domain_path);
|
|
|
|
manager->locale_domains = g_slist_prepend (manager->locale_domains, domain);
|
|
|
|
#ifdef VERBOSE
|
|
g_print ("added locale domain \"%s\" for path \"%s\"\n",
|
|
domain->domain_name ? domain->domain_name : "(null)",
|
|
domain->domain_path ?
|
|
gimp_filename_to_utf8 (domain->domain_path) : "(null)");
|
|
#endif
|
|
}
|
|
|
|
gboolean
|
|
gimp_plug_in_manager_get_i18n (GimpPlugInManager *manager,
|
|
GFile *file,
|
|
const gchar **locale_domain,
|
|
const gchar **domain_path)
|
|
{
|
|
GSList *list;
|
|
|
|
g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), FALSE);
|
|
g_return_val_if_fail (file == NULL || G_IS_FILE (file), FALSE);
|
|
|
|
if (domain_path)
|
|
*domain_path = gimp_locale_directory ();
|
|
|
|
/* A NULL prog_name is GIMP itself, return the default domain */
|
|
if (! file)
|
|
{
|
|
if (locale_domain)
|
|
*locale_domain = NULL;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
for (list = manager->locale_domains; list; list = list->next)
|
|
{
|
|
GimpPlugInLocaleDomain *domain = list->data;
|
|
|
|
if (domain && domain->file &&
|
|
g_file_equal (domain->file, file))
|
|
{
|
|
if (domain_path && domain->domain_path)
|
|
*domain_path = domain->domain_path;
|
|
|
|
if (locale_domain)
|
|
*locale_domain = domain->domain_name;
|
|
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
gint
|
|
gimp_plug_in_manager_get_locale_domains (GimpPlugInManager *manager,
|
|
gchar ***locale_domains,
|
|
gchar ***locale_paths)
|
|
{
|
|
GSList *list;
|
|
GSList *unique = NULL;
|
|
gint n_domains;
|
|
gint i;
|
|
|
|
g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), 0);
|
|
g_return_val_if_fail (locale_domains != NULL, 0);
|
|
g_return_val_if_fail (locale_paths != NULL, 0);
|
|
|
|
for (list = manager->locale_domains; list; list = list->next)
|
|
{
|
|
GimpPlugInLocaleDomain *domain = list->data;
|
|
GSList *tmp;
|
|
|
|
for (tmp = unique; tmp; tmp = tmp->next)
|
|
if (! strcmp (domain->domain_name, (const gchar *) tmp->data))
|
|
break;
|
|
|
|
if (! tmp)
|
|
unique = g_slist_prepend (unique, domain);
|
|
}
|
|
|
|
unique = g_slist_reverse (unique);
|
|
|
|
n_domains = g_slist_length (unique) + 1;
|
|
|
|
*locale_domains = g_new0 (gchar *, n_domains + 1);
|
|
*locale_paths = g_new0 (gchar *, n_domains + 1);
|
|
|
|
(*locale_domains)[0] = g_strdup (STD_PLUG_INS_LOCALE_DOMAIN);
|
|
(*locale_paths)[0] = g_strdup (gimp_locale_directory ());
|
|
|
|
for (list = unique, i = 1; list; list = list->next, i++)
|
|
{
|
|
GimpPlugInLocaleDomain *domain = list->data;
|
|
|
|
(*locale_domains)[i] = g_strdup (domain->domain_name);
|
|
(*locale_paths)[i] = (domain->domain_path ?
|
|
g_strdup (domain->domain_path) :
|
|
g_strdup (gimp_locale_directory ()));
|
|
}
|
|
|
|
g_slist_free (unique);
|
|
|
|
return n_domains;
|
|
}
|