@@ -128,6 +128,18 @@ function overlayChildNodes(fromFragment, toElement) {
128
128
toElement . appendChild ( fromFragment ) ;
129
129
}
130
130
131
+ function hasAttribute ( attributes , name ) {
132
+ if ( ! attributes ) {
133
+ return false ;
134
+ }
135
+ for ( let attr of attributes ) {
136
+ if ( attr . name === name ) {
137
+ return true ;
138
+ }
139
+ }
140
+ return false ;
141
+ }
142
+
131
143
/**
132
144
* Transplant localizable attributes of an element to another element.
133
145
*
@@ -144,9 +156,11 @@ function overlayAttributes(fromElement, toElement) {
144
156
. split ( "," ) . map ( i => i . trim ( ) )
145
157
: null ;
146
158
147
- // Remove existing localizable attributes.
159
+ // Remove existing localizable attributes if they
160
+ // will not be used in the new translation.
148
161
for ( const attr of Array . from ( toElement . attributes ) ) {
149
- if ( isAttrNameLocalizable ( attr . name , toElement , explicitlyAllowed ) ) {
162
+ if ( isAttrNameLocalizable ( attr . name , toElement , explicitlyAllowed )
163
+ && ! hasAttribute ( fromElement . attributes , attr . name ) ) {
150
164
toElement . removeAttribute ( attr . name ) ;
151
165
}
152
166
}
@@ -160,7 +174,8 @@ function overlayAttributes(fromElement, toElement) {
160
174
161
175
// Set localizable attributes.
162
176
for ( const attr of Array . from ( fromElement . attributes ) ) {
163
- if ( isAttrNameLocalizable ( attr . name , toElement , explicitlyAllowed ) ) {
177
+ if ( isAttrNameLocalizable ( attr . name , toElement , explicitlyAllowed )
178
+ && toElement . getAttribute ( attr . name ) !== attr . value ) {
164
179
toElement . setAttribute ( attr . name , attr . value ) ;
165
180
}
166
181
}
0 commit comments