我很難理解我做錯了什麼,我希望有人能幫助。我需要構建一個小應用程序,以便使用angular-gettext進行練習。我遵循這裏的教程:http://lostechies.com/gabrielschenker/2014/02/11/angularjspart-12-multi-language-support/Angular-gettext翻譯服務似乎沒有工作。
但是,我的項目不會翻譯。我在控制檯中沒有任何錯誤。我擁有所有必需的依賴關係,並且所有內容似乎都能正常工作(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;
});
});
的Index.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"
});
}]);
我知道這很長。感謝您閱讀並提前感謝您的任何建議。
非常感謝你的迴應(和修復)!我認爲我的帖子在'沒人關心'的轉儲中迷路了。我還沒有嘗試過,但再次感謝! – user3882751 2014-09-18 14:31:34
永不放棄希望:-) – 2014-09-19 08:18:49