Commit 19fbd75e authored by Philip Withnall's avatar Philip Withnall

internationalization: Recommend use of org.freedesktop.locale1

Rather than inventing our own system-wide LocaleManager D-Bus service,
we should use the one provided by systemd: systemd-localed. It provides
the org.freedesktop.locale1 D-Bus service, which does exactly what we
want.
Signed-off-by: default avatarPhilip Withnall <philip.withnall@collabora.co.uk>
Reviewed-by: default avatarMathieu Duponchelle <mathieu.duponchelle@collabora.co.uk>
Differential Revision: https://phabricator.apertis.org/D4032
parent b1fde290
......@@ -613,39 +613,56 @@ Other UI elements that take locale-dependent decisions (in the diagram,
so they can change their UI (update strings, change icons, change text
orientation, etc.).
If the UI element that changes the current locale and the UI elements
that have to be updated don't reside in the same operating system
process, `LocaleManager` could be a D-Bus service whose API would include
the capability to set and get the current locale and be notified of
changes.
Since systemd version 30, the [systemd-localed service][systemd-localed] has
been provided as a standard D-Bus API (`org.freedesktop.locale1`) for managing
the system’s locale, including being notified when it is changed, getting its
current value, and setting a new value. We suggest that it is used as the
`LocaleManager` implementation from the diagram.
These snippets show how such a solution could be implemented (for the
single process variant):
It is provided as a D-Bus API only, so a set of wrapper functions should be
written as a convenience for application developers.
systemd-localed uses [polkit] to authorise changes to the system locale, so
vendors would need to write a policy which determines which applications are
permitted to change the system locale, and which are allowed to query it. The
default should be that only the system preferences application is allowed to
change the locale; and all applications are allowed to query it (and be
notified of changes to the locale).
These snippets show how systemd-localed could be used by an application
(omitting asynchronous calls for simplicity):
``` c
/* This code belongs to the UI for changing the language, for simplicity we assume that there's a button for each language */
/* This code belongs to the UI for changing the language, for simplicity we
* assume that there's a button for each language. */
static gboolean
german_button_event_cb (ClutterActor *actor,
ClutterEvent *event,
gpointer user_data)
{
ExampleSettingsManager *settings_manager = example_settings_manager_get ();
example_settings_manager_set_language (settings_manager, "de");
ExampleBluetoothSettingsDialog *self;
self = EXAMPLE_BLUETOOTH_SETTINGS_DIALOG (user_data);
example_locale_manager_set_locale (self->locale_manager, "de", TRUE);
}
/* This code belongs to UI that needs to change according to the language */
/* This code belongs to UI that needs to change according to the language; the
* UI stores a reference to the ExampleLocaleManager. */
static void
example_bluetooth_settings_dialog_init (ExampleBluetoothSettingsDialog *self)
{
ExampleSettingsManager *settings_manager = example_settings_manager_get ();
g_signal_connect (G_OBJECT (settings_manager), "language-changed", _language_changed_cb, self);
self->locale_manager = example_locale_manager_get ();
g_signal_connect (G_OBJECT (self->locale_manager), "notify::locale",
(GCallback) _notify_locale_cb, self);
_retranslate_ui (self);
}
static void
_language_changed_cb (ExampleSettingsManager *settings_manager,
ExampleBluetoothSettingsDialog *self)
_notify_locale_cb (GObject *obj,
GParamSpec *pspec,
gpointer user_data)
{
ExampleBluetoothSettingsDialog *self;
self = EXAMPLE_BLUETOOTH_SETTINGS_DIALOG (user_data);
_retranslate_ui (self);
}
......@@ -795,3 +812,7 @@ This graph illustrates their work-flow:
[gnome-translation-contribute]: https://live.gnome.org/TranslationProject/ContributeTranslations
[Poedit]: http://www.poedit.net/
[systemd-localed]: https://www.freedesktop.org/wiki/Software/systemd/localed/
[polkit]: https://www.freedesktop.org/wiki/Software/polkit/
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