@@ -16,14 +16,18 @@ guard let enumerator = FileManager.default.enumerator(at: URL(fileURLWithPath: F
16
16
var missingStrings : [ String : [ String ] ] = [ : ]
17
17
18
18
for case let url as URL in enumerator where try url. resourceValues ( forKeys: [ . isRegularFileKey] ) . isRegularFile == true {
19
+ var exceptions = Set < String > ( )
20
+ if url. pathExtension == " txt " && url. deletingPathExtension ( ) . lastPathComponent == " ignored_translation_keys " {
21
+ exceptions = try parseExceptionKeys ( at: url)
22
+ }
19
23
if url. pathExtension == " strings " {
20
- let emptyStrings = try parseEmptyStringsFile ( at: url)
24
+ let emptyStrings = try parseEmptyStringsFile ( at: url, with : exceptions )
21
25
if !emptyStrings. isEmpty {
22
26
missingStrings [ url. pathComponents [ max ( 0 , url. pathComponents. count - 2 ) ] , default: [ ] ] . append ( contentsOf: emptyStrings)
23
27
}
24
28
}
25
29
if url. pathExtension == " stringsdict " {
26
- let emptyStrings = try parseEmptyStringsDictFile ( at: url)
30
+ let emptyStrings = try parseEmptyStringsDictFile ( at: url, with : exceptions )
27
31
if !emptyStrings. isEmpty {
28
32
missingStrings [ url. pathComponents [ max ( 0 , url. pathComponents. count - 2 ) ] , default: [ ] ] . append ( contentsOf: emptyStrings)
29
33
}
@@ -41,21 +45,26 @@ if !missingStrings.isEmpty {
41
45
print ( " No missing strings in project " )
42
46
}
43
47
44
- func parseEmptyStringsFile( at url: URL ) throws -> [ String ] {
48
+ func parseExceptionKeys( at url: URL ) throws -> Set < String > {
49
+ let strings = try String ( contentsOf: url) . components ( separatedBy: . newlines)
50
+ return Set ( strings)
51
+ }
52
+
53
+ func parseEmptyStringsFile( at url: URL , with exceptions: Set < String > ) throws -> [ String ] {
45
54
let strings = try String ( contentsOf: url) . components ( separatedBy: . newlines)
46
55
let keyValues = strings. compactMap { string -> String ? in
47
56
var string = string
48
57
guard string. popLast ( ) == " ; " else { return nil }
49
58
let components = string. components ( separatedBy: " = " ) . map { $0. trimmingCharacters ( in: . whitespaces) . replacingOccurrences ( of: " \" " , with: " " ) }
50
59
guard components. count == 2 else { return nil }
51
- guard !components[ 0 ] . isEmpty else { return nil }
60
+ guard !components[ 0 ] . isEmpty, !exceptions . contains ( components [ 0 ] ) else { return nil }
52
61
guard components [ 1 ] . isEmpty else { return nil }
53
62
return components [ 0 ]
54
63
}
55
64
return keyValues
56
65
}
57
66
58
- func parseEmptyStringsDictFile( at url: URL ) throws -> [ String ] {
67
+ func parseEmptyStringsDictFile( at url: URL , with exceptions : Set < String > ) throws -> [ String ] {
59
68
struct StringsDictionaryValue : Decodable {
60
69
struct Format : Decodable {
61
70
var NSStringFormatSpecTypeKey : String
@@ -78,7 +87,7 @@ func parseEmptyStringsDictFile(at url: URL) throws -> [String] {
78
87
dictionary. format. many? . isEmpty != true ,
79
88
dictionary. format. few? . isEmpty != true
80
89
else {
81
- return key
90
+ return exceptions . contains ( key ) ? nil : key
82
91
}
83
92
return nil
84
93
}
0 commit comments