i18next / i18next-xhr-backend

[deprecated] can be replaced with i18next-http-backend
https://github.com/i18next/i18next-http-backend
MIT License
253 stars 75 forks source link

Return a default sub object of the custom AJAX payload #345

Open jackblackCH opened 4 years ago

jackblackCH commented 4 years ago

My registered API via loadPath returns all translation keys in a nested "data" object. i.e

{
  "data": {
      "key1": "foo",
      "key2: "bar"
   }
}

This forces me to use "data" like a namespace. i.e `t("data.mykey")". though it is not a namespace, it is just because I am not in control of the translation API.

Is there a way to always return a sub object of the JSON payload?

Lately I would like to use t("key1") instead of multiple t("data.key1") or t("data.key2").

jamuhl commented 4 years ago

Not looked deeper - but I guess you can use the parse option of the backend: https://github.com/i18next/i18next-xhr-backend#backend-options