Skip to content

Instantly share code, notes, and snippets.

@StreetStrider
Created October 30, 2014 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StreetStrider/3ad0105793f877f3415d to your computer and use it in GitHub Desktop.
Save StreetStrider/3ad0105793f877f3415d to your computer and use it in GitHub Desktop.
locale object
function Locale ()
{
var locale = Object.create(Locale.prototype);
locale.ns = {};
return locale;
}
Locale.prototype.register = function (localePlugin, pseudo)
{
var name = localePlugin.name;
if (pseudo)
{
name = pseudo;
}
this.ns[name] = localePlugin;
return this;
}
Locale.prototype.use = function (name)
{
if (name in this.ns)
{
return this.ns[name];
}
else
{
throw new TypeError('wrong_locale_name');
}
}
function Plugin ()
{
var plugin = {};
plugin.name = 'ru';
plugin.collate = function () { /* ... */};
plugin.plural = function (n) { /* ... */};
plugin.monetary = function (money) { /* ... */};
return plugin;
}
var locale = Locale()
.register(new Plugin)
.register(new Plugin, 'ru-doctor')
//.register(new AnotherPlugin)
//.register(new AnotherPlugin) ...
locale.use('ru').monetary(2);
var collate = locale.use('ru').collate;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment