I have React app using react-i18next, the translations are stored in two locations. One set is stored locally to the app in a folder, the rest of the translations come from a remote API.
I am struggling to have both sets loaded into the app. Using the i18next-chained-backend plugin it seems that it only provides fallbacks if the first backend does not load the translations, i cant seem to configure it to load both sets of translations.
What is the best method of including translations from mulitple sources in a React based app?
I was able to load translations from different places without using any dependency. (Only with npm packages 'react-i18next' and 'i18next')
These are the steps I followed:
i18n.js
, set your client-side locale definitions.ns
key in the same file.
Say the namespaces are ['translations', 'bkdynamic']
In the given sandbox, API call is a mock which fetches
sampleTx.json
from yourpublic/
directory. This could be replaced to an actual endpoint which returns a JSON.
i18next.addResourceBundle
API, load these translations for the language you require.
Load the newly fetched translations in namespace
bkdynamic
for the selected language. Note: While doingi18next.addResourceBundle
call, setdeep
param totrue
; so that new translations are extended.
Live sandbox here - https://codesandbox.io/embed/i18next-muliple-files-p565v
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With