Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在配置阶段使用角度gettext?_Javascript_Angularjs_Gettext_Breadcrumbs_Angular Gettext - Fatal编程技术网

Javascript 如何在配置阶段使用角度gettext?

Javascript 如何在配置阶段使用角度gettext?,javascript,angularjs,gettext,breadcrumbs,angular-gettext,Javascript,Angularjs,Gettext,Breadcrumbs,Angular Gettext,我在用,还有 我的应用程序配置与此类似: app.config(function($stateProvider) { $stateProvider.state('welcome', { url : '/', templateUrl: 'index.html', ncyBreadcrumb : { label : 'Home' } }); }); 我希望能够通过angular gettext翻译面包屑('Home')的标签。为此

我在用,还有

我的应用程序配置与此类似:

app.config(function($stateProvider) {

  $stateProvider.state('welcome', {
     url : '/',
     templateUrl: 'index.html',
     ncyBreadcrumb : {
        label : 'Home'
     }
  });

});
我希望能够通过
angular gettext
翻译面包屑(
'Home'
)的标签。为此,我需要在
app.config()
函数中包含gettext工具。类似这样的内容非常理想,但是在配置阶段,
gettextCatalog
不可用:

app.config(function($stateProvider, gettextCatalog) {

  $stateProvider.state('welcome', {
     url : '/',
     templateUrl: 'index.html',
     ncyBreadcrumb : {
        label : gettextCatalog.getString('Home')
     }
  });

});
有没有其他方法可以通过这些插件实现这一点,特别是通过
angular gettext

根据文档:

属性
ncybreadbacklabel
可以包含根据当前状态控制器的范围进行评估的绑定

我尚未对此进行测试,但我认为您可以在控制器中使用
gettextCatalog
模块:

$stateProvider.state('home', {
  url: '/',
  templateUrl: 'index.html',
  controller: function($scope, gettextCatalog) {
    $scope.label = gettextCatalog.getString('Home');
  },
  ncyBreadcrumb: {
    label: '{{label}}'
  }
})

这可能是最好的解决方案。另一种可能性是。甚至
label:{{label | translate}}}
也可以工作,但是
grunt angular gettext
提取没有检测到这两个表达式,因此它们是无用的。