Files
GLEGram-iOS/third-party/XcodeGen/Sources/XcodeGenKit/StringCatalogDecoding.swift
T
Leeksov 4647310322 GLEGram 12.5 — Initial public release
Based on Swiftgram 12.5 (Telegram iOS 12.5).
All GLEGram features ported and organized in GLEGram/ folder.

Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass,
Font Replacement, Fake Profile, Chat Export, Plugin System, and more.

See CHANGELOG_12.5.md for full details.
2026-04-06 09:48:12 +03:00

83 lines
2.1 KiB
Swift

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)
})
}
}