phrase / ios-sdk

Phrase Over the Air iOS SDK
https://phrase.com
Other
14 stars 3 forks source link

Fallback issue when using `Phrase.shared.localizedString` #73

Open Liquidsoul opened 1 month ago

Liquidsoul commented 1 month ago

Hi,

I hope this is the right place to report this issue we have with the behavior of Phrase.localizedString.

Context

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

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.

carstenapploft commented 1 month ago

hi,

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

carstenapploft commented 1 month ago

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

carstenapploft commented 1 month ago

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.