Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
feat(translateFilter): teaches filter to use custom interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
0x-r4bbit committed Jul 18, 2013
1 parent 5e20e24 commit 46f03cc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/filter/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ angular.module('pascalprecht.translate')
</example>
*/
.filter('translate', ['$parse', '$translate', function ($parse, $translate) {
return function (translationId, interpolateParams) {
return function (translationId, interpolateParams, interpolation) {

if (!angular.isObject(interpolateParams)) {
interpolateParams = $parse(interpolateParams)();
}
return $translate(translationId, interpolateParams);
return $translate(translationId, interpolateParams, interpolation);
};
}]);
46 changes: 46 additions & 0 deletions test/unit/translateFilterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,50 @@ describe('pascalprecht.translate', function () {
});
});
});

describe('additional interpolation', function () {

var $filter;

beforeEach(module('pascalprecht.translate', function ($translateProvider, $provide) {

$provide.factory('customInterpolation', function () {

var translateInterpolator = {},
$locale;

// provide a method to set locale
translateInterpolator.setLocale = function (locale) {
$locale = locale;
};

// provide a method to return an interpolation identifier
translateInterpolator.getInterpolationIdentifier = function () {
return 'custom';
}

// defining the actual interpolate function
translateInterpolator.interpolate = function (string, interpolateParams) {
return 'custom interpolation';
};

return translateInterpolator;
});

$translateProvider.translations('en', {
'FOO': 'Yesssss'
});

$translateProvider.addInterpolation('customInterpolation');
$translateProvider.preferredLanguage('en');
}));

beforeEach(inject(function (_$filter_) {
$filter = _$filter_;
}));

it('should consider translate-interpolation value', function () {
expect($filter('translate')('FOO', {}, 'custom')).toEqual('custom interpolation');
});
});
});

0 comments on commit 46f03cc

Please sign in to comment.