[systemd-commits] 3 commits - Makefile.am src/locale

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Fri Feb 6 06:13:58 PST 2015


 Makefile.am                      |    7 +--
 src/locale/language-fallback-map |    6 +++
 src/locale/localed.c             |   76 ++++++++++++++++++++++++++++++++++-----
 3 files changed, 76 insertions(+), 13 deletions(-)

New commits:
commit 4e829d218cb2ba7e50616945007081f4c7fe0e29
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sat Jan 31 14:11:23 2015 -0500

    localed: add LANGUAGE= fallback when LANG= is specified
    
    For the entries listed in the first column of language-fallback-map,
    the entry from the second column will be used for LANGUAGE=, if
    LANGUAGE= is not explicitly specified.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=624158

diff --git a/Makefile.am b/Makefile.am
index 12116c5..d289914 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -190,6 +190,7 @@ AM_CPPFLAGS = \
 	-DSYSTEM_SHUTDOWN_PATH=\"$(systemshutdowndir)\" \
 	-DSYSTEM_SLEEP_PATH=\"$(systemsleepdir)\" \
 	-DSYSTEMD_KBD_MODEL_MAP=\"$(pkgdatadir)/kbd-model-map\" \
+	-DSYSTEMD_LANGUAGE_FALLBACK_MAP=\"$(pkgdatadir)/language-fallback-map\" \
 	-DX_SERVER=\"$(bindir)/X\" \
 	-DUDEVLIBEXECDIR=\"$(udevlibexecdir)\" \
 	-DPOLKIT_AGENT_BINARY_PATH=\"$(bindir)/pkttyagent\" \
@@ -4990,7 +4991,8 @@ BUSNAMES_TARGET_WANTS += \
 	org.freedesktop.locale1.busname
 
 dist_pkgdata_DATA += \
-	src/locale/kbd-model-map
+	src/locale/kbd-model-map \
+	src/locale/language-fallback-map
 
 localectl_SOURCES = \
 	src/locale/localectl.c
diff --git a/src/locale/localed.c b/src/locale/localed.c
index ed763c3..d1c90d6 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -512,7 +512,9 @@ static const char* strnulldash(const char *s) {
         return isempty(s) || streq(s, "-") ? NULL : s;
 }
 
-static int read_next_mapping(FILE *f, unsigned *n, char ***a) {
+static int read_next_mapping(const char* filename,
+                             unsigned min_fields, unsigned max_fields,
+                             FILE *f, unsigned *n, char ***a) {
         assert(f);
         assert(n);
         assert(a);
@@ -521,6 +523,7 @@ static int read_next_mapping(FILE *f, unsigned *n, char ***a) {
                 char line[LINE_MAX];
                 char *l, **b;
                 int r;
+                size_t length;
 
                 errno = 0;
                 if (!fgets(line, sizeof(line), f)) {
@@ -541,8 +544,9 @@ static int read_next_mapping(FILE *f, unsigned *n, char ***a) {
                 if (r < 0)
                         return r;
 
-                if (strv_length(b) < 5) {
-                        log_error("Invalid line "SYSTEMD_KBD_MODEL_MAP":%u, ignoring.", *n);
+                length = strv_length(b);
+                if (length < min_fields || length > max_fields) {
+                        log_error("Invalid line %s:%u, ignoring.", filename, *n);
                         strv_free(b);
                         continue;
 
@@ -579,7 +583,7 @@ static int vconsole_convert_to_x11(Context *c, sd_bus *bus) {
                         _cleanup_strv_free_ char **a = NULL;
                         int r;
 
-                        r = read_next_mapping(f, &n, &a);
+                        r = read_next_mapping(SYSTEMD_KBD_MODEL_MAP, 5, UINT_MAX, f, &n, &a);
                         if (r < 0)
                                 return r;
                         if (r == 0)
@@ -677,7 +681,7 @@ static int find_legacy_keymap(Context *c, char **new_keymap) {
                 _cleanup_strv_free_ char **a = NULL;
                 unsigned matching = 0;
 
-                r = read_next_mapping(f, &n, &a);
+                r = read_next_mapping(SYSTEMD_KBD_MODEL_MAP, 5, UINT_MAX, f, &n, &a);
                 if (r < 0)
                         return r;
                 if (r == 0)
@@ -752,6 +756,35 @@ static int find_legacy_keymap(Context *c, char **new_keymap) {
         return 0;
 }
 
+static int find_language_fallback(const char *lang, char **language) {
+        _cleanup_fclose_ FILE *f = NULL;
+        unsigned n = 0;
+
+        assert(language);
+
+        f = fopen(SYSTEMD_LANGUAGE_FALLBACK_MAP, "re");
+        if (!f)
+                return -errno;
+
+        for (;;) {
+                _cleanup_strv_free_ char **a = NULL;
+                int r;
+
+                r = read_next_mapping(SYSTEMD_LANGUAGE_FALLBACK_MAP, 2, 2, f, &n, &a);
+                if (r <= 0)
+                        return r;
+
+                if (streq(lang, a[0])) {
+                        assert(strv_length(a) == 2);
+                        *language = a[1];
+                        a[1] = NULL;
+                        return 1;
+                }
+        }
+
+        assert_not_reached("should not be here");
+}
+
 static int x11_convert_to_vconsole(Context *c, sd_bus *bus) {
         bool modified = false;
         int r;
@@ -841,9 +874,10 @@ static int method_set_locale(sd_bus *bus, sd_bus_message *m, void *userdata, sd_
         Context *c = userdata;
         _cleanup_strv_free_ char **l = NULL;
         char **i;
+        const char *lang = NULL;
         int interactive;
         bool modified = false;
-        bool passed[_LOCALE_MAX] = {};
+        bool have[_LOCALE_MAX] = {};
         int p;
         int r;
 
@@ -867,7 +901,10 @@ static int method_set_locale(sd_bus *bus, sd_bus_message *m, void *userdata, sd_
                             (*i)[k] == '=' &&
                             locale_is_valid((*i) + k + 1)) {
                                 valid = true;
-                                passed[p] = true;
+                                have[p] = true;
+
+                                if (p == LOCALE_LANG)
+                                        lang = (*i) + k + 1;
 
                                 if (!streq_ptr(*i + k + 1, c->locale[p]))
                                         modified = true;
@@ -880,10 +917,31 @@ static int method_set_locale(sd_bus *bus, sd_bus_message *m, void *userdata, sd_
                         return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid Locale data.");
         }
 
+        /* If LANG was specified, but not LANGUAGE, check if we should
+         * set it based on the language fallback table. */
+        if (have[LOCALE_LANG] && !have[LOCALE_LANGUAGE]) {
+                _cleanup_free_ char *language = NULL;
+
+                assert(lang);
+
+                (void) find_language_fallback(lang, &language);
+                if (language) {
+                        log_debug("Converted LANG=%s to LANGUAGE=%s", lang, language);
+                        if (!streq_ptr(language, c->locale[LOCALE_LANGUAGE])) {
+                                r = strv_extendf(&l, "LANGUAGE=%s", language);
+                                if (r < 0)
+                                        return r;
+
+                                have[LOCALE_LANGUAGE] = true;
+                                modified = true;
+                        }
+                }
+        }
+
         /* Check whether a variable is unset */
         if (!modified)
                 for (p = 0; p < _LOCALE_MAX; p++)
-                        if (!isempty(c->locale[p]) && !passed[p]) {
+                        if (!isempty(c->locale[p]) && !have[p]) {
                                 modified = true;
                                 break;
                         }
@@ -911,7 +969,7 @@ static int method_set_locale(sd_bus *bus, sd_bus_message *m, void *userdata, sd_
                         }
 
                 for (p = 0; p < _LOCALE_MAX; p++) {
-                        if (passed[p])
+                        if (have[p])
                                 continue;
 
                         free_and_replace(&c->locale[p], NULL);

commit 757b23a6cd15f4b5fdcc3ea99754b7173aff0309
Author: Naveen Kumar <nkumar at redhat.com>
Date:   Sat Jan 31 12:50:49 2015 -0500

    Add language fallback map
    
    This map will be used to provide a fallback for translations.
    For example, a Niederdeutsch (nds) speaker prefers to fall back to
    German (de) translations rather then the English (C) ones.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=624158#c9

diff --git a/src/locale/language-fallback-map b/src/locale/language-fallback-map
new file mode 100644
index 0000000..8b7532f
--- /dev/null
+++ b/src/locale/language-fallback-map
@@ -0,0 +1,6 @@
+en_AU en_AU:en_GB
+en_IE en_IE:en_GB
+en_NZ en_NZ:en_GB
+en_ZA en_ZA:en_GB
+mai_IN mai:hi
+nds_DE nds:de

commit a08d90d6b3eaafa5a8305f601f16cd85480b82c3
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Fri Feb 6 09:12:27 2015 -0500

    build-sys: remove reference to long gone file
    
    Interesting that automake doesn't complain about this at all.
    That file was removed in 3fb97a58fa3f233.

diff --git a/Makefile.am b/Makefile.am
index 53ad568..12116c5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4992,9 +4992,6 @@ BUSNAMES_TARGET_WANTS += \
 dist_pkgdata_DATA += \
 	src/locale/kbd-model-map
 
-dist_noinst_SCRIPT = \
-	src/locale/generate-kbd-model-map
-
 localectl_SOURCES = \
 	src/locale/localectl.c
 



More information about the systemd-commits mailing list