Fallback issue when using `Phrase.shared.localizedString`
Hi,
I hope this is the right place to report this issue we have with the behavior of Phrase.localizedString.
Context
- version : 4.4.1
- we pull the translations offline to embed them in Localizable.strings files
- OTA is in place with a
updateTranslationat app launch PhraseSDKMainBundleProxyDisabledis set to YES in Info.plist- Swiftgen is used to generate code to access the l10n keys with a custom implementation that uses
Phrase.shared.localizedString()instead of SwitfGen default's implementation that usesBundle.localizedString
Steps
- A new key was added to the project but not yet included in the OTA release.
- Pull the Localizable.strings file into an app
- Call
Phrase.shared.localizedStringon the new key
Result
- Calling
Phrase.shared.localizedString(forKey: "your.new.key", value: "fallback", table: "Localizable")returnsfallback - Calling the OS
Bundle.main.localizedString(forKey: "your.new.key", value: "fallback", table: "Localizable")returns the translated key in the device's language
The behavior of Phrase.localizedString does not match the behavior of the Bundle.localizedString and that triggers the fallback that is not in the device's language. We expect that Phrase uses the default implementation of the OS so that it shows the correct strings to the user and not the fallback value when no translation is found.
Thank you in advance for your time on this.
hi,
I'll discuss the topic with the team. I'll give an update in the middle of next week.
Hi, I haven't had the chance to talk to the team yet, so the feedback won't come until next week.
Hi @Liquidsoul ,
I've spoken to the team. We have a fallback to the translations in the main bundle if the key was not found and if no fallback was set. So if the fallback is nil, the SDK will pull the translation from the main bundle.
As an alternative, we suggest extending the swiftgen script to pass the translation from the main bundle as fallback.
Phrase.shared.localizedString(
forKey: "your.new.key",
value: Bundle.main.localizedString(forKey: "your.new.key", value: "fallback", table: "Localizable"),
table: "Localizable"
)
At the moment, we would not make any adjustments to the SDK, as the current implementation gives the user a certain degree of flexibility.