我使用angular translate static files loader来翻译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文件都包含单词world !!
答案 0 :(得分:0)
您应该注意在选择输入中更改语言:
<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);
};