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

Commit

Permalink
fix(directive): fix issue with data- prefixed attributes #954
Browse files Browse the repository at this point in the history
  • Loading branch information
knalli committed Apr 12, 2015
1 parent 846f19e commit ee253bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/directive/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,12 @@ angular.module('pascalprecht.translate')
if (!successful && typeof scope.defaultText !== 'undefined') {
value = scope.defaultText;
}
var attributeName = iAttr.$attr[translateAttr].substr(15);
var attributeName = iAttr.$attr[translateAttr];
if (attributeName.substr(0, 5) === 'data-') {
// ensure html5 data prefix is stripped
attributeName = attributeName.substr(5);
}
attributeName = attributeName.substr(15);
iElement.attr(attributeName, value);
}
};
Expand Down
6 changes: 6 additions & 0 deletions test/unit/directive/translate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,12 @@ describe('pascalprecht.translate', function () {
expect(element.attr('title')).toBe('foo');
});

it('should make simple attribute translation (data prefixed)', function () {
element = $compile('<div translate data-translate-attr-title="TRANSLATION_ID"></div>')($rootScope);
$rootScope.$digest();
expect(element.attr('title')).toBe('foo');
});

it('should translate multiple attributes', function () {
element = $compile('<div translate translate-attr-name="ANOTHER_ONE" translate-attr-title="TRANSLATION_ID"></div>')($rootScope);
$rootScope.$digest();
Expand Down

0 comments on commit ee253bc

Please sign in to comment.