Get started with jquery.i18n CDN

(MIT OR GPL-2.0) licensed

JQuery.i18n: Popular library for jQuery app internationalization/localization.

Tags:
  • jquery
  • i18n
  • internationalization
  • l10n
  • localization

Stable version

Copied!

How to start using jquery.i18n CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with jquery.i18n CDN - cdnhub.io</title>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <script src="https://cdn.cdnhub.io/jquery.i18n/1.0.9/jquery.i18n.min.js"></script>
  <script>
    $(document).ready(function() {
      // Initialize i18n
      $.i18n.init({
        fallbackLng: 'en',
        debug: false,
        resGetText: true,
        resLoad: function(name, callback) {
          jQuery.get(name, function(data) {
            callback(data);
          });
        }
      });

      // Define messages
      $.i18n.add('en', {
        greeting: 'Hello, {0}!',
        farewell: 'Goodbye, {0}.'
      });

      // Use messages
      $.i18n.set('en');
      $('#greeting').text($.i18n('greeting', 'John'));
      $('#farewell').text($.i18n('farewell', 'John'));

      // Add a new language
      $.i18n.add('es', {
        greeting: 'Hola, {0}!',
        farewell: 'Adiós, {0}.'
      });

      // Switch language
      $('#language').click(function() {
        $.i18n.set('es');
        $('#greeting').text($.i18n('greeting', 'John'));
        $('#farewell').text($.i18n('farewell', 'John'));
      });
    });
  </script>
  <style>
    #greeting, #farewell {
      margin: 10px;
    }
  </style>
</head>
<body>
  <button id="language">Switch to Spanish</button>
  <div id="greeting"></div>
  <div id="farewell"></div>
</body>
</html>
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!

All versions