这是Fiddle
是否有可能在angular-translate中检查其他语言中的键值是否不可用,那么它是否可以从另一种语言中提取该键值? 就像在例子中我有英语和西班牙语。并且一个键值(示例中为“CONFIRM_LABEL”)不支持西班牙语。是否可以从英文版中提取数据?
HTML
<div name="info" ng-controller="myctrl">
<label translate="TERMS_LABEL"></label>
<h4 translate="ZIPCODE_LABEL"></h4>
<p translate="LAST_NAME"></p>
<p translate="CONFIRM_LABEL"></p>
<button type="submit" ng-click="changeLanguage('de')" >Spanish</button>
<button type="submit" ng-click="changeLanguage('en')" >English</button>
JS
var demo = angular.module('demo', ['pascalprecht.translate']);
demo.controller('myctrl',function ($scope,$translate)
{
$scope.changeLanguage = function (key)
{
$translate.use(key);
};
})
demo.config(function ($translateProvider) {
$translateProvider.translations('en', {
"TERMS_CONDITIONS":"TERMS & CONDITIONS",
"TERMS_LABEL":"TERMS",
"ZIPCODE_LABEL":"ZIP CODE",
"LAST_NAME":"Last Name",
"CONFIRM_LABEL": "Confirm Number ",
})
.translations('de', {
"TERMS_LABEL": "Términos",
"FORM_LABEL": "Información ",
"LAST_NAME": "Apellido",
"ZIPCODE_LABEL": "Código Postal"
});
$translateProvider.preferredLanguage('en');
})
答案 0 :(得分:6)
是的,这是可能的。
$translateProvider
.translations('de', { /* ... */ })
.translations('en', { /* ... */ })
.fallbackLanguage('en');