Open judithgomezlorenzo opened 1 month ago
Hi, I need some more information about the language change process.
Do you change the language in the Apple Settings or do you use another method?
Can you describe this in a more detail?
Hello,
Inside our app we have direct access to the Apple settings to change the language. We support English (US, CA, UK), French, German and Spanish.
To give you more details:
I hope this explanation has enough detail for you.
Thank you,
Hi @judithgomezlorenzo ,
sorry for the late response(another task required more time).
Do you use english default values in the calls to Phrase.shared.localizedString
?
It is possible that the defaults will be returned as long as we download the translations.
Example:
Phrase.shared.localizedString(forKey: "your_translation_key", value: "the_english_text_as_fallback", table: "Localizable")
The order in which we determine the translation is as follows:
That can explain why the translations are always in English after a language change.
And why NSLocalizedString works, maybe you have disabled "PhraseSDKMainBundleProxyDisabled" in the Info.plist? In this case, NSLocalizedString always returns the translations from the app bundle.
One more question about changing the language. You said you have direct access to the Apple settings to change the language. But you didn't mean the UserDefauls, right?
The app is restarted after changing the language?
Hi @carstenapploft,
No worries.
The app is restarted after changing the language, we do it through Apple settings, not User Defaults.
The PhraseSDKMainBundleProxyDisabled
key is set to YES
.
We don't use english default values when calling Phrase.shared.localizedString
, we have an extension to localise any string like:
func localized() -> String {
return Phrase.shared.localizedString(forKey: self, value: nil, table: nil)
}
We call Phrase.shared.updateTranslation
inside the AppDelegate on app launch and we also try to override the locale with Phrase.shared.configuration.localeOverride
but without luck.
hi,
there is a case where we fall back to the "Base.lproj" translations if no bundle could be created for the selected language. Can you check whether this code returns a valid URL in the app and whether the url is also a directory?
extension URL {
var isDirectory: Bool {
(try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true
}
}
// inside your app(e.g. AppDelegate)
let languageCode: String = Bundle.main.preferredLocalizations.first!
let modifiedLanguageCode = languageCode.replacingOccurrences(of: "_", with: "-")
let languageURL = Bundle.main.url(forResource: modifiedLanguageCode, withExtension: "lproj")
print(languageURL)
print(languageURL?.isDirectory)
Hello,
After running the above piece of code:
Optional(file:///Users/judith/Library/Developer/CoreSimulator/Devices/59D49403-21E3-49EE-9639-9EC6AEC38359/data/Containers/Bundle/Application/ECC48499-0152-49B3-BF91-B972CDD4E3B0/x.app/en-GB.lproj/)
Optional(true)
Optional(file:///private/var/containers/Bundle/Application/BEF9FCCA-2DC5-4E4A-9C8A-57AD4BD48D08/x.app/en-GB.lproj/)
Optional(true)
Hello @judithgomezlorenzo , thanks for trying. I still assume there is a problem with pulling the fallback translations from the app bundle. Can you also run the code once after you have changed the language? (e.g. from English to German).
Can you tell me if the translations are also in English after you change the language between non-English languages? (e.g. from German to French)
If I'm right and the problem is in the fallback translation and you say NSLocalizedString works, then you can specify NSLocalizedString as a fallback and it should work(as a workaround).
func localized() -> String {
return Phrase.shared.localizedString(
forKey: self,
value: NSLocalizedString(self, comment: ""),
table: nil
)
}
Hi @carstenapploft,
Sorry for the late reply, I have been out of town these days.
If I change the localized
method as you suggested, when I change the language from English to German, then the app seems to restart in German, but once the LaunchScreen is dismissed, the app is translated back to English.
If I switch from German to French, the same thing happens, the LaunchScreen is in French, but then the app is in English.
Hi @judithgomezlorenzo , too bad that this did not work out. I had been trying to recreate the problem for the last few days, but without success.
We should check the API calls that are sent from SDK. Maybe the server always returns English translations. Please use Charles (or a similar tool) to check whether the correct translation are returned.
The first URL should look like this(this will redirect to the second url):
https://ota.eu.phrase.com/<id>/<secret>/en/strings?client=iOS&platform_version=<iosVersion>&sdk_version=4.4.1&app_version=1.0.0&device_identifier=<id>
And the second url should look like this and contains the translations:
https://cdn.phraseapp.com/ota/<id>/strings/en.strings?version=<number>
(You may need to delete the app beforehand so that the cache is removed)
Please do not post your URLs here as they contain api secrets. I will be away next week and be back on 16 September.
You can also submit a bug report here(This allows us to assign the problem to an organization.): https://support.phrase.com/hc/en-us/requests/new
Hi,
We have a problem with Phrase.localizedString or OTA.
Context
Result
Could you help us? Thanks in advance.