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

(help) How to parse data-18n? #1124

Closed
ancientaccount opened this issue Oct 30, 2018 · 3 comments
Closed

(help) How to parse data-18n? #1124

ancientaccount opened this issue Oct 30, 2018 · 3 comments

Comments

@ancientaccount
Copy link

Hello,

I would like to point out that I am starting with i18next and have been looking for ways to solve my problem but without really understanding or succeeding.

I am currently using i18next (vanilla) in a development environment with webpack (but with the official i18n library, not any loaders/plugins here).
My problem is that i18next does not parse the "data-18n" html tags.
(I tried to try jquery.i18n but I got a lot of error which led me to use i18next vanilla.)

i18next
    .use(i18nextXHRBackend)
    .use(i18nextBrowserLanguageDetector)
    .init({
      fallbackLng: 'fr',
      debug: true,
      backend: {
        loadPath: 'translations/{{lng}}.json',
        crossDomain: true
      }
    }, function(err, t) {
      $(".container").i18n();
    });

    function updateContent() {
      document.getElementById('presentation').innerHTML = i18next.t('nav.presentation');
      document.getElementById('location').innerHTML = i18next.t('nav.location');
      document.getElementById('medias').innerHTML = i18next.t('nav.medias');
    }
    
    $('#fr').click(function() {
      i18next.changeLanguage('fr');
      /* location.reload(); */
    });

    $('#nl').click(function() {
      i18next.changeLanguage('nl');
      /* location.reload(); */
    });
    
    i18next.on('languageChanged', () => {
      updateContent();
    });

Hoping you can tell me more about this problem. :)

@jamuhl
Copy link
Member

jamuhl commented Oct 30, 2018

i18next itself does not care for data-i18n - it is not web only:

choose one of:

@ancientaccount
Copy link
Author

Thank you very much! :) I'm going to open an exit on the repo of the library I'm using.

@jamuhl
Copy link
Member

jamuhl commented Oct 30, 2018

If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project -> there are many ways to help this project 🙏

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