Translations

In order to set the languages that your app supports you just need to edit the translate module config file at src\/app\/index.constant.js

At the top of the config file is this code.

    locales : [
     {
         translation: 'portugues',
         code : 'pt'
     },
     {
         translation: 'english',
         code : 'en'
     },
     {
         translation: 'turkish',
         code : 'tr'
     },
     {
         translation: 'persian',
         code : 'fa'
     },
     {
         translation: 'german',
         code : 'de'
     }
 ],

This sets out the name and keys of the language that your app will support.

Note - The key you set here will determine the names of the translation files that are loaded. e.g. key: fr will make the app load src\/app\/i18n\/fr.json

Set default language

To change the default language, just change the preferredLocale in src\/app\/index.constant.js to the language of the src\/app\/i18n folder

preferredLocale: 'en',

By default the application detects the application language and located between the values of language array, if not Econtra it uses this primary language

How to translate a page

In order to translate some text in a page just use the translate directive in your HTML.

for example

<h1 translate>Settings</h1>

or

<h1 translate="Settings"></h1>

in Angular Controller, Directive or Service, inject $translate and use $translate.instant('string') for translate in code

.controller('Sample', function($scope, $translate) {
 $scope.title = $translate.instant('Settings');
})

Then edit or create a json translation file in your app\/i18n folder.

So for example to translate to French we would create a new file called fr.json in the app\/i18n folder and add the following json.

{
 "Settings": "Paramètres",
}

You will then see that your Settings text is translated into Paramètres.

Auto translating all template strings

We have built in an auto translater into triangular that sends all the strings in your i18n folders to Yandex to be translated.

It then writes translation files in your chosen language.

First of all to use this you will need to get a Yandex API Key.

Once you have a key edit this file

app\/gulp\/translate.js

At the top of the file you will see this code

// ADD YOUR YANDEX API KEY HERE
// go here for more info
// https://tech.yandex.com/translate/
var YANDEX_API_KEY = '';

edit the YANDEX_API_KEY and add your api key

var YANDEX_API_KEY = '1234567894621695846516546951651981';

Once this is done, open up a terminal and cd to your app directory.

From there you can run the gulp task that will translate the template translation files.

You need to specify 2 lanuages e.g.

$ gulp translate --from en --to fr

The command above will grab all en.json files from all your i18n folders send them to Yandex to be translated into French.

Once this is done the resulting translations will be written to fr.json files in each coresponding i18n folder.


results matching ""

    No results matching ""