meteor-messageformat 
MessageFormat support, the Meteor way.
For iron:router < 1.0.0, use messageformat v0.0.45.
For Meteor < 0.8.0, use messageformat v0.0.26.
Description
Easy reactive use of complicated strings (gender, plural, etc) with insanely easy translation into other languages (through a web UI).
For full info, docs and examples, see the
Meteor MessageFormat home page
(or install/clone the smart package and run mrt
in its website
directory).
Installation
To install, simply run the following command in your project folder:
meteor add gadicohen:messageformat
You will then need to add an initialization setting in your project. E.g. in lib/config.js
add the following:
mfPkg.init('en');
Replace 'en' with the native language of your project, if appropriate. You can also pass a second argument with options; for more details see the online docs.
Usage
Once installed, you can start adding the MessageFormat helper to templates:
<p>This string is translatable</p>
...becomes ...
<p>{{mf 'trans_string' 'This string is translatable'}}</p>
Note: Each translation string must have a unique key. In the above example, trans_string
is the key.
In short, you'll get to use the {{mf}}
helper.
Extracting translation strings
After you have added several translation strings to your templates, you will need to extract those strings for translation. To do so:
sudo npm install -g meteor-messageformat
(once)- To update strings, in your project directory, type
mf_extract
- To see the tralsnation UI, navigate to localhost:3000/translate
Advanced Usage
Much more complex strings are possible, and are useful even if your website is only available in one language, e.g.:
1{{#mf KEY='gender_plural' GENDER=getGender NUM_RESULTS=getNum NUM_CATS=getNum2}} 2{GENDER, select, 3 male {He} 4 female {She} 5 other {They} 6 } found {NUM_RESULTS, plural, 7 =0 {no results} 8 one {1 result} 9 other {# results} 10 } in {NUM_CATS, plural, 11 one {1 category} 12 other {# categories} 13 }. 14 {{/mf}}
Possible outputs:
1He found 2 results in 1 category. 2She found 1 result in 2 categories. 3etc
Besides gender, there is support for offsets too, e.g.:
1You and one other person added this to their profile.
For full info, docs and examples, see the
Meteor MessageFormat home page
(or install/clone the smart package and run mrt
in its website
directory).