Skip to content

Commit

Permalink
feat(GiniBankSDK): Set localized strings from the correct bundle
Browse files Browse the repository at this point in the history
PIA-2548
  • Loading branch information
ValentinaIancu-Gini committed Aug 30, 2023
1 parent 6744da1 commit 7443011
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions BankSDK/GiniBankSDK/Sources/GiniBankSDK/Core/GiniBankUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,52 @@ func NSLocalizedStringPreferredGiniBankFormat(_ key: String,
fallbackKey: String = "",
comment: String,
isCustomizable: Bool = true) -> String {
var clientString: String
var fallbackClientString: String
if isCustomizable {
if let clientLocalizedStringMainBundle = clientLocalizedString(key, fallbackKey: fallbackKey, comment: comment, bundle: .main) {

return clientLocalizedStringMainBundle

} else if let customBundle = GiniBankConfiguration.shared.customResourceBundle,
let clientLocalizedStringCustomBundle = clientLocalizedString(key, fallbackKey: fallbackKey, comment: comment, bundle: customBundle) {

return clientLocalizedStringCustomBundle
}
}

return giniLocalizedString(key, fallbackKey: fallbackKey, comment: comment)
}

private func clientLocalizedString(_ key: String,
fallbackKey: String,
comment: String,
bundle: Bundle) -> String? {
var clientString = NSLocalizedString(key, bundle: bundle, comment: comment)
var fallbackClientString = NSLocalizedString(fallbackKey,bundle: bundle, comment: comment)

if let localizedResourceName = GiniBankConfiguration.shared.localizedStringsTableName {
clientString = NSLocalizedString(key, tableName: localizedResourceName, comment: comment)
fallbackClientString = NSLocalizedString(fallbackKey,tableName: localizedResourceName, comment: comment)
} else {
clientString = NSLocalizedString(key, comment: comment)
fallbackClientString = NSLocalizedString(fallbackKey, comment: comment)
clientString = NSLocalizedString(key, tableName: localizedResourceName, bundle: bundle, comment: comment)
fallbackClientString = NSLocalizedString(fallbackKey,tableName: localizedResourceName, bundle: bundle, comment: comment)
}

guard (clientString.lowercased() != key.lowercased() || fallbackClientString.lowercased() != fallbackKey.lowercased()) else {
return nil
}

return clientString
}

let format: String
private func giniLocalizedString(_ key: String,
fallbackKey: String,
comment: String) -> String {
let bundle = giniBankBundle()

if (clientString.lowercased() != key.lowercased() || fallbackClientString.lowercased() != fallbackKey.lowercased())
&& isCustomizable {
format = clientString
} else {
let bundle = giniBankBundle()
var defaultFormat = NSLocalizedString(key, bundle: bundle, comment: comment)

if defaultFormat.lowercased() == key.lowercased() {
defaultFormat = NSLocalizedString(fallbackKey, bundle: bundle, comment: comment)
}

format = defaultFormat
var defaultFormat = NSLocalizedString(key, bundle: bundle, comment: comment)

if defaultFormat.lowercased() == key.lowercased() {
defaultFormat = NSLocalizedString(fallbackKey, bundle: bundle, comment: comment)
}

return format
return defaultFormat
}

func giniBankBundle() -> Bundle {
Expand Down

0 comments on commit 7443011

Please sign in to comment.