@@ -13,23 +13,26 @@ import Foundation
1313class LocalizationProvider {
1414 private let ignoredDirectories = [ " Carthage " , " build " , " .framework " ]
1515
16- func getLocalizations( url: URL ) -> [ Localization ] {
16+ func getLocalizations( url: URL ) -> [ LocalizationGroup ] {
1717 Log . debug? . message ( " Searching \( url) for Localizable.strings " )
1818
1919 guard let folder = try ? Folder ( path: url. path) else {
2020 return [ ]
2121 }
2222
23- let localizationFiles = folder. makeFileSequence ( recursive: true ) . filter { file in
24- return file. name == " Localizable .strings" && ignoredDirectories. map ( { file. path. contains ( " \( $0) / " ) } ) . filter ( { $0} ) . count == 0
25- }
26-
23+ let localizationFiles = Dictionary ( grouping : folder. makeFileSequence ( recursive: true ) . filter { file in
24+ return file. name. hasSuffix ( " .strings " ) && ignoredDirectories. map ( { file. path. contains ( " \( $0) / " ) } ) . filter ( { $0} ) . count == 0
25+ } , by : { $0 . path . components ( separatedBy : " / " ) . filter ( { !$0 . hasSuffix ( " .lproj " ) } ) . joined ( separator : " / " ) } )
26+
2727 Log . debug? . message ( " Found \( localizationFiles) localization files " )
28-
29- return localizationFiles. map ( { file in
30- let parts = file. path. split ( separator: " / " )
31- let lang = String ( parts [ parts. count - 2 ] ) . replacingOccurrences ( of: " .lproj " , with: " " )
32- return Localization ( language: lang, translations: getLocalizationStrings ( path: file. path) , path: file. path)
28+
29+ return localizationFiles. map ( { ( path, files) in
30+ let name = URL ( fileURLWithPath: path) . lastPathComponent
31+ return LocalizationGroup ( name: name, localizations: files. map ( { file in
32+ let parts = file. path. split ( separator: " / " )
33+ let lang = String ( parts [ parts. count - 2 ] ) . replacingOccurrences ( of: " .lproj " , with: " " )
34+ return Localization ( language: lang, translations: getLocalizationStrings ( path: file. path) , path: file. path)
35+ } ) , path: path)
3336 } )
3437 }
3538
0 commit comments