【问题标题】:Angular-gettext translation service doesn't appear to be working.Angular-gettext 翻译服务似乎不起作用。
【发布时间】: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


    【解决方案1】:

    这可能是一个 angular-gettext 错误:您的字符串是在您设置语言后加载的。随着 angular.js 最近的变化,这可能会中断。

    我会对此进行修复。

    更新:angular-gettext 1.1.2 已发布并对此进行了修复(试试看)。请注意,在最近的版本中,currentLanguage 的使用已被弃用。你应该改用gettextCatalog.setCurrentLanguage('de')

    https://angular-gettext.rocketeer.be/dev-guide/api/angular-gettext/

    【讨论】:

    • 非常感谢您的回复(以及修复)!我以为我的帖子在“没人关心”转储中丢失了。我还没有尝试过,但再次感谢!
    • 永不放弃希望 :-)
    猜你喜欢
    • 1970-01-01
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多