【发布时间】:2014-08-29 19:14:20
【问题描述】:
我很难理解我做错了什么,我希望有人能提供帮助。我需要构建一个小应用程序来练习 angular-gettext。我在这里按照教程进行操作:http://lostechies.com/gabrielschenker/2014/02/11/angularjspart-12-multi-language-support/
但是,我的项目不会翻译。我在控制台中没有任何错误。我拥有所有必要的依赖项,并且一切似乎都正常工作(grunt、bower 等),所以它必须在实际代码中。可能是花括号什么的。
这是我的 app.js 文件:
var app = angular.module('app', ['gettext']);
app.controller("TestCtrl", function($scope){
app.run(function(gettextCatalog){
gettextCatalog.currentLanguage = 'de';
gettextCatalog.debug = true;
});
});
索引.html:
<!DOCTYPE html>
<html>
<head>
<title>Translation Sample</title>
<link rel="stylesheet" type="text/css"
href="bower_components/bootstrap/dist/css/bootstrap.css"/>
</head>
<body ng-app="app">
<div ng-controller="TestCtrl">
<p translate>Welcome to my app</p>
<p translate>We want to test globalization and localization</p>
</div>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-gettext/dist/angular-gettext.js"></script>
<script src="app.js"></script>
<script src="translations.js"></script>
</body>
</html>
Gruntfile.js:
module.exports = function(grunt){
grunt.loadNpmTasks('grunt-angular-gettext');
grunt.initConfig({
nggettext_extract:{
pot: {
files: {
'po/template.pot': ['**/*.html']
}
}
},
nggettext_compile:{
all: {
files: {
'translations.js': ['po/*.po']
}
}
}
})
};
Translations.js:
angular.module('gettext').run(['gettextCatalog', function (gettextCatalog) {
gettextCatalog.setStrings('de', {
"We want to test globalization and localization":"Wir wollen testen, Globalisierung und Lokalisierung",
"Welcome to my app":"Willkommen auf meiner App"
});
}]);
我知道这很长。感谢您的阅读,并提前感谢您的任何建议。
【问题讨论】:
标签: javascript angularjs language-translation