gadicc / meteor-messageformat

MessageFormat i18n support for Meteor, with reactive templates
54 stars 22 forks source link

Extractor having trouble with parameters in javascript #253

Open monitz87 opened 7 years ago

monitz87 commented 7 years ago

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 commented 7 years ago

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}');
gadicc commented 7 years ago

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