如果在$ translateProvider.translations()中提供了symabol和翻译,则角度转换可以正常工作。但是,当我尝试使用json文件中的值执行转换时,转换不起作用。
var mymodel= angular.module('mymodel',['pascalprecht.translate']).
config(function($translateProvider) {
$translateProvider.translations('en', {
HEADLINE: 'Hello there, This is my awesome app!',
INTRO_TEXT: 'And it has i18n support!'
}) .translations('de', {
HEADLINE: 'Hey, das ist meine großartige App!',
INTRO_TEXT: 'Und sie untersützt mehrere Sprachen!'
});
$translateProvider.useStaticFilesLoader({
prefix: 'https://localhost/angular%20seed/app/js/languages/',
suffix: '.json'
});
$translateProvider.preferredLanguage('de');
$translateProvider.fallbackLanguage('de');
// $translateProvider.useLocalStorage();
});
我的html文件
<html ng-app="mymodel">
<head>
<title> Sing up</title>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<link rel="stylesheet" href="css/app.css"/>
<script src="lib/angular/angular.js"></script>
<script src="lib/angular/angular-resource.js"></script>
<script src="lib/angular/angular-translate.js"></script>
<script src="lib/angular/angular-translate-loader-static-files.js"></script>
<script src="js/app.js"></script>
<script src="js/Controllers/FirstController.js"></script>
</head>
<body style="margin-left:200px">
<div ng-controller="FirstController">
{{ 'INTRO_TEXT' | translate }}
{{ 'INTRO_TEXT1' | translate }}
</div>
</body>
</html>
de.json(路径:https://localhost/angular%20seed/app/js/languages/de.json
)
{
"HEADLINE1": "Hey, das ist meine großartige App!",
"INTRO_TEXT1": "Und sie untersützt mehrere Sprachen!"
}
输出
Und sie untersützt mehrere Sprachen!
INTRO_TEXT1
修改 我没有收到任何错误消息。