meteor-messageformat icon indicating copy to clipboard operation
meteor-messageformat copied to clipboard

Extractor having trouble with parameters in javascript

Open monitz87 opened this issue 7 years ago • 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

monitz87 avatar Mar 10 '17 21:03 monitz87

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}');

monitz87 avatar May 02 '17 22:05 monitz87

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).

gadicc avatar May 04 '17 08:05 gadicc