Skip to content

Commit

Permalink
Merge pull request #64 from stelabouras/feature/substitutions-device-…
Browse files Browse the repository at this point in the history
…rules

Full String Catalog support
  • Loading branch information
Nikos Vasileiou authored May 29, 2024
2 parents 4490b3e + 4fd48bc commit b85d7c8
Show file tree
Hide file tree
Showing 6 changed files with 1,048 additions and 57 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,11 @@ bundled source locale translations, in case the target translations was not
found, was trying to access the file by using the format that Transifex uses
(e.g. `en_US`) instead of the one that iOS and Xcode use (e.g. `en-US`). The
logic now normalizes the locale name to match the format that iOS accepts.

## Transifex iOS SDK 2.0.2

*May 29, 2024*

- Adds full support for String Catalogs support.
- Adds support for substitution phrases on old Strings Dictionary file format.
- Updates unit tests.
29 changes: 28 additions & 1 deletion Sources/Transifex/Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,34 @@ public final class TXDiskCacheProvider: NSObject, TXCacheProvider {
return nil
}

return storedTranslations
return filterXMLPlurals(storedTranslations)
}

// Process XML stored translations (device variations, substitutions, etc).
private static func filterXMLPlurals(_ translations: TXTranslations?) -> TXTranslations? {
guard var translations = translations else {
return nil
}
for (localeKey, localeStrings) in translations {
for (sourceStringKey, stringInfo) in localeStrings {
guard let sourceString = stringInfo[TXDecoratorCache.STRING_KEY] else {
continue
}
// Detect if the string begins with the CDS root XML tag:
// `<cds-root>`
if (!sourceString.hasPrefix("<\(TXNative.CDS_XML_ROOT_TAG_NAME)>")) {
continue
}
// Process it and synthesize the final rule.
guard let processedString = XMLPluralParser.extract(pluralString: sourceString) else {
Logger.error("\(#function) Error attempting to extract source string with key \(sourceStringKey)")
continue
}
// Replace the source string with the processed value
translations[localeKey]?[sourceStringKey]?[TXDecoratorCache.STRING_KEY] = processedString
}
}
return translations
}

public func getTranslations() -> TXTranslations? {
Expand Down
16 changes: 14 additions & 2 deletions Sources/Transifex/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,23 @@ render '\(stringToRender)' locale code: \(localeCode) params: \(params). Error:
/// A static class that is the main point of entry for all the functionality of Transifex Native throughout the SDK.
public final class TXNative : NSObject {
/// The SDK version
internal static let version = "2.0.1"
internal static let version = "2.0.2"

/// The filename of the file that holds the translated strings and it's bundled inside the app.
public static let STRINGS_FILENAME = "txstrings.json"


/// XML name to be used for the root XML element when the pluralization rule is not supported by CDS
/// and has to be uploaded as XML instead of the ICU format.
public static let CDS_XML_ROOT_TAG_NAME = "cds-root"

/// XML name to be used for the child XML elements when the pluralization rule is not supported by
/// CDS and has to be uploaded as XML instead of the ICU format.
public static let CDS_XML_TAG_NAME = "cds-unit"

/// XML attribute to be used in the CDS_XML_TAG_NAME elements when the pluralization rule is not
/// supported by CDS and has to be uploaded as XML instead of the ICU format.
public static let CDS_XML_ID_ATTRIBUTE = "id"

/// An instance of the core class that handles all the work
private static var tx : NativeCore?

Expand Down
Loading

0 comments on commit b85d7c8

Please sign in to comment.