Variables - Nemo64/meteor-translator GitHub Wiki

Defining placeholders

Sometimes parts can't be translated because they are dynamic. For this case there are placeholders.

greeting: "Hello {username}!"
long_time_notice: "It has been {days} days!"

With introduction of a syntax, there also has to be a way to escape it. In this case writing inside single quotes ' will pass everything though. Some '{braces}' will therefor output Some {braces}, even if the variable braces does exist. Now if you need a literal single quote you just pass 2 quotes ''. So I''d recommend knowing that if you write in English.

Passing variables

You can simply pass information to the get method.

FrontLang.get('greeting', { username: user.name });
FrontLang.get('long_time_notice', { days: user.daysSinceLogin() });

The template helper create with createHelper() is also capable of variables.

<p>{{trans 'greeting' username=user.name}}<p>
<p>{{trans 'greeting' username="Mustermann"}}<p>

Under the hood

As already described in [Writing Language Files](Writing Language Files) there is some pre-processing going on. The client side of this script does not get any JavaScript dedicated to parse the translations. Instead variables will be parsed on the server and create an array which will look like this: ["Hello ",{name:"username"},"!"]. Not only makes it the client implementation very fast, it will also tell you syntax errors during compilation and not during run-time, making you application a little more stable.