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

Localization does not work trivially

Open erik-kallen opened this issue 2 years ago • 5 comments

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.

erik-kallen avatar Apr 28 '22 14:04 erik-kallen

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

descorp avatar Apr 28 '22 14:04 descorp

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.

erik-kallen avatar Apr 28 '22 14:04 erik-kallen

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..

descorp avatar Apr 28 '22 23:04 descorp

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.

erik-kallen avatar Apr 29 '22 07:04 erik-kallen

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..

descorp avatar Apr 29 '22 09:04 descorp

Enforced locale was added on v5.3.0

descorp avatar Aug 28 '23 16:08 descorp