Skip to content

Instantly share code, notes, and snippets.

@rxaviers
Last active August 29, 2015 14:07
Show Gist options
  • Save rxaviers/ec8443f489f1d8d0d454 to your computer and use it in GitHub Desktop.
Save rxaviers/ec8443f489f1d8d0d454 to your computer and use it in GitHub Desktop.
SlexAxton/messageformat.js vs. plural functions

Running test.js fails with

undefined:4
  return a(x);
         ^
ReferenceError: a is not defined
    at Object.i18n.lc.fr (eval at <anonymous> (/tmp/node_modules/messageformat/messageformat.js:1428:13), <anonymous>:4:10)
    at Object.i18n.p (eval at <anonymous> (/tmp/node_modules/messageformat/messageformat.js:1428:13), <anonymous>:9:73)
    at eval (eval at <anonymous> (/tmp/node_modules/messageformat/messageformat.js:1428:13), <anonymous>:10:97)
    at Object.<anonymous> (/tmp/mf-test.js:13:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)

If you drop the plural function dependency on the function a() by uncommenting line 8, it works just fine.

one task
var MessageFormat = require("messageformat");
function a() {
return "one";
}
var mf = new MessageFormat("fr", function(x) {
//return "one";
return a(x);
});
var formatter = mf.compile("{count, plural, one{one task} other{# tasks}}");
console.log(formatter({ count: 7 }));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment