omit charset from en_US.UTF-8 env variable when picking i18n strings

This commit is contained in:
Christian Grothoff 2021-04-05 19:27:19 +02:00
parent 004a7c9d54
commit 63c6654c0f
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC

View File

@ -380,7 +380,7 @@ struct I18nContext
/**
* Language pattern to match.
*/
const char *lp;
char *lp;
/**
* Name of the field to match.
@ -466,6 +466,7 @@ i18n_cleaner (void *cls,
{
struct I18nContext *ctx = cls;
GNUNET_free (ctx->lp);
GNUNET_free (ctx);
}
@ -486,7 +487,7 @@ TALER_JSON_spec_i18n_string (const char *name,
.size_ptr = NULL
};
ctx->lp = language_pattern;
ctx->lp = GNUNET_strdup (language_pattern);
ctx->field = name;
*strptr = NULL;
return ret;
@ -497,9 +498,30 @@ struct GNUNET_JSON_Specification
TALER_JSON_spec_i18n_str (const char *name,
const char **strptr)
{
return TALER_JSON_spec_i18n_string (name,
getenv ("LANG"),
const char *lang = getenv ("LANG");
char *dot;
char *l;
struct GNUNET_JSON_Specification ret;
if (NULL != lang)
{
dot = strchr (lang,
'.');
if (NULL == dot)
l = GNUNET_strdup (lang);
else
l = GNUNET_strndup (lang,
dot - lang);
}
else
{
l = NULL;
}
ret = TALER_JSON_spec_i18n_string (name,
l,
strptr);
GNUNET_free (l);
return ret;
}