i installed angular-translate-loader-static-files
with this command line bower install angular-translate-loader-static-files
我使用这个命令行bower安装了angular-translate-loader-static文件
after ,i create a file json with this name messages_en.json
in folder i18n
之后,我创建了一个名为messages_en的json文件。json在文件夹i18n
my angular.module like this:
我的角。模块是这样的:
angular.module('starter', ['ionic', 'ngStorage', 'ngCordova','starter.services','ionic-datepicker','starter.directives','ion-google-place','ngAutocomplete','colorpicker.module','ui.calendar','ngLoadingSpinner','ionic-ratings','pascalprecht.translate'])
facebookExample.config(function($stateProvider, $urlRouterProvider, $translateProvider) {
$translateProvider.useStaticFilesLoader({
prefix: 'i18n/messages_',
suffix: '.json'
});
$translateProvider.preferredLanguage("en");
$translateProvider.fallbackLanguage("en");
});
in my index.html
在我的index . html
<script type="text/javascript" src="lib/angular-translate/angular-translate.js"></script>
<script type="text/javascript" src="lib/angular-translate-loader-static-files/angular-translate-loader-static-files.js"></script>
<script type="text/javascript" src="lib/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js"></script>
my messages_en.json:
我的messages_en.json:
{
"Accueil" : "welcome",
"Livre" : "book",
}
but when i run my application the word 'Livre' not translate into English
但是当我运行我的应用程序时,“Livre”这个词不会翻译成英文。
what's the problem please help me
有什么问题请帮帮我
2 个解决方案
#1
3
Your problem is in your json file. Remove the last comma and you should be OK.
问题在json文件中。去掉最后一个逗号,就可以了。
Note : Don't add angular-translate-loader-static-files.js and angular-translate-loader-static-files.min.js. Choose only one to keep.
注意:不要添加angular- translation -loader-static文件。js和angular-translate-loader-static-files.min.js。只选择一个保存。
#2
0
You can add the follow code to get en error message, if your JSON-File is invalid
如果json文件无效,您可以添加以下代码以获取en错误消息
$scope.changeLanguage = function (langKey) {
$translate.use(langKey).then(function(){}, function(){toastr.error('JSON file is invalid')})
};
#1
3
Your problem is in your json file. Remove the last comma and you should be OK.
问题在json文件中。去掉最后一个逗号,就可以了。
Note : Don't add angular-translate-loader-static-files.js and angular-translate-loader-static-files.min.js. Choose only one to keep.
注意:不要添加angular- translation -loader-static文件。js和angular-translate-loader-static-files.min.js。只选择一个保存。
#2
0
You can add the follow code to get en error message, if your JSON-File is invalid
如果json文件无效,您可以添加以下代码以获取en错误消息
$scope.changeLanguage = function (langKey) {
$translate.use(langKey).then(function(){}, function(){toastr.error('JSON file is invalid')})
};