@@ -14,22 +14,25 @@ import Foundation
14
14
public func parseAndValidateXCStrings(
15
15
base: File ,
16
16
translation: File ,
17
+ baseLanguageName: String ,
17
18
translationLanguageName: String ,
18
19
problemReporter: ProblemReporter ) {
19
- let collectLines = { ( file: File , baseStringMap: [ String : FormatString ] ) -> [ LocalizedStringPair ] in
20
+ let collectLines = { ( file: File , isBase : Bool , baseStringMap: [ String : FormatString ] ) -> [ LocalizedStringPair ] in
20
21
file. lo_getLines ( problemReporter: problemReporter) ?
21
22
. enumerated ( )
22
23
. compactMap {
23
24
LocalizedStringPair (
24
25
string: $0. 1 ,
25
26
path: file. path,
26
27
line: $0. 0 + 1 ,
28
+ basePath: base. path,
29
+ baseLineFallback: isBase ? $0. 0 + 1 : 0 ,
27
30
baseStringMap: baseStringMap)
28
31
} ?? [ ]
29
32
}
30
33
31
34
// Compare similarly-named files 1-to-1
32
- let baseStrings : [ LocalizedStringPair ] = collectLines ( base, [ : ] )
35
+ let baseStrings : [ LocalizedStringPair ] = collectLines ( base, true , [ : ] )
33
36
guard !baseStrings. isEmpty else { return }
34
37
35
38
let baseStringMap = baseStrings. lo_makeDictionary (
@@ -42,10 +45,11 @@ public func parseAndValidateXCStrings(
42
45
lineNumber: value. line)
43
46
} )
44
47
45
- let translationStrings = collectLines ( translation, baseStringMap)
48
+ let translationStrings = collectLines ( translation, false , baseStringMap)
46
49
validateStrings (
47
50
baseStrings: baseStrings,
48
51
translationStrings: translationStrings,
52
+ baseLanguageName: baseLanguageName,
49
53
translationLanguageName: translationLanguageName,
50
54
problemReporter: problemReporter)
51
55
}
@@ -57,6 +61,7 @@ public func parseAndValidateXCStrings(
57
61
func validateStrings(
58
62
baseStrings: [ LocalizedStringPair ] ,
59
63
translationStrings: [ LocalizedStringPair ] ,
64
+ baseLanguageName: String ,
60
65
translationLanguageName: String ,
61
66
problemReporter: ProblemReporter ) {
62
67
// MARK: Ensure all base strings appear in this translation
@@ -128,7 +133,38 @@ func validateStrings(
128
133
129
134
let baseArgs = translationString. base. arguments. sorted ( by: { $0. position < $1. position } )
130
135
136
+ if baseArgs. count > 1 {
137
+ for arg in baseArgs where !arg. isPositionExplicit {
138
+ // This might be reported multiple times, but it's deduped
139
+ problemReporter. report (
140
+ StringHasImplicitPosition (
141
+ base: translationString. base. string,
142
+ translation: translationString. base. string,
143
+ key: translationString. key,
144
+ value: translationString. base. string,
145
+ position: arg. position,
146
+ language: baseLanguageName,
147
+ suggestion: arg. asExplicit) ,
148
+ path: translationString. base. path,
149
+ lineNumber: translationString. base. line)
150
+ }
151
+ }
152
+
131
153
for arg in translationString. translation. arguments {
154
+ if !arg. isPositionExplicit && translationString. translation. arguments. count > 1 {
155
+ problemReporter. report (
156
+ StringHasImplicitPosition (
157
+ base: translationString. base. string,
158
+ translation: translationString. translation. string,
159
+ key: translationString. key,
160
+ value: translationString. translation. string,
161
+ position: arg. position,
162
+ language: translationLanguageName,
163
+ suggestion: arg. asExplicit) ,
164
+ path: translationString. path,
165
+ lineNumber: translationString. line)
166
+ }
167
+
132
168
guard let baseArg = baseArgs. first ( where: { $0. position == arg. position } ) else {
133
169
continue // we already logged an error for this above
134
170
}
0 commit comments