【问题标题】:Use of angular-translate-static-files-loader in html在 html 中使用 angular-translate-static-files-loader
【发布时间】:2016-02-22 15:38:08
【问题描述】:

我使用角度翻译静态文件加载器来翻译 html 中的内容。 我的代码在页面加载时工作正常,当我选择另一种未翻译的语言时,加载后以所选语言可见。

我的html代码是:

 <select ng-model="selected" ng-options=" selec.Name for selec in langTable"> </select><br>
       <span ng-bind-html="'world' |translate"></span>

我的角码是:

.config(function($translateProvider){
 $translateProvider.useStaticFilesLoader({
prefix:'assets/',
suffix:'.STRINGS'
 });
 }) 
 .controller( 'Ctrl', function ( $scope,$translate ) {
  $scope.langTable=[{Name:'English',value:"en_US"},{Name:'France',value:"fr_FR"},{Name:'German',value:"pt_BR"}];
  $scope.selected=$scope.langTable[1];
   $translate.use($scope.selected.value);
   console.log($scope.selected.value);
 })

my en_US.STRINGS contains :
 {
 "world": "halooo worlde welcame to our new aPPP",
 "hello":"haloo"
 }

我所有的 .strings 文件都包含世界这个词!!

【问题讨论】:

    标签: angularjs angular-translate angularjs-ng-options


    【解决方案1】:

    您应该注意在选择输入中更改语言:

     <select ng-model="selected" ng-options=" selec.value as selec.Name for selec in langTable" ng-change="setLang()"> </select>
    

    在你的控制器中:

    $scope.setLang = function() {
      $translate.use($scope.selected);
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-28
      • 2015-03-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 2018-10-10
      • 2016-08-27
      相关资源
      最近更新 更多