@@ -60,7 +60,7 @@ struct StringsGenerator: Generator {
60
60
// Maybe when we pick up this issue: https://github.com/mac-cain13/R.swift/issues/136
61
61
private static func computeParams( filename: String , strings: [ LocalizableStrings ] ) -> [ StringValues ] {
62
62
63
- var allParams : [ String : [ ( Locale , String , [ StringParam ] ) ] ] = [ : ]
63
+ var allParams : [ String : [ ( Locale , LocalizableStrings . Entry ) ] ] = [ : ]
64
64
let baseKeys : Set < String > ?
65
65
let bases = strings. filter { $0. locale. isBase }
66
66
if bases. isEmpty {
@@ -95,10 +95,10 @@ struct StringsGenerator: Generator {
95
95
for key in groupedKeys. uniques {
96
96
if let entry = byKey [ key] {
97
97
if let _ = allParams [ key] {
98
- allParams [ key] ? . append ( ( ls. locale, entry. val , entry . params ) )
98
+ allParams [ key] ? . append ( ( ls. locale, entry) )
99
99
}
100
100
else {
101
- allParams [ key] = [ ( ls. locale, entry. val , entry . params ) ]
101
+ allParams [ key] = [ ( ls. locale, entry) ]
102
102
}
103
103
}
104
104
}
@@ -138,8 +138,8 @@ struct StringsGenerator: Generator {
138
138
var params : [ StringParam ] = [ ]
139
139
var areCorrectFormatSpecifiers = true
140
140
141
- for (locale, _ , ps ) in keyParams {
142
- if ps . any ( { $0. spec == FormatSpecifier . TopType } ) {
141
+ for (locale, entry ) in keyParams {
142
+ if entry . params . any ( { $0. spec == FormatSpecifier . TopType } ) {
143
143
let name = locale. withFilename ( filename)
144
144
warn ( " Skipping string \( key) in \( name) , not all format specifiers are consecutive " )
145
145
@@ -149,8 +149,8 @@ struct StringsGenerator: Generator {
149
149
150
150
if !areCorrectFormatSpecifiers { continue }
151
151
152
- for (_, _ , ps ) in keyParams {
153
- if let unified = params. unify ( ps ) {
152
+ for (_, entry ) in keyParams {
153
+ if let unified = params. unify ( entry . params ) {
154
154
params = unified
155
155
}
156
156
else {
@@ -162,8 +162,9 @@ struct StringsGenerator: Generator {
162
162
163
163
if !areCorrectFormatSpecifiers { continue }
164
164
165
- let vals = keyParams. map { ( $0. 0 , $0. 1 ) }
166
- let values = StringValues ( key: key, params: params, tableName: filename, values: vals )
165
+ let vals = keyParams. map { locale, entry in ( locale, entry. val) }
166
+ let comments = keyParams. map { locale, entry in ( locale, entry. comment) }
167
+ let values = StringValues ( key: key, params: params, tableName: filename, values: vals, entryComments: comments)
167
168
results. append ( values)
168
169
}
169
170
@@ -273,6 +274,7 @@ private struct StringValues {
273
274
let params : [ StringParam ]
274
275
let tableName : String
275
276
let values : [ ( Locale , String ) ]
277
+ let entryComments : [ ( Locale , String ? ) ]
276
278
277
279
var localizedString : String {
278
280
let escapedKey = key. escapedStringLiteral
@@ -317,6 +319,22 @@ private struct StringValues {
317
319
let locales = values. flatMap { $0. 0 . localeDescription }
318
320
results. append ( " Locales: \( locales. joinWithSeparator ( " , " ) ) " )
319
321
}
322
+
323
+ let baseEntryComment = entryComments. filter { $0. 0 . isBase } . flatMap { $0. 1 } . first
324
+ if let baseEntryComment = baseEntryComment {
325
+ if !results. isEmpty {
326
+ results. append ( " " )
327
+ }
328
+
329
+ let lines = baseEntryComment. componentsSeparatedByString ( " \n " )
330
+ if lines. count == 1 {
331
+ results. append ( " Comment: \( lines [ 0 ] ) " )
332
+ } else {
333
+ results. append ( " Comment: " )
334
+ let indented = lines. map { " \( $0) " }
335
+ results. appendContentsOf ( indented)
336
+ }
337
+ }
320
338
321
339
return results
322
340
}
0 commit comments