-
Notifications
You must be signed in to change notification settings - Fork 822
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Strings Catalogs (Xcode 15) (#1421)
* Support for xcode 15 string catalogs * Add sample string catalog to Test Fixture and basic test to check that asset catalogs are added in the resources build phase * Restore unintended changes * Update Pull Request number for 'Support for Strings Catalogs' in changelog * Update fixture yml generator * Detect knownRegions based on locales in string catalogs
- Loading branch information
1 parent
2c15007
commit 2881fcc
Showing
9 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import Foundation | ||
import JSONUtilities | ||
import PathKit | ||
|
||
struct StringCatalog { | ||
|
||
/** | ||
* Sample string catalog: | ||
|
||
* { | ||
* "sourceLanguage" : "en", | ||
* "strings" : { | ||
* "foo" : { | ||
* "localizations" : { | ||
* "en" : { | ||
* ... | ||
* }, | ||
* "es" : { | ||
* ... | ||
* }, | ||
* "it" : { | ||
* ... | ||
* } | ||
* } | ||
* } | ||
* } | ||
* } | ||
*/ | ||
|
||
private struct CatalogItem { | ||
private enum JSONKeys: String { | ||
case localizations | ||
} | ||
|
||
private let key: String | ||
let locales: Set<String> | ||
|
||
init?(key: String, from jsonDictionary: JSONDictionary) { | ||
guard let localizations = jsonDictionary[JSONKeys.localizations.rawValue] as? JSONDictionary else { | ||
return nil | ||
} | ||
|
||
self.key = key | ||
self.locales = Set(localizations.keys) | ||
} | ||
} | ||
|
||
private enum JSONKeys: String { | ||
case strings | ||
} | ||
|
||
private let strings: [CatalogItem] | ||
|
||
init?(from path: Path) { | ||
guard let catalogDictionary = try? JSONDictionary.from(url: path.url), | ||
let catalog = StringCatalog(from: catalogDictionary) else { | ||
return nil | ||
} | ||
|
||
self = catalog | ||
} | ||
|
||
private init?(from jsonDictionary: JSONDictionary) { | ||
guard let stringsDictionary = jsonDictionary[JSONKeys.strings.rawValue] as? JSONDictionary else { | ||
return nil | ||
} | ||
|
||
self.strings = stringsDictionary.compactMap { key, value -> CatalogItem? in | ||
guard let stringDictionary = value as? JSONDictionary else { | ||
return nil | ||
} | ||
|
||
return CatalogItem(key: key, from: stringDictionary) | ||
} | ||
} | ||
|
||
var includedLocales: Set<String> { | ||
strings.reduce(Set<String>(), { partialResult, catalogItem in | ||
partialResult.union(catalogItem.locales) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Tests/Fixtures/TestProject/String Catalogs/Localizable.xcstrings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"sourceLanguage" : "en", | ||
"strings" : { | ||
"sampleText" : { | ||
"comment" : "Sample string in an asset catalog", | ||
"extractionState" : "manual", | ||
"localizations" : { | ||
"en" : { | ||
"stringUnit" : { | ||
"state" : "translated", | ||
"value" : "This is a localized string" | ||
} | ||
}, | ||
"es" : { | ||
"stringUnit" : { | ||
"state" : "translated", | ||
"value" : "Esta es una cadena de texto localizable." | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"version" : "1.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters