Skip to content

Commit

Permalink
Merge pull request #61 from transifex/stelios/fix/language-tag-delimiter
Browse files Browse the repository at this point in the history
Version 2.0.1
  • Loading branch information
Nikos Vasileiou authored Sep 21, 2023
2 parents 12778a7 + 3516590 commit 4490b3e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,13 @@ array.
or empty source string keys.
- `pushTranslations()` now accepts a configuration object that holds any extra
options that might need to be set during the push logic.

## Transifex iOS SDK 2.0.1

*September 21, 2023*

- Addresses language tag discrepancy: The fallback mechanism for accessing the
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.
14 changes: 11 additions & 3 deletions Sources/Transifex/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ public enum TXRenderingStategy : Int {
/// is about to be called.
final class BypassLocalizer {
let bundle : Bundle?


private static let IOS_LANGUAGE_TAG_DELIMITER = "-"
private static let TRANSIFEX_LANGUAGE_TAG_DELIMITER = "_"

/// Initializes bypass localizer with a certain locale.
///
/// - Parameter localeCode: The locale to be used
init(with localeCode: String) {
/// Ensure that the bundled localized project container will be accessible for the provided locale,
/// as the iOS uses a hyphen for the language tag (e.g. en-GB) while Transifex uses an
/// underscore (e.g. en_GB).
let normalizedLocaleCode = localeCode.replacingOccurrences(of: Self.TRANSIFEX_LANGUAGE_TAG_DELIMITER,
with: Self.IOS_LANGUAGE_TAG_DELIMITER)
/// Get the bundle for the provided locale code, if it exists.
guard let bundlePath = Bundle.main.path(forResource: localeCode,
guard let bundlePath = Bundle.main.path(forResource: normalizedLocaleCode,
ofType: "lproj") else {
self.bundle = nil
return
Expand Down Expand Up @@ -353,7 +361,7 @@ 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.0"
internal static let version = "2.0.1"

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

0 comments on commit 4490b3e

Please sign in to comment.