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

Commit

Permalink
feat(directive): Support for camel casing interpolation variables.
Browse files Browse the repository at this point in the history
When using a directive with interpolation variables with camel cased
words (camelCase), there was no nice way to specify the values of the
variables with the `translate-value-*` attributes.

You can specify attributes like this `translate-value-first-name="Glenn"`,
which would work together with this translation string `'Hello {{firstName}}'`.
  • Loading branch information
tregusti authored and 0x-r4bbit committed Apr 2, 2014
1 parent 640291d commit b345041
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/directive/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ angular.module('pascalprecht.translate')
if (translateValueExist) {
var fn = function (attrName) {
iAttr.$observe(attrName, function (value) {
scope.interpolateParams[angular.lowercase(attrName.substr(14))] = value;
scope.interpolateParams[angular.lowercase(attrName.substr(14, 1)) + attrName.substr(15)] = value;
});
};
for (var attr in iAttr) {
Expand Down
9 changes: 8 additions & 1 deletion test/unit/directive/translate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ describe('pascalprecht.translate', function () {
'FOO': 'hello my name is {{name}}',
'BAR': 'and I\'m {{age}} years old',
'BAZINGA': 'hello my name is {{name}} and I\'m {{age}} years old.',
'YAY': 'hello my name is {{name}} and I\'m {{age}} years old. {{foo}}'
'YAY': 'hello my name is {{name}} and I\'m {{age}} years old. {{foo}}',
'CAMEL': 'hello my name is {{firstName}} {{lastName}}.'
})
.preferredLanguage('en');
}));
Expand Down Expand Up @@ -322,6 +323,12 @@ describe('pascalprecht.translate', function () {
$rootScope.$digest();
expect(element.text()).toEqual('hello my name is Pascal and I\'m 22 years old.');
});

it('should handle interpolation variables with camel casing', function() {
element = $compile('<p translate="CAMEL" translate-value-first-name="Glenn" translate-value-last-name="Jorde"></p>')($rootScope);
$rootScope.$digest();
expect(element.text()).toEqual('hello my name is Glenn Jorde.');
});
});

describe('translate sanitization', function () {
Expand Down

0 comments on commit b345041

Please sign in to comment.