在 html 中使用 angular-translate-static-files-loader

Use of angular-translate-static-files-loader in html

我使用 angular 翻译静态文件加载器来翻译 html 中的内容。 我的代码在加载页面时工作正常,当我 select 另一种它没有翻译的语言时,它在加载后以 selected 语言可见。

我的html代码是:

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

我的angular代码是:

.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 文件都包含单词 world!!

您应该注意 select 输入中的语言变化:

 <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);
};