@@ -44,6 +44,7 @@ angular.module('gettext').directive('translate', function (gettextCatalog, $pars
44
44
post : function ( scope , element , attrs ) {
45
45
var countFn = $parse ( attrs . translateN ) ;
46
46
var pluralScope = null ;
47
+ var linking = true ;
47
48
48
49
function update ( ) {
49
50
// Fetch correct translated string.
@@ -56,11 +57,22 @@ angular.module('gettext').directive('translate', function (gettextCatalog, $pars
56
57
translated = gettextCatalog . getString ( msgid , null , translateContext ) ;
57
58
}
58
59
60
+ var oldContents = element . contents ( ) ;
61
+
62
+ // Avoid redundant swaps
63
+ if ( translated === oldContents [ 0 ] . textContent ) {
64
+ // Take care of unlinked content
65
+ if ( linking ) {
66
+ $compile ( oldContents ) ( scope ) ;
67
+ }
68
+ return ;
69
+ }
70
+
59
71
// Swap in the translation
60
72
var newWrapper = angular . element ( '<span>' + translated + '</span>' ) ;
61
73
$compile ( newWrapper . contents ( ) ) ( scope ) ;
62
- var oldContents = element . contents ( ) ;
63
74
var newContents = newWrapper . contents ( ) ;
75
+
64
76
$animate . enter ( newContents , element ) ;
65
77
$animate . leave ( oldContents ) ;
66
78
}
@@ -72,6 +84,7 @@ angular.module('gettext').directive('translate', function (gettextCatalog, $pars
72
84
scope . $on ( 'gettextLanguageChanged' , update ) ;
73
85
74
86
update ( ) ;
87
+ linking = false ;
75
88
}
76
89
} ;
77
90
}
0 commit comments