Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Fix language (DEV) #4792

Merged
merged 11 commits into from
Feb 9, 2022
Merged

Fix language (DEV) #4792

merged 11 commits into from
Feb 9, 2022

Conversation

chiljamgossow
Copy link
Contributor

No description provided.

@chiljamgossow chiljamgossow requested a review from a team February 7, 2022 16:31
mtwalli
mtwalli previously approved these changes Feb 7, 2022
Copy link
Contributor

@mtwalli mtwalli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

mtwalli
mtwalli previously approved these changes Feb 7, 2022
@mtwalli mtwalli self-assigned this Feb 7, 2022
@mtwalli mtwalli added the maintainers Tag pull requests created by maintainers label Feb 7, 2022
@mtwalli mtwalli added this to the 2.18.0 milestone Feb 7, 2022
private fun getLanguage(): String {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
LocaleList.getDefault().getFirstMatch(supportedLanguages)?.language ?: Locale.getDefault().language
val cclLanguage: String by lazy {
Copy link
Contributor

@mtwalli mtwalli Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please check if the language changes when the device language changes while using the App?
I suspect that the value is cached , because this val is for the whole App

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right, it won't change. Getting it each time has impact on performance, so let me find a different solution.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this work?

fun getCclLanguage(): String {
    val currentDeviceLang = Locale.getDefault().language
    if (currentSupportedLang[currentDeviceLang].isNullOrEmpty()) {
        currentSupportedLang[currentDeviceLang] = supportedLang()
    }
    return currentSupportedLang[currentDeviceLang]!!
}

private val currentSupportedLang = mutableMapOf<String, String>()

private fun supportedLang(): String = when {
    Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> {
        LocaleList.getDefault().getFirstMatch(supportedLanguages)?.language
            ?: Locale.getDefault().language.also {
                Timber.d("Using default language $it")
            }
    }
    else -> Locale.getDefault().language
}.also { Timber.d("Language is $it") }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried several things. The only thing that would work is a broadcast receiver for the locale change, but is it worth it? will be reset on next app start, and since we do not calculate the wallet info again, the new language may not be there right away anyway

Copy link
Contributor

@mtwalli mtwalli Feb 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using map as above did not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the setting is Spanish, English, German, the app will be in English
If the setting is Spanish, German, English, the app will be in German
getDefault will return Spanish in both cases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until walletInfo is recalculated, the new language is not available anyway, so it may even be worse to update immediately

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean to update on locale change in this case ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep an eye on that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, update the language and trigger a new calculation on locale change

@LukasLechnerDev LukasLechnerDev self-assigned this Feb 8, 2022
@chiljamgossow chiljamgossow added the bug Something isn't working label Feb 8, 2022
@sonarcloud
Copy link

sonarcloud bot commented Feb 8, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

48.5% 48.5% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@mtwalli mtwalli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us merge it for now , We should test it when languages are there

@chiljamgossow chiljamgossow merged commit 861a3dd into release/2.18.x Feb 9, 2022
@chiljamgossow chiljamgossow deleted the fix/language branch February 9, 2022 13:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working maintainers Tag pull requests created by maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants