Skip to content

Commit 1a05e6d

Browse files
committed
add support for translating directly into the element
By specifying the "content" attribute in a translate-child attribute list the translated text will be added directly to the element using `element.html()`. This is useful in cases where you need the translation to occur before another directive which has a higher priority than the default translate directive.
1 parent c5a67a6 commit 1a05e6d

File tree

7 files changed

+29
-9
lines changed

7 files changed

+29
-9
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"main": [
44
"dist/angular-devtrw-translate.js"
55
],
6-
"version": "0.2.1",
6+
"version": "0.2.2",
77
"description": "Provides translate-base and translate-child directives for angular-translate",
88
"authors": [
99
"Steven Nance <steven@devtrw.com>"

demo/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ <h4>exclude parent translate base</h4>
119119
</div>
120120
</div>
121121

122+
<div class="example">
123+
<h4>using special "content" attribute</h4>
124+
<hr>
125+
<p translate-child="(content)=DIRECT_CONTENT"></p>
126+
</div>
127+
122128
</div>
123129

124130
<script src="../node_modules/angular/angular.js"></script>
@@ -141,6 +147,8 @@ <h4>exclude parent translate base</h4>
141147
}
142148
},
143149
examples: {
150+
DIRECT_CONTENT: 'This text it translated directly into the element instead of using ' +
151+
'the <b>translate</b> attribute',
144152
GOOGLE_LINK: {
145153
TEXT: 'Google Search'
146154
},

dist/angular-devtrw-translate.js

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-devtrw-translate.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-devtrw-translate.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-devtrw-translate",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"author": "Steven Nance <steven@devtrw.com>",
55
"homepage": "https://github.com/devtrw/angular-devtrw-translate",
66
"repository": {

src/translate-child-directive.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
function dtrwTranslateChildDirective($compile, $translate) {
22

33
function setValueForAttrs(element, targetAttrs, value) {
4-
targetAttrs.forEach((targetAttrs) => {
5-
element.attr(targetAttrs, value);
4+
targetAttrs.forEach((targetAttr) => {
5+
// allow directly setting the content of an element, essentially the same as using
6+
// the translate filter within the element
7+
if ('content' === targetAttr) {
8+
element.html(value);
9+
} else {
10+
element.attr(targetAttr, value);
11+
}
612
});
713
}
814

0 commit comments

Comments
 (0)