adyen-ios
adyen-ios copied to clipboard
Localization does not work trivially
Describe the bug The documentation of how to use localization is a little lacking, and trying it in the obvious way does not work.
To get it working, I needed to do (trial and error, perhaps there is a better way):
let adyenPath = Bundle.main.path(forResource: "Adyen", ofType: "bundle")!
let adyenBundle = Bundle(path: adyenPath)!
let localizedBundle: Bundle
if let localizedPath = adyenBundle.path(forResource: locale, ofType: "lproj") {
localizedBundle = Bundle(path: localizedPath)!
} else {
localizedBundle = adyenBundle
}
configuration.localizationParameters = LocalizationParameters(bundle: localizedBundle, locale: locale)
I would have expected to just have been able to do
configuration.localizationParameters = LocalizationParameters(locale: locale)
and it should automatically pick the default Adyen translations bundle.
I'm using cocoapods if that matters.
Hey @erik-kallen
Thanks for reaching out!
To make custom localisation you need to use your own Bundle (example Bundle.main
):
configuration.localizationParameters = LocalizationParameters(bundle: Bundle.main)
UPD
SDK uses iOS default localisation engine - picks up localization file based on phone's locale. If you want to enforce the locale - you can follow this guidance
I don't understand what you mean. The Podspec for the Core package includes a resource_bundles
statement to create a bundle with all the default translations, and this bundle has to be identified in order for the localization to work. It would make sense to me that this bundle could be found automatically.
I don't want custom localization, I want the built-in translations.
Hey @erik-kallen
For example: So if you want Spanish translation on device with Spanish locale - you don't need to do anything. If you want Spanish translation on device with French locale - there are 2 ways:
a) keep doing what you are doing;
b) Copy our Localizable.strings to your project as "XXX.strings", then reference it with LocalizationParameters(tableName: "XXX")
UPD
I would have expected to just have been able to do
configuration.localizationParameters = LocalizationParameters(locale: locale)
We will investigate if we can improve this in v5..
What, then, is the purpose of configuration.localizationParameters.locale
if it does not work?
And, as I said, I have a working solution. It was just quite tricky to make it work.
What, then, is the purpose of
configuration.localizationParameters.locale
if it does not work?
localizationParameters.locale
is used to enforce locale for everything but translation - amounts, dates e.t.c
And, as I said, I have a working solution. It was just quite tricky to make it work.
TBH, your solution seems easier than we thought it would be - it inspires us to make some research :) Thanks for feedback! We will investigate further improvement..
Enforced locale was added on v5.3.0