Skip to content

Instantly share code, notes, and snippets.

@ryaz
Last active August 29, 2015 13:57
Show Gist options
  • Save ryaz/9530376 to your computer and use it in GitHub Desktop.
Save ryaz/9530376 to your computer and use it in GitHub Desktop.
api for kostia/jquery.li18n.js

API

$.li18n.currentLocale = locale

Set the current locale.

Default is 'en'.

$.li18n.currentLocale = 'de';

$.li18n.fallbackLocale = locale

Set the fallback locale.

Default is null.

$.li18n.fallbackLocale = 'en';

$.li18n.translations = translations

Set the translations.

Default is {}.

$.li18n.translations = {en: {greeing: 'Hello %{{name}}'}};

$.li18n.translate(key, interpolationOptions)

Translates the given key using interpolation options.

Params:

  • key - translation lookup key (String).
  • interpolationOptions - options for translations with interpolation (Object).

Returns:

  • translation (String) if found.
  • error message (String) if translation not found and $.li18n.onTranslationMissing is set to 'message'.
  • value from $.li18n.onTranslationMissing if translation not found and $.li18n.onTranslationMissing is set to a function.
  • throws an error if translation is not found and $.li18n.onTranslationMissing is not set.
$.li18n.translate('greeting', {name: 'Alice'});
// => 'Hello Alice!'

$.li18n._localize = function

Set the localize function.

Default is null.

$.li18n._localize = function(object, format, currentLocale) {
  // 'object' is the object to be localized, e.g. a Date.
  // 'format' is the localization format for the given object.
  // 'currentLocale' is the current locale...
  return moment(object).lang(currentLocale).format(format);
};

$.li18n.localize(object, options)

Localize the given object using options.

$.li18n.localize(new Date('1971.01.01')); // 'Friday, January 1 1971 12:00 AM'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment