Search code examples
javascriptreactjsinternationalizationi18nextreact-i18next

react-i18next fallback backend combination issue


I've used "i18next-chained-backend" library to load multiple i18n backend but it seems it does not work as my expectation. I expect that it will load multiple resources from those backends, then when I translate some key, it checks that key on those backends one by one in order.

Currently, I think when the first backend is loaded successfully, it will use that backend and ignore the rest. How can I achieve as my expect? I appreciate any helps, thanks in advance.


Solution

  • Here is my setup to resolve the multiple backends issues:

    For example I have 2 backend called: backend1 (1st priority), backend2.
    On backend1, I create namespace1 then make namespace1 as default namespace.
    On backend2, I create namespace2 then make namespace2 as fallback namespace.
    So in namespace1 (backend1) I have

    {
       "key1": "different Key1"
    }
    

    and in namespace2 (backend2) I have

    {
       "key1": "Key1",
       "key2": "Key2"
    }
    

    So here is the result:
    t("key1") will be "different Key1" --> Because it's found in namespace1 as default (as it's 1st priority)
    t("key2") will be "Key2" --> Because it's not found in namespace1 so it will look at the fallback namespace (namespace2).