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

Commit

Permalink
fix(directive): handle interpolation of undefined keys correctly in u…
Browse files Browse the repository at this point in the history
…pdateTranslations, fixes issues in #971
  • Loading branch information
tspaeth authored and knalli committed Apr 8, 2015
1 parent 401204a commit 3f7cf4c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/directive/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ angular.module('pascalprecht.translate')
// Master update function
var updateTranslations = function () {
for (var key in translationIds) {
if (translationIds.hasOwnProperty(key)) {

if (translationIds.hasOwnProperty(key) && translationIds[key] !== undefined) {
updateTranslation(key, translationIds[key], scope, scope.interpolateParams, scope.defaultText);
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/unit/directive/translate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ describe('pascalprecht.translate', function () {
expect(element.text()).toBe('TEXT');
});

it('should return empty translation if translationId scope Variable does not exist and if its passed as interpolation', function () {
element = $compile('<div translate>{{translationIdNotExisting}}</div>')($rootScope);
$rootScope.$digest();
expect(element.text()).toBe('');
});


it('should return translation prepended by additional content when passed as interpolation', function () {
$rootScope.translationId = 'TRANSLATION_ID';
element = $compile('<div translate>abc{{translationId}}')($rootScope);
Expand Down
4 changes: 3 additions & 1 deletion test/unit/filter/translate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ describe('pascalprecht.translate', function () {
it('should return with translation id if translation doesn\'t exist', function () {
expect($translate('WOOP')).toEqual('WOOP');
});

it('should return with translation id if translation doesn\'t exist', function () {
expect($translate(null)).toEqual(null);
});
it('should return translation if translation id exist', function () {
expect($translate('TRANSLATION_ID')).toEqual('Lorem Ipsum ');
});
Expand Down

0 comments on commit 3f7cf4c

Please sign in to comment.