Translating Meteor apps: UI, user generated content and emails
So one of our meteor apps is fully translated, including all ui, notifications and emails being sent to the clients. We’ve made heavy use of tap-i18n to achieve this, along with meteorhacks:ssr to render dynamic blaze emailtemplates on the backend.
tap-i18n makes it incredibly easy to translate ui using labels. We add translation files in an i18n folder in the root of the project, as simple json files:
Inside the blaze component, we then render the label using the tap-i18n helper with an _ like so:
All thats left now, is configuring which language should be loaded in the client. As documented in the tapi18n documentation, this can be done in the following way while bootstrapping the application:
To render translated emails and send them to users, we create separate emailtemplates with a predictable filename, e.g. reset_password.en.html and reset_password.nl.html with contents being translated versions of the same email, including placeholders:
Before we can use the meteorhacks:ssr module to render a template, we have to precompile the html template and assign it to a key that we can use later. We indexed all of the emails and locales in some variables and loop through these to pre-compile all of the templates:
When configuring the emails of the accounts package, we use the meteorhacks:ssr module to render the correct template with a data object containing the variable fields: