i18next / i18next-http-backend

i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.
MIT License
454 stars 71 forks source link

Inconsistency between how i18next-http-backend and passing resources directly to init works #26

Closed mayteio closed 4 years ago

mayteio commented 4 years ago

🐛 Bug Report

Given the json file:

{
  "ns": {
     "example": "Example"
  }
}

You can access example via t like so: t("ns:example") by passing in resources option to init.

When using i18next-http-backend to load the resource, i.e. loadPath: "/translations/{{lng}}.json", it seems the namespace is lost and you must access it via dotty notation t("ns.example").

To Reproduce

codesandbox

Expected behavior

Accessing keys should be consistent between the two packages.

Your Environment

Chrome latest "i18next": "^19.6.3", "i18next-http-backend": "^1.0.18", MacOS

jamuhl commented 4 years ago

https://www.i18next.com/translation-function/essentials#accessing-keys-in-different-namespaces

That is not an inconsistency - when adding resources on init you will have to additionally give i18next the namespace.

Loading: translation.json

{
     "example": "Example"
}

// it nows the namespace and loads one by one

Passing resources

{
  "translation": {
     "example": "Example"
  }
}

// it does not know the namespace upfront and gets passed in multiple

mayteio commented 4 years ago

Got it, so I have to pass in the 'translation' namespace explicitly when passing resources into init. Cheers.

jamuhl commented 4 years ago

https://www.i18next.com/how-to/add-or-load-translations might help too

mayteio commented 4 years ago

Fantastic, thanks mate.