Get started with i18next-xhr-backend CDN

MIT licensed

I18next-xhr-backend: library, XHR backend for i18nexts asynchronous translations.

Tags:
  • i18next
  • i18next-backend
  • browser
  • xhr

Stable version

Copied!

How to start using i18next-xhr-backend CDN


<!DOCTYPE html>
<html>
<head>
  <script src="https://unpkg.com/i18next@latest/i18next.min.js"></script>
  <script src="https://cdn.cdnhub.io/i18next-xhr-backend/3.2.2/i18nextXHRBackend.min.js"></script>
  <script>
    const i18n = new I18N({
      backend: {
        load: function (locales, done) {
          this.options.backend.xhr(this, 'en', () => {
            this.options.backend.xhr(this, locales[0], done);
          });
        }
      },
      init: () => {},
      lng: 'en',
      resources: {
        en: {
          greeting: 'Hello, {name}!'
        },
        fr: {
          greeting: 'Bonjour, {name}!'
        }
      }
    });

    i18n.init().then(() => {
      const name = 'John';
      const translation = i18n.t('greeting', { name });
      console.log(translation); // Output: 'Hello, John!'
    });
  </script>
</head>
<body></body>
</html>
Copied!
Copied!

All versions