[glib/mcatanzaro/l10n-time] gsettingsschema: fix l10n=time attribute




commit 908e9be606fae23d90ded46041dcf0f0b346e49c
Author: Michael Catanzaro <mcatanzaro redhat com>
Date:   Fri Jan 7 19:14:46 2022 -0600

    gsettingsschema: fix l10n=time attribute
    
    It's supposed to be possible to translate settings values using LC_TIME
    rather than LC_MESSAGES to determine which translation to use, but
    Sebastian Keller noticed that it's not working properly. I've
    implemented his proposed solution, which is to actually temporarily
    change LC_MESSAGES to match LC_TIME for just as long as necessary to
    force gettext to use the desired message catalog.
    
    Fixes #2575

 gio/gsettingsschema.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
index ef4ec1799..65a363111 100644
--- a/gio/gsettingsschema.c
+++ b/gio/gsettingsschema.c
@@ -1410,9 +1410,12 @@ g_settings_schema_key_range_fixup (GSettingsSchemaKey *key,
 GVariant *
 g_settings_schema_key_get_translated_default (GSettingsSchemaKey *key)
 {
-  const gchar *translated;
+  const gchar *translated = NULL;
   GError *error = NULL;
   const gchar *domain;
+  const gchar *lc_time;
+  locale_t old_locale;
+  locale_t locale;
   GVariant *value;
 
   domain = g_settings_schema_get_gettext_domain (key->schema);
@@ -1421,9 +1424,25 @@ g_settings_schema_key_get_translated_default (GSettingsSchemaKey *key)
     /* translation not requested for this key */
     return NULL;
 
+#ifdef HAVE_USELOCALE
   if (key->lc_char == 't')
-    translated = g_dcgettext (domain, key->unparsed, LC_TIME);
-  else
+    {
+      lc_time = setlocale (LC_TIME, NULL);
+      if (lc_time)
+        {
+          locale = newlocale (LC_MESSAGES_MASK, lc_time, (locale_t) 0);
+          if (locale != (locale_t) 0)
+            {
+              old_locale = uselocale (locale);
+              translated = g_dgettext (domain, key->unparsed);
+              uselocale (old_locale);
+              freelocale (locale);
+            }
+        }
+    }
+#endif
+
+  if (translated == NULL)
     translated = g_dgettext (domain, key->unparsed);
 
   if (translated == key->unparsed)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]