Skip to content

Commit b85d7c8

Browse files
author
Nikos Vasileiou
authored
Merge pull request #64 from stelabouras/feature/substitutions-device-rules
Full String Catalog support
2 parents 4490b3e + 4fd48bc commit b85d7c8

File tree

6 files changed

+1048
-57
lines changed

6 files changed

+1048
-57
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,11 @@ bundled source locale translations, in case the target translations was not
109109
found, was trying to access the file by using the format that Transifex uses
110110
(e.g. `en_US`) instead of the one that iOS and Xcode use (e.g. `en-US`). The
111111
logic now normalizes the locale name to match the format that iOS accepts.
112+
113+
## Transifex iOS SDK 2.0.2
114+
115+
*May 29, 2024*
116+
117+
- Adds full support for String Catalogs support.
118+
- Adds support for substitution phrases on old Strings Dictionary file format.
119+
- Updates unit tests.

Sources/Transifex/Cache.swift

+28-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,34 @@ public final class TXDiskCacheProvider: NSObject, TXCacheProvider {
173173
return nil
174174
}
175175

176-
return storedTranslations
176+
return filterXMLPlurals(storedTranslations)
177+
}
178+
179+
// Process XML stored translations (device variations, substitutions, etc).
180+
private static func filterXMLPlurals(_ translations: TXTranslations?) -> TXTranslations? {
181+
guard var translations = translations else {
182+
return nil
183+
}
184+
for (localeKey, localeStrings) in translations {
185+
for (sourceStringKey, stringInfo) in localeStrings {
186+
guard let sourceString = stringInfo[TXDecoratorCache.STRING_KEY] else {
187+
continue
188+
}
189+
// Detect if the string begins with the CDS root XML tag:
190+
// `<cds-root>`
191+
if (!sourceString.hasPrefix("<\(TXNative.CDS_XML_ROOT_TAG_NAME)>")) {
192+
continue
193+
}
194+
// Process it and synthesize the final rule.
195+
guard let processedString = XMLPluralParser.extract(pluralString: sourceString) else {
196+
Logger.error("\(#function) Error attempting to extract source string with key \(sourceStringKey)")
197+
continue
198+
}
199+
// Replace the source string with the processed value
200+
translations[localeKey]?[sourceStringKey]?[TXDecoratorCache.STRING_KEY] = processedString
201+
}
202+
}
203+
return translations
177204
}
178205

179206
public func getTranslations() -> TXTranslations? {

Sources/Transifex/Core.swift

+14-2
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,23 @@ render '\(stringToRender)' locale code: \(localeCode) params: \(params). Error:
361361
/// A static class that is the main point of entry for all the functionality of Transifex Native throughout the SDK.
362362
public final class TXNative : NSObject {
363363
/// The SDK version
364-
internal static let version = "2.0.1"
364+
internal static let version = "2.0.2"
365365

366366
/// The filename of the file that holds the translated strings and it's bundled inside the app.
367367
public static let STRINGS_FILENAME = "txstrings.json"
368-
368+
369+
/// XML name to be used for the root XML element when the pluralization rule is not supported by CDS
370+
/// and has to be uploaded as XML instead of the ICU format.
371+
public static let CDS_XML_ROOT_TAG_NAME = "cds-root"
372+
373+
/// XML name to be used for the child XML elements when the pluralization rule is not supported by
374+
/// CDS and has to be uploaded as XML instead of the ICU format.
375+
public static let CDS_XML_TAG_NAME = "cds-unit"
376+
377+
/// XML attribute to be used in the CDS_XML_TAG_NAME elements when the pluralization rule is not
378+
/// supported by CDS and has to be uploaded as XML instead of the ICU format.
379+
public static let CDS_XML_ID_ATTRIBUTE = "id"
380+
369381
/// An instance of the core class that handles all the work
370382
private static var tx : NativeCore?
371383

0 commit comments

Comments
 (0)