Installing The Aurelia-I18N Plugin in a CLI App
The new hotness with Aurelia is the brand new CLI Tool. It helps you to create a new project easily by just asking you a few questions and on you go. Since I saw this request few times, here is a short intro in how to install the Aurelia-I18N plugin in your newly created CLI Application.
First you want to install the plugin via npm:
npm install aurelia-i18n
Since Aurelia-I18N is backed by i18next, you should install it and a backend plugin of your choice. As an example we’re going to leverage the i18next-xhr-backend:
npm install i18next i18next-xhr-backend
After that we need to tell our CLI App about the new dependencies. To do so we’re going to open the file aurelia_project/aurelia.json and scroll down to section named dependencies. In there add the following three entries:
1 | { |
Great, now following the official Aurelia-I18N Guide we create a folder in the root of your app named locales.
You have to put the folder into the root (on same level as src) as this is the hosted root of your app
In there add subfolders for each language you’d like to support, eg en and de for English and German language.
Inside of each of those folders create a file named translation.json with your translation keys and values. Follow the official guide for detailed info.
Last but not least it’s time to wire up the plugin inside your app. Therefore go to your src/main.js file and configure it as follows.
1 | /**********************************************/ |
Now you should be all set to start using the features of Aurelia-I18N inside your app.
As always, I’m happy about reading your comments below
photo credit: Gerd Altmann: Kontinente Flaggen Silhouetten via Pixabay (license)