SlexAxton/messageformat.js — pull request #51 by eemeli (2014-06-03 20:52:47+00:00)
Title: Stop leaking things outside our own namespace

This sets up a user-definable global variable that contains the translations and their required executable code, so no more single-letter functions are leaked into the global namespace.

For direct use, `compile()` returns a function that's ready to use. If using `precompile()` to generate static code for later evaluation and use, the usage should look something like:
```js
var mf = new MessageFormat('en'),
gn = 'window["' + mf.globalName + '"]',
msg = { 'test': 'Your {N, plural, one{message} other{messages}} go here.',
'friends': 'I have {N, plural, one{one friend} other{# friends}}.' },
output = gn + '=' + mf.functions() + ';\n' + gn + '["msg"]={};\n';
for (var key in msg) {
var fn_str = mf.precompile(mf.parse(msg[key]));
output += gn + '["msg"]["' + key + '"]=' + fn_str + ';\n';
}
...
```

Changelog:
- add `MF.functions()` to return array of functions as a string, for
inclusion in code by `MF.compile()` or `build()` in `bin/messageformat.js`
- add `MF.globalName` (default 'i18n') to define said global variable,
which is also a new 3rd parameter to `MessageFormat()`
- rm `lib/messageformat.include.js` as obsolete
- wrap up locale loading as `MF.loadLocale()`
- update examples to match changes