来自Angular翻译文档:
$translate(translationId [,interpolateParams],interpolationId);
interpolationId参数的用途是什么,你能举个例子吗?
What is the purpose of interpolationId parameter…
interpolationId的目的是引用已添加的自定义插值的getInterpolationIdentifier返回的标识符.您可以使用$translateProvider.addInterpolation
添加自定义插值.
这在angular-translate的Pluralization documentation中有更好的记录.
…can you also give an example?
这是一个例子:
https://plnkr.co/edit/cDpNzZ6T6TSc13Qmji77
HTML
<body ng-controller="MyCtrl"> $translate('greeting',{},'custom'): {{ customGreeting }} <br> $translate('greeting',{}): {{ regularGreeting }} </body>
JavaScript的
var app = angular.module('app',[ 'pascalprecht.translate' ]); app.config(["$translateProvider",function($translateProvider){ $translateProvider.translations('en',{ "greeting" : "Welcome Dinesh" }); $translateProvider.preferredLanguage('en'); $translateProvider.addInterpolation('customInterpolator'); } ]); app.controller('MyCtrl',[ '$scope','$translate',function ($scope,$translate) { $translate('greeting','custom').then(function (result) { $scope.customGreeting = result; }); $translate('greeting',{}).then(function (result) { $scope.regularGreeting = result; }); } ]); app.factory('customInterpolator',[ function () { var customInterpolator = {}; customInterpolator.$get = function () { }; customInterpolator.setLocale = function (locale) { }; customInterpolator.getInterpolationIdentifier = function () { return 'custom'; }; customInterpolator.interpolate = function (string,interpolateParams) { return 'My custom interpolation message'; }; return customInterpolator; } ]);