aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-04-05 18:40:23 +0200
committerChristian Grothoff <christian@grothoff.org>2021-04-05 18:40:23 +0200
commit004a7c9d5447de29972af560765791066c198226 (patch)
treed9f6f05b7fcc8122ee6561cc083090865766fe85
parent99fff4f98fd02dc14b4c18ba9fb05816979f0e5f (diff)
implement convenience function to extract i18n values from JSON (for #6749)
-rw-r--r--src/include/taler_json_lib.h39
-rw-r--r--src/json/json_helper.c10
2 files changed, 49 insertions, 0 deletions
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
@@ -142,6 +142,45 @@ TALER_JSON_spec_denomination_signature (const char *field,
/**
+ * 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.
*
* See https://tools.ietf.org/html/draft-rundgren-json-canonicalization-scheme-15
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 */