gadicc/meteor-messageformat

Extractor having trouble with parameters in javascript

monitz87 opened this issue · 2 comments

Hi,

I have a line like this in my javascript code:

mf('error_field_invalid', { field: 'phone' }, 'Invalid {field}')

I then use it again as such:

mf('error_field_invalid', { field: 'email' })

When I do, the meteor log throws the following error:

warn: [msgfmt:extracts] { error_field_invalid: "email" } in imports/ui/pages/accounts/profile.js:375 replaces DUP_KEY

And if I check the database, the mfString with key 'error_field_invalid' has 'email' as its 'text' attribute. I'm assuming that the regular expression tasked with parsing the javascript files is having trouble recognizing parameters.

Cheers

Indeed, the regexp sees the string literal and assumes it's a text value instead of a parameter. My workaround was to assign the parameter object previously like so:

const fieldParam = { field: 'phone' };
mf('error_field_invalid', fieldParam, 'Invalid {field}');

That's annoying :) Since this would be hard to fix in regexp, maybe this will help.

v2.0.0-preview.24 (2017-05-04)

Added

  • Allow mf('key', 'text', params) in addition to the regular
    mf('key', params, 'text') Previously, mf('key', 'text') was accepted
    too, but there was no way to provide params in this ordering. Now if
    the second argument is a String, the second and third arguments are swapped.
    (#253).