Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localization is working partially #1768

Open
kacpr opened this issue Aug 28, 2024 · 4 comments
Open

Localization is working partially #1768

kacpr opened this issue Aug 28, 2024 · 4 comments
Labels
Enhancement Indicates a new feature request

Comments

@kacpr
Copy link

kacpr commented Aug 28, 2024

Description

Strings in dropin are translated partially.
When shopperLocale is set to:

  • "pl_PL" - strings are translated partially (mix of pl and eng) - see attached screenshots with "pl_PL" suffix
  • "pl-PL" - strings are translated correctly - see attached screenshots with "pl-PL" suffix.

Backend uses sessions integration flow.
Backend set shopperLocale to "pl_PL".
Android app receives CheckoutSession with SessionSetupResponse.shopperLocale set to "pl_PL".

Since strings in dropin are partially translated, I believe there are multiple call sites and methods that try to obtain locale and this flow isn't bulletproof.

Expected behavior (possible solutions):

  • Unify / fix flow of obtaining locale
  • Handle both formats (with "_" and "-") of shopperLocale properly or inform about invalid format
  • Consistent translation

Steps to Reproduce

  1. I am able to consistently reproduce this issue: Yes
  2. Steps to reproduce the issue:
    1. Get CheckoutSession from SessionSetupResponse.createSession()
    2. Create copy of returned CheckoutSession from step i with overwritten SessionSetupResponse.shopperLocale ("pl_PL")
    3. Start payment:
        DropIn.startPayment(
            dropInLauncher = dropInLauncher,
            checkoutSession = checkoutSession,
        )
    
  3. Screenshots:
    "pl_PL" (check Blik z kodem and Karta bankowa):
screen_1_pl_PL screen_2_pl_PL screen_3_pl_PL screen_4_pl_PL

"pl-PL":

screen_1_pl-PL screen_2_pl-PL screen_3_pl-PL screen_4_pl-PL

Code Snippets

Maybe this will be helpful:
during debugging I found that those methods weren't using / returning correct locale:

checkout-core:5.6.0
LocaleUtil
    fun fromLanguageTag(tag: String): Locale {
        return Locale.forLanguageTag(tag)
    }
checkout-core:5.6.0
LocaleProvider
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
class LocaleProvider {

    fun getLocale(context: Context): Locale {
        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            context.resources.configuration.locales[0]
        } else {
            @Suppress("DEPRECATION")
            context.resources.configuration.locale
        }
    }
}
components-core:5.6.0
ContextExtensions:
fun Context.createLocalizedContext(locale: Locale): Context {
    val configuration = resources.configuration
    val newConfig = Configuration(configuration)
    newConfig.setLocale(locale)

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        val localeList = LocaleList(locale)
        LocaleList.setDefault(localeList)
        newConfig.setLocales(localeList)
    }

    return createConfigurationContext(newConfig) ?: this
}

Integration Information

  1. Server-side integration: Sessions
  2. Client-side integration: Drop-in
  3. SDK version: 5.6.0
  4. Android version(s) where issue occurs: API 34
  5. Device model(s) where issue occurs: emulator - pixel 5, google play services, API 34, arm64. System language: polish (default), english (US).

Additional Context

Related issues:
Adyen/adyen-react-native#15
#1558
#680

Keywords: localization, translations, language, resources

@jreij jreij added the Question Indicates issue only requires an answer to a question label Aug 28, 2024
@jreij
Copy link
Collaborator

jreij commented Aug 28, 2024

Hi @kacpr , thanks for reaching out and providing all the details. This is the intended behavior currently, we parse the locale based on Java's Locale forLanguageTag method, which means that pl-PL is the expected format and pl_PL will not parse properly.

Can your backend change the shopperLocale value sent in the /sessions request to pl-PL? That is also the expected format by our API and should solve the issue.

@kacpr
Copy link
Author

kacpr commented Aug 28, 2024

Hi @jreij !
Thank you for the quick response!
Yes, we've already changed it and it's WORKING, however I wanted to point out this problem, because:

  • there are discrepancies between platforms: Android vs iOS - the latter handles both formats (pl_PL, pl-PL) properly
  • part of the dropin components are translated, despite the invalid locale format (pl_PL - attached screenshots)

These beahviors gave us false leads (mixed translations -> checking for overrides; Android vs iOS - searching for bugs in Android) and cost us some time :)

I strongly believe it's possible to fix these discrepancies (e.g. informing about invalid format; fixing mixed translations), which will probably spare some time to other teams and make the dropin more user-friendly :)

@jreij
Copy link
Collaborator

jreij commented Aug 29, 2024

@kacpr good points! It makes sense that we support locales formatted with underscores if the backend and iOS do. We already raised this point internally and we're discussing the best way to solve it. But for now good to hear that using pl-PL works for you.

Thanks again for raising this, I will change this issue into an enhancement and keep it open to provide updates later when it's resolved.

@jreij jreij added Enhancement Indicates a new feature request and removed Question Indicates issue only requires an answer to a question labels Aug 29, 2024
@kacpr
Copy link
Author

kacpr commented Aug 29, 2024

Awesome! Thanks @jreij

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Indicates a new feature request
Projects
None yet
Development

No branches or pull requests

2 participants