Created
October 30, 2014 15:33
-
-
Save StreetStrider/3ad0105793f877f3415d to your computer and use it in GitHub Desktop.
locale object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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