Reputation: 1955
I am very new to both Angularjs and Ionic Framework. I coming from Microsoft background.
I am trying to make app in 3 languages (English, Arabic and French). As I told you that I am coming from Microsoft background I am thinking in .net way that for multilingual apps translation we use resource file and in our .net code as per language environment. As for example
http://www.codeproject.com/Tips/580043/How-to-make-a-multi-language-application-in-Csharp
Is there any way to do same thing Angularjs or Ionic Framework
Upvotes: 2
Views: 5544
Reputation: 680
I have create a library for translate angular and ionic app.
You can install with bower:
bower install ng-translator --save
or with npm
npm install ng-translator --save
Upvotes: 0
Reputation: 111
Follow the steps here:
Create a sub-folder, for example, 'lang' within www and add js files for each language you want to add to your application. Within individual JavaScript files, create an array variable containing key-value mapping of all translations. For example, in english.js file:
var translations_en = { Title:'My app title', Settings:'Settings' } In bengali.js file: var translations_bng={ Title:'অ্যাপের নাম', Settings: 'সেটিংস' }
Note here, the key names will be same in all files but values will be different. In your HTML, you will access the value through the key. Similarly, you can add multiple language in multiple files.
Now, in your app.js, add the following code.If you already have some other .config functions in your app.js, No worries! You can have more than one .config functions. Add this separately, better.
.config(function($translateProvider) { $translateProvider.translations('en', translations_en); $translateProvider.translations('bng', translations_bng); $translateProvider.preferredLanguage('en'); }
You can show values like this, {{'Title'|translate}}. Depending on the preferredLanguage given, in place of 'Title', appropriate value declared in js file of 'lang' folder will be shown here.
For more details, visit this blogpost
Upvotes: 3