martinandert / counterpart

A translation and localization library for Node.js and the browser.
MIT License
242 stars 25 forks source link

`translate` as an instance #8

Closed callum closed 10 years ago

callum commented 10 years ago

I'm working on a plugin where it will be possible to have multiple instances on a page using different locales. I couldn't find a way to do it, but I'm proposing something like this:

var translate = new Counterpart();

translate.setLocale('en');
translate.registerTranslations('en', {foo: 'bar'});

translate('foo'); // bar

You can then set the locale per instance, instead of globally.