Re: [systemd-devel] [RFC PATCH 2/2] localed: add LANGUAGE= fallback when LANG= is specified

2015-02-06 Thread Zbigniew Jędrzejewski-Szmek
On Mon, Feb 02, 2015 at 03:10:37PM +0100, Zbigniew Jędrzejewski-Szmek wrote:
 On Mon, Feb 02, 2015 at 11:56:39AM +0100, Martin Pitt wrote:
  Zbigniew Jędrzejewski-Szmek [2015-01-31 20:20 +0100]:
   I think the implementation is fine, since it is rather trivial, but I'm
   less certain about the implications of setting LANGUAGE in addtion to
   LANG.
  
  That's totally fine -- it's precisely what $LANGUAGE is meant for. One
  must be aware that it is a GNU extension, i. e. software like
  thunderbird won't respect it and thus just use $LANG (in which case
  you are no worse than now). But pretty much all native Linux sofware
  does and thus will behave as intended.  We've used this schema in
  Ubuntu since around 2005 [1].
 Thanks. Incomplete support sounds fine.
 
  Now, I wish such a fallback list would be in upstream glibc so that
  OSes, systemd etc. wouldn't have to repeat and maintain it; but while
  [1] looks quite complex, it hasn't really changed in years.
 Looking at the list, I'm wondering about using en_GB as the fallback for
 most locales. I guess that for European countries it makes some sense, but
 for Japanese, Kazakh, and many other places, I'd expect en_US to be
 better last choice. Especially that en_US translation coverage is more
 complete than en_GB.
 
 Also, I'd expect a fallback to Russian before English for Kazakh, it's
 their second official language.
 
  If this patch goes in, I'm happy to augment the list according to [1]
  and then move our language-selector to use that instead, to reduce
  duplication.
 Great.
I pushed the patches now.

It would be great if you could add more mappings.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [RFC PATCH 2/2] localed: add LANGUAGE= fallback?when LANG= is specified

2015-02-02 Thread Zbigniew Jędrzejewski-Szmek
On Mon, Feb 02, 2015 at 07:11:04AM +, Jan Janssen wrote:
 Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl writes:
 
  I think the implementation is fine, since it is rather trivial, but I'm
  less certain about the implications of setting LANGUAGE in addtion to
  LANG.
  
  Zbyszek
 
 Isn't this something that should be in glibc's lang/locale handling code?

They probably could in principle, but those settings are somewhat arbitrary and
at a higher level than libc usually operates. We are already taking care of
configuration of a lot of related stuff, so this seems a natural extension.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [RFC PATCH 2/2] localed: add LANGUAGE= fallback when LANG= is specified

2015-02-02 Thread Zbigniew Jędrzejewski-Szmek
On Mon, Feb 02, 2015 at 11:56:39AM +0100, Martin Pitt wrote:
 Zbigniew Jędrzejewski-Szmek [2015-01-31 20:20 +0100]:
  I think the implementation is fine, since it is rather trivial, but I'm
  less certain about the implications of setting LANGUAGE in addtion to
  LANG.
 
 That's totally fine -- it's precisely what $LANGUAGE is meant for. One
 must be aware that it is a GNU extension, i. e. software like
 thunderbird won't respect it and thus just use $LANG (in which case
 you are no worse than now). But pretty much all native Linux sofware
 does and thus will behave as intended.  We've used this schema in
 Ubuntu since around 2005 [1].
Thanks. Incomplete support sounds fine.

 Now, I wish such a fallback list would be in upstream glibc so that
 OSes, systemd etc. wouldn't have to repeat and maintain it; but while
 [1] looks quite complex, it hasn't really changed in years.
Looking at the list, I'm wondering about using en_GB as the fallback for
most locales. I guess that for European countries it makes some sense, but
for Japanese, Kazakh, and many other places, I'd expect en_US to be
better last choice. Especially that en_US translation coverage is more
complete than en_GB.

Also, I'd expect a fallback to Russian before English for Kazakh, it's
their second official language.

 If this patch goes in, I'm happy to augment the list according to [1]
 and then move our language-selector to use that instead, to reduce
 duplication.
Great.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [RFC PATCH 2/2] localed: add LANGUAGE= fallback when LANG= is specified

2015-02-02 Thread Martin Pitt
Zbigniew Jędrzejewski-Szmek [2015-01-31 20:20 +0100]:
 I think the implementation is fine, since it is rather trivial, but I'm
 less certain about the implications of setting LANGUAGE in addtion to
 LANG.

That's totally fine -- it's precisely what $LANGUAGE is meant for. One
must be aware that it is a GNU extension, i. e. software like
thunderbird won't respect it and thus just use $LANG (in which case
you are no worse than now). But pretty much all native Linux sofware
does and thus will behave as intended.  We've used this schema in
Ubuntu since around 2005 [1].

Now, I wish such a fallback list would be in upstream glibc so that
OSes, systemd etc. wouldn't have to repeat and maintain it; but while
[1] looks quite complex, it hasn't really changed in years.

If this patch goes in, I'm happy to augment the list according to [1]
and then move our language-selector to use that instead, to reduce
duplication.

Martin

[1] 
http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/vivid/language-selector/vivid/view/head:/data/languagelist
-- 
Martin Pitt| http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [RFC PATCH 2/2] localed: add LANGUAGE= fallback when LANG= is specified

2015-02-02 Thread Lennart Poettering
On Sat, 31.01.15 20:20, Zbigniew Jędrzejewski-Szmek (zbys...@in.waw.pl) wrote:

 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.

Looks conceptually OK to me, sounds like a useful addition!

Thanks!

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [RFC PATCH 2/2] localed: add LANGUAGE= fallback when LANG= is specified

2015-02-01 Thread Jan Janssen
Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl writes:

 I think the implementation is fine, since it is rather trivial, but I'm
 less certain about the implications of setting LANGUAGE in addtion to
 LANG.
 
 Zbyszek

Isn't this something that should be in glibc's lang/locale handling code?
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [RFC PATCH 2/2] localed: add LANGUAGE= fallback when LANG= is specified

2015-01-31 Thread Zbigniew Jędrzejewski-Szmek
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
---
This fixes a long-standing bug where users of a dialect locale would like
to fallback to a more general one for translations. For example, zh_HK to
zh_CN, etc.

I think the implementation is fine, since it is rather trivial, but I'm
less certain about the implications of setting LANGUAGE in addtion to
LANG.

Zbyszek


 Makefile.am  |  1 +
 src/locale/localed.c | 76 +---
 2 files changed, 68 insertions(+), 9 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index e3ba11c8c0..f359da7154 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\ \
diff --git a/src/locale/localed.c b/src/locale/localed.c
index 529a9abfd6..3a11992f6a 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