Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resGetPath doesn't load json file #471

Closed
aonzzung opened this issue Dec 16, 2015 · 4 comments
Closed

resGetPath doesn't load json file #471

aonzzung opened this issue Dec 16, 2015 · 4 comments

Comments

@aonzzung
Copy link

First, this is my first time with i18next and I have no idea how to make it work. (it seems like the documentation http://i18next.com/docs/ is incomplete to me)

Here is my code

window.i18next.init({
    debug : true,
    load: 'all',
    lng: 'en',
    resGetPath : 'locales/__lng__/__ns__.json',
    fallbackLng : false
    /*,
    resources: {
        en: {
          translation: {
            "key": "hello world"
          }
        }
      }*/
}, function() {


  alert(window.i18next.t("key"));

});

It works if I set and use the "resources" variable instead of resGetPath.
But when I purely use resGetPath, I got error "i18next::translator: missingKey en translation key key".

The json file is on "http://localhost:8090/locales/en/translation.json" and it's accessible via web browser.
2015-12-16_17h46_09

Am I missing anything?

@jamuhl
Copy link
Member

jamuhl commented Dec 16, 2015

loading resources via xhr is not in the i18next core:

see http://i18next.com/docs/#add-plugins for adding plugins
see http://i18next.com/docs/ecosystem/ for avaiable plugins

details on needed xhr backend: https://github.com/i18next/i18next-xhr-backend

@aonzzung
Copy link
Author

Ok, I've tried to include the plugin by setting "backend" option but it doesn't work. :(

<script type="text/javascript" src="../vendor/js/i18nextXHRBackend.min.js"></script>
<script type="text/javascript" src="../vendor/js/i18next.min.js"></script>
...
...
<script type="text/javascript">
window.i18next.init({
    debug : true,
    load: 'all',
    lng: 'en',

    resGetPath: 'locales/{{lng}}/{{ns}}.json',
    fallbackLng : "en",
    backend: {
        // path where resources get loaded from
          loadPath: 'locales/{{lng}}/{{ns}}.json',

          // path to post missing resources
          addPath: 'locales/add/{{lng}}/{{ns}}',

          // your backend server supports multiloading
          // /locales/resources.json?lng=de+en&ns=ns1+ns2
          allowMultiLoading: false
    },

}, function() {

  alert(window.i18next.t("key"));

});
</script>

Sorry, I am not a js expert.
How should I do with these ?

import XHR from 'i18next-xhr-backend';

and

i18next.use(XHR)

Thanks for your time

@aonzzung
Copy link
Author

No problem now.

I figured it out to use

.use(window.i18nextXHRBackend)

But I have to look into the code and the documentation doesn't even mention "i18nextXHRBackend" variable.
:(

Thanks

@jamuhl
Copy link
Member

jamuhl commented Dec 16, 2015

will update readme to mention the object appended to window.

@jamuhl jamuhl closed this as completed Dec 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants