implement convenience function to extract i18n values from JSON (for #6749)

This commit is contained in:
Christian Grothoff 2021-04-05 18:40:23 +02:00
parent 99fff4f98f
commit 004a7c9d54
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
2 changed files with 49 additions and 0 deletions

View File

@ -141,6 +141,45 @@ TALER_JSON_spec_denomination_signature (const char *field,
struct TALER_DenominationSignature *sig); 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. * Hash a JSON for binary signing.
* *

View File

@ -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 */ /* end of json/json_helper.c */