Skip to content

Latest commit

 

History

History
68 lines (53 loc) · 1.29 KB

load-translation.md

File metadata and controls

68 lines (53 loc) · 1.29 KB

.loadTranslations( json )

Load translation data.

The first dregree keys must be locales. For example:

{
  en: {
    hello: "Hello"
  },
  pt: {
    hello: "Olá"
  }
}

Parameters

json

JSON object of translation data.

Example

Globalize.loadTranslations({
  pt: {
    greetings: {
      hello: "Olá",
      bye: "Tchau"
    }
  }
});

Globalize( "pt" ).translate( "greetings/hello" ); // Olá

It's possible to inherit translations, for example:

Globalize.loadTranslations({
  root: {
    amen: "Amen"
  },
  pt: {
    amen: "Amém"
  }
});

Globalize( "pt-PT" ).translate( "amen" ); // "Amém"
Globalize( "de" ).translate( "amen" ); // "Amen"
Globalize( "en" ).translate( "amen" ); // "Amen"
Globalize( "en-GB" ).translate( "amen" ); // "Amen"
Globalize( "fr" ).translate( "amen" ); // "Amen"

Note that pt-PT, de, en, en-GB, and fr have never been defined. .translate() inherits pt-PT translation from pt (pt-PTpt), and it inherits the other translations from root, eg. en-GBenroot. Yes, root is the last bundle of the parent lookup.

Attention: On browsers, translation inheritance only works if the optional dependency cldr/unresolved is loaded.

<script src="cldr/unresolved.js"></script>