Skip to content

Commit 10dcb27

Browse files
committed
Fix anchor text not translated in ie8
Related #49 that is caused by angular/angular.js/#1949 / angular/angular.js/#2013
1 parent fcf3483 commit 10dcb27

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

dist/angular-gettext.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ angular.module('gettext').factory('gettextCatalog', ["gettextPlurals", "$http",
101101
return catalog;
102102
}]);
103103

104-
angular.module('gettext').directive('translate', ["gettextCatalog", "$parse", "$animate", "$compile", function (gettextCatalog, $parse, $animate, $compile) {
104+
angular.module('gettext').directive('translate', ["gettextCatalog", "$parse", "$animate", "$compile", "$window", function (gettextCatalog, $parse, $animate, $compile, $window) {
105105
// Trim polyfill for old browsers (instead of jQuery)
106106
// Based on AngularJS-v1.2.2 (angular.js#620)
107107
var trim = (function () {
@@ -121,6 +121,8 @@ angular.module('gettext').directive('translate', ["gettextCatalog", "$parse", "$
121121
}
122122
}
123123

124+
var msie = parseInt((/msie (\d+)/.exec(angular.lowercase($window.navigator.userAgent)) || [])[1], 10);
125+
124126
return {
125127
restrict: 'A',
126128
terminal: true,
@@ -132,6 +134,14 @@ angular.module('gettext').directive('translate', ["gettextCatalog", "$parse", "$
132134
var msgid = trim(element.html());
133135
var translatePlural = attrs.translatePlural;
134136

137+
if (msie <= 8) {
138+
// Workaround fix relating to angular adding a comment node to
139+
// anchors. angular/angular.js/#1949 / angular/angular.js/#2013
140+
if (msgid.slice(-13) === '<!--IE fix-->') {
141+
msgid = msgid.slice(0, -13);
142+
}
143+
}
144+
135145
return {
136146
post: function (scope, element, attrs) {
137147
var countFn = $parse(attrs.translateN);

dist/angular-gettext.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.

src/directive.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
angular.module('gettext').directive('translate', function (gettextCatalog, $parse, $animate, $compile) {
1+
angular.module('gettext').directive('translate', function (gettextCatalog, $parse, $animate, $compile, $window) {
22
// Trim polyfill for old browsers (instead of jQuery)
33
// Based on AngularJS-v1.2.2 (angular.js#620)
44
var trim = (function () {
@@ -18,6 +18,8 @@ angular.module('gettext').directive('translate', function (gettextCatalog, $pars
1818
}
1919
}
2020

21+
var msie = parseInt((/msie (\d+)/.exec(angular.lowercase($window.navigator.userAgent)) || [])[1], 10);
22+
2123
return {
2224
restrict: 'A',
2325
terminal: true,
@@ -29,6 +31,14 @@ angular.module('gettext').directive('translate', function (gettextCatalog, $pars
2931
var msgid = trim(element.html());
3032
var translatePlural = attrs.translatePlural;
3133

34+
if (msie <= 8) {
35+
// Workaround fix relating to angular adding a comment node to
36+
// anchors. angular/angular.js/#1949 / angular/angular.js/#2013
37+
if (msgid.slice(-13) === '<!--IE fix-->') {
38+
msgid = msgid.slice(0, -13);
39+
}
40+
}
41+
3242
return {
3343
post: function (scope, element, attrs) {
3444
var countFn = $parse(attrs.translateN);

0 commit comments

Comments
 (0)