From 004a7c9d5447de29972af560765791066c198226 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 5 Apr 2021 18:40:23 +0200 Subject: implement convenience function to extract i18n values from JSON (for #6749) --- src/include/taler_json_lib.h | 39 +++++++++++++++++++++++++++++++++++++++ src/json/json_helper.c | 10 ++++++++++ 2 files changed, 49 insertions(+) (limited to 'src') diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h index a1e4d8830..f61e2c0fd 100644 --- a/src/include/taler_json_lib.h +++ b/src/include/taler_json_lib.h @@ -141,6 +141,45 @@ TALER_JSON_spec_denomination_signature (const char *field, struct TALER_DenominationSignature *sig); +/** + * The expected field stores a possibly internationalized string. + * Internationalization means that there is another field "$name_i18n" + * which is an object where the keys are languages. If this is + * present, and if @a language_pattern is non-NULL, this function + * should return the best match from @a language pattern from the + * "_i18n" field. If no language matches, the normal field under + * @a name is to be returned. + * + * The @a language_pattern is given using the format from + * https://tools.ietf.org/html/rfc7231#section-5.3.1 + * so that #TALER_language_matches() can be used. + * + * @param name name of the JSON field + * @param language_pattern language pattern to use to find best match, possibly NULL + * @param[out] strptr where to store a pointer to the field with the best variant + */ +struct GNUNET_JSON_Specification +TALER_JSON_spec_i18n_string (const char *name, + const char *language_pattern, + const char **strptr); + + +/** + * The expected field stores a possibly internationalized string. + * Internationalization means that there is another field "$name_i18n" which + * is an object where the keys are languages. If this is present, this + * function should return the best match based on the locale from the "_i18n" + * field. If no language matches, the normal field under @a name is to be + * returned. + * + * @param name name of the JSON field + * @param[out] strptr where to store a pointer to the field with the best variant + */ +struct GNUNET_JSON_Specification +TALER_JSON_spec_i18n_str (const char *name, + const char **strptr); + + /** * Hash a JSON for binary signing. * diff --git a/src/json/json_helper.c b/src/json/json_helper.c index f30705883..2a9b01a75 100644 --- a/src/json/json_helper.c +++ b/src/json/json_helper.c @@ -493,4 +493,14 @@ TALER_JSON_spec_i18n_string (const char *name, } +struct GNUNET_JSON_Specification +TALER_JSON_spec_i18n_str (const char *name, + const char **strptr) +{ + return TALER_JSON_spec_i18n_string (name, + getenv ("LANG"), + strptr); +} + + /* end of json/json_helper.c */ -- cgit v1.2.3