ios-sdk icon indicating copy to clipboard operation
ios-sdk copied to clipboard

Fallback issue when using `Phrase.shared.localizedString`

Open Liquidsoul opened this issue 1 year ago • 3 comments

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 updateTranslation at app launch
  • PhraseSDKMainBundleProxyDisabled is 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 uses Bundle.localizedString

Steps

  1. A new key was added to the project but not yet included in the OTA release.
  2. Pull the Localizable.strings file into an app
  3. Call Phrase.shared.localizedString on the new key

Result

  • Calling Phrase.shared.localizedString(forKey: "your.new.key", value: "fallback", table: "Localizable") returns fallback
  • 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.

Liquidsoul avatar Jul 23 '24 08:07 Liquidsoul

hi,

I'll discuss the topic with the team. I'll give an update in the middle of next week.

carstenapploft avatar Jul 24 '24 09:07 carstenapploft

Hi, I haven't had the chance to talk to the team yet, so the feedback won't come until next week.

carstenapploft avatar Jul 31 '24 12:07 carstenapploft

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.

carstenapploft avatar Aug 06 '24 08:08 carstenapploft