多语种应用在英语或Ionic框架

时间:2023-01-14 22:57:01

I am very new to both Angularjs and Ionic Framework. I coming from Microsoft background.

我对Angularjs和Ionic Framework都很陌生。我来自微软背景。

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

我正在尝试用三种语言(英语、阿拉伯语和法语)制作app。正如我告诉你的,我来自微软背景,我正在用。net的方式思考,对于多语言应用程序的翻译,我们使用资源文件,在。net代码中使用语言环境。例如

http://www.codeproject.com/Tips/580043/How-to-make-a-multi-language-application-in-Csharp

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

有什么方法可以做同样的事情天使或者离子框架吗

2 个解决方案

#1


3  

Follow the steps here:

按以下步骤:

  1. Download the Source Code.zip file from here and copy the angular-translate and angular-translate.min file to www/lib/ionic/js/angular folder along with other js files.
  2. 下载源代码。压缩文件从这里和拷贝的英语翻译和英语翻译。最小文件到www/lib/离子/js/角文件夹以及其他js文件。
  3. In index.html, include "http://lib/ionic/js/angular/angular-translate.js" along with other script tags.
  4. 在索引。html,包括“http://lib/ionic/js/angular/angular-translate。以及其他脚本标签。
  5. Now you need to add 'pascalprecht.translate' in dependency list of controllers.js file like, angular.module('starter.controllers', ['pascalprecht.translate']). You can also add it in dependency list of main module.
  6. 现在你需要添加“pascalprecht”。在控制器的依赖列表中转换。js文件,angular.module(“起动器。控制器”,[' pascalprecht.translate '])。您还可以在主模块的依赖列表中添加它。
  7. 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:

    创建一个子文件夹,例如,在www中创建“lang”,并为要添加到应用程序的每种语言添加js文件。在单独的JavaScript文件中,创建包含所有翻译的键值映射的数组变量。例如,在英语。js文件:

    var translations_en = { Title:'My app title', Settings:'Settings' } In bengali.js file: var translations_bng={ Title:'অ্যাপের নাম', Settings: 'সেটিংস' }

    var translations_en = {Title:'My app Title ', Settings:'Settings'} In bengali。js文件:var translations_bng = {标题:“অ্যাপেরনাম”,设置:“সেটিংস' }

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.

注意,所有文件中的键名都是相同的,但是值是不同的。在HTML中,您将通过键访问该值。类似地,您可以在多个文件中添加多种语言。

  1. 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.

    现在,在您的app.js中,添加以下代码。如果你的app.js中已经有了一些其他的.config函数,不用担心!可以有多个.config函数。单独添加这个,更好。

    .config(function($translateProvider) { $translateProvider.translations('en', translations_en); $translateProvider.translations('bng', translations_bng); $translateProvider.preferredLanguage('en'); }

    过程(函数(translateProvider美元){ translateProvider美元。翻译(“en”,translations_en);translateProvider美元。翻译(bng,translations_bng);美元translateProvider.preferredLanguage(en);}

  2. 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.

    您可以显示这样的值,{{{'Title'|translate}}。根据给定的首选语言,这里将显示在'lang'文件夹的js文件中声明的适当值,以取代'Title'。

For more details, visit this blogpost

欲了解更多详情,请访问此博客。

#2


0  

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

npm install ng-translator --save

Check out this

看看这个

#1


3  

Follow the steps here:

按以下步骤:

  1. Download the Source Code.zip file from here and copy the angular-translate and angular-translate.min file to www/lib/ionic/js/angular folder along with other js files.
  2. 下载源代码。压缩文件从这里和拷贝的英语翻译和英语翻译。最小文件到www/lib/离子/js/角文件夹以及其他js文件。
  3. In index.html, include "http://lib/ionic/js/angular/angular-translate.js" along with other script tags.
  4. 在索引。html,包括“http://lib/ionic/js/angular/angular-translate。以及其他脚本标签。
  5. Now you need to add 'pascalprecht.translate' in dependency list of controllers.js file like, angular.module('starter.controllers', ['pascalprecht.translate']). You can also add it in dependency list of main module.
  6. 现在你需要添加“pascalprecht”。在控制器的依赖列表中转换。js文件,angular.module(“起动器。控制器”,[' pascalprecht.translate '])。您还可以在主模块的依赖列表中添加它。
  7. 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:

    创建一个子文件夹,例如,在www中创建“lang”,并为要添加到应用程序的每种语言添加js文件。在单独的JavaScript文件中,创建包含所有翻译的键值映射的数组变量。例如,在英语。js文件:

    var translations_en = { Title:'My app title', Settings:'Settings' } In bengali.js file: var translations_bng={ Title:'অ্যাপের নাম', Settings: 'সেটিংস' }

    var translations_en = {Title:'My app Title ', Settings:'Settings'} In bengali。js文件:var translations_bng = {标题:“অ্যাপেরনাম”,设置:“সেটিংস' }

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.

注意,所有文件中的键名都是相同的,但是值是不同的。在HTML中,您将通过键访问该值。类似地,您可以在多个文件中添加多种语言。

  1. 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.

    现在,在您的app.js中,添加以下代码。如果你的app.js中已经有了一些其他的.config函数,不用担心!可以有多个.config函数。单独添加这个,更好。

    .config(function($translateProvider) { $translateProvider.translations('en', translations_en); $translateProvider.translations('bng', translations_bng); $translateProvider.preferredLanguage('en'); }

    过程(函数(translateProvider美元){ translateProvider美元。翻译(“en”,translations_en);translateProvider美元。翻译(bng,translations_bng);美元translateProvider.preferredLanguage(en);}

  2. 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.

    您可以显示这样的值,{{{'Title'|translate}}。根据给定的首选语言,这里将显示在'lang'文件夹的js文件中声明的适当值,以取代'Title'。

For more details, visit this blogpost

欲了解更多详情,请访问此博客。

#2


0  

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

npm install ng-translator --save

Check out this

看看这个