phrase / ios-sdk

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

String is not localised when running test plan with multiple configs #45

Closed bill-florio closed 1 year ago

bill-florio commented 2 years ago

When running unit test for multiple languages, the random language config(mostly the first one.) is not localised if Phrase is setup. Current workaround is skill Phrase set up when running unit tests

Screenshot 2022-06-10 at 16 33 34
winkelsdorf commented 2 years ago

Hello @bill-florio,

thank you for your question. I think we need a bit more information here about what you want to achieve and how you are trying to do so.

bill-florio commented 2 years ago

Hello @bill-florio,

thank you for your question. I think we need a bit more information here about what you want to achieve and how you are trying to do so.

  • Is this an UI or an Unit Test? Meaning: are you running in the context of a XCUIApplication or any other Host Runner (e.g. like CocoaPods does for Unit Tests with App Hosts)?

It is a unit test, with SwiftSnapshotTesting library

  • How do you download the translations? Are you waiting for them to be ready and available for the Simulator? e.g. using Nimble and waitFor or any other asynchronous handler?

The project have a copy of localised strings. No waiting for downloading the translations.

winkelsdorf commented 2 years ago

Thank you for the answer and the details.

Then I have a strong guess what is going on:

Missing Preferences

The Phrase SDK stores the list of available translations in the Preferences. This is necessary because we need to know for which distribution which language is available. In the test, this information will most likely be missing and only the translation files will have been copied.

In the RC for version 4.0 these are located in the simulator under the preferences directory, stored as com.phrase.PhraseSDK.Settings.plist. Previously they were stored in the UserDefaults.standard which is you App plist in the Simulator.

It should be noted that the plain Xcode Unit Test XC test runner has its own main bundle - with its own version information (CFBundleShortVersionString) - therefore min/max version may be invalid for RC 4 of our SDK. And of course the Main Bundle does not contain any translations included in the App's Main Bundle.

Wrong Location

If the test/project has a copy of the translations and depending on what is to be tested, the translations are either for Xcode XC/XCUITest in the wrong directory or for the Phrase SDK: Our SDK needs the translations in its own data directory. Xcode needs them in the App Bundle.

If you ship the translations with your App in the bundle, there is no need to invoke Phrase Methods during the tests at all: The System methods will pick up the correct localizations.

If you (indirectly) use Phrase methods in your Tests, you will need to have 1) valid Preferences (think of getting them from a valid Simulator run and insert them in a Test via UserDefaults methods). 2) the localizations in the correct data folder.

Hint: Settings and Data folder might differ between v3.0.1 and the 4.0.1-rc.1, but both are located in the app Preferences and Application Support.

E.g. for RC 4:

[Simulator Path]/Library/Preferences/com.phrase.PhraseSDK.Settings.plist
[Simulator Path]/Library/Application Support/com.phrase.phraseSDK/Translations/en.lproj/Localizable.strings
[Simulator Path]/Library/Application Support/com.phrase.phraseSDK/Translations/en.lproj/Localizable.stringsdict

hth!

forelabs commented 1 year ago

Closing due to inactivity.