@@ -132,44 +132,49 @@ struct LocalizationFiles {
132
132
sortLinesAlphabetically ( )
133
133
}
134
134
let location = singleLanguage ? " \( path) /Localizable.strings " : " \( path) / \( name) .lproj/Localizable.strings "
135
- if let string = try ? String ( contentsOfFile: location, encoding: . utf8) {
136
- let lines = string. components ( separatedBy: . newlines)
137
- keyValue = [ : ]
138
- let pattern = " \" (.*) \" = \" (.+) \" ; "
139
- let regex = try ? NSRegularExpression ( pattern: pattern, options: [ ] )
140
- var ignoredTranslation : [ String ] = [ ]
141
-
142
- for (lineNumber, line) in lines. enumerated ( ) {
143
- let range = NSRange ( location: 0 , length: ( line as NSString ) . length)
144
-
145
- // Ignored pattern
146
- let ignoredPattern = " \" (.*) \" = \" (.+) \" ; * \\ / \\ / *ignore-same-translation-warning "
147
- let ignoredRegex = try ? NSRegularExpression ( pattern: ignoredPattern, options: [ ] )
148
- if let ignoredMatch = ignoredRegex? . firstMatch ( in: line,
149
- options: [ ] ,
150
- range: range) {
151
- let key = ( line as NSString ) . substring ( with: ignoredMatch. range ( at: 1 ) )
152
- ignoredTranslation. append ( key)
153
- }
154
- if let firstMatch = regex? . firstMatch ( in: line, options: [ ] , range: range) {
155
- let key = ( line as NSString ) . substring ( with: firstMatch. range ( at: 1 ) )
156
- let value = ( line as NSString ) . substring ( with: firstMatch. range ( at: 2 ) )
157
- if let _ = keyValue [ key] {
158
- let str = " \( path) / \( name) .lproj "
159
- + " /Localizable.strings: \( linesNumbers [ key] !) : "
160
- + " error: [Redundance] \" \( key) \" "
161
- + " is redundant in \( name. uppercased ( ) ) file "
162
- print ( str)
163
- numberOfErrors += 1
164
- } else {
165
- keyValue [ key] = value
166
- linesNumbers [ key] = lineNumber + 1
167
- }
135
+ guard let string = try ? String ( contentsOfFile: location, encoding: . utf8) else {
136
+ return
137
+ }
138
+
139
+ let lines = string. components ( separatedBy: . newlines)
140
+ keyValue = [ : ]
141
+
142
+ let pattern = " \" (.*) \" = \" (.+) \" ; "
143
+ let regex = try ? NSRegularExpression ( pattern: pattern, options: [ ] )
144
+ var ignoredTranslation : [ String ] = [ ]
145
+
146
+ for (lineNumber, line) in lines. enumerated ( ) {
147
+ let range = NSRange ( location: 0 , length: ( line as NSString ) . length)
148
+
149
+ // Ignored pattern
150
+ let ignoredPattern = " \" (.*) \" = \" (.+) \" ; * \\ / \\ / *ignore-same-translation-warning "
151
+ let ignoredRegex = try ? NSRegularExpression ( pattern: ignoredPattern, options: [ ] )
152
+ if let ignoredMatch = ignoredRegex? . firstMatch ( in: line,
153
+ options: [ ] ,
154
+ range: range) {
155
+ let key = ( line as NSString ) . substring ( with: ignoredMatch. range ( at: 1 ) )
156
+ ignoredTranslation. append ( key)
157
+ }
158
+
159
+ if let firstMatch = regex? . firstMatch ( in: line, options: [ ] , range: range) {
160
+ let key = ( line as NSString ) . substring ( with: firstMatch. range ( at: 1 ) )
161
+ let value = ( line as NSString ) . substring ( with: firstMatch. range ( at: 2 ) )
162
+
163
+ if keyValue [ key] != nil {
164
+ let str = " \( path) / \( name) .lproj "
165
+ + " /Localizable.strings: \( linesNumbers [ key] !) : "
166
+ + " error: [Duplication] \" \( key) \" "
167
+ + " is duplicated in \( name. uppercased ( ) ) file "
168
+ print ( str)
169
+ numberOfErrors += 1
170
+ } else {
171
+ keyValue [ key] = value
172
+ linesNumbers [ key] = lineNumber + 1
168
173
}
169
174
}
170
- print ( ignoredFromSameTranslation)
171
- ignoredFromSameTranslation [ name] = ignoredTranslation
172
175
}
176
+ print ( ignoredFromSameTranslation)
177
+ ignoredFromSameTranslation [ name] = ignoredTranslation
173
178
}
174
179
175
180
func rebuildFileString( from lines: [ String ] ) -> String {
@@ -306,6 +311,15 @@ for file in localizationFiles {
306
311
numberOfErrors += 1
307
312
}
308
313
}
314
+
315
+ let redundantKeys = file. keyValue. keys. filter { !masterLocalizationFile. keyValue. keys. contains ( $0) }
316
+
317
+ for k in redundantKeys {
318
+ let str = " \( path) / \( file. name) .lproj/Localizable.strings: \( file. linesNumbers [ k] !) : "
319
+ + " error: [Redundant key] \" \( k) \" redundant in \( file. name. uppercased ( ) ) file "
320
+
321
+ print ( str)
322
+ }
309
323
}
310
324
311
325
if checkForUntranslated {
0 commit comments