Skip to content
New issue

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

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

Already on GitHub? # to your account

LanguagesService: redirect "en" language code to "en_US" #14701

Merged
merged 1 commit into from
Nov 30, 2022

Conversation

cbjeukendrup
Copy link
Contributor

If the system language code happens to be something like "en_CY", that will decay to "en". But we don't have that, only "en_US". That causes some problems. To fix that, we map "en" to "en_US".

Might resolve: #13926
May resolve: #12917 (comment)

@cbjeukendrup cbjeukendrup requested a review from Eism November 23, 2022 20:18
@cbjeukendrup
Copy link
Contributor Author

@Eism Could you please try if this solves the issue for you?

There are multiple ways to solve this; I'm now doing it without touching the languages hash, but alternatively we could make sure that we put "en" in the hash instead of "en_US", by making a special case in the languages.json reading code. We can't edit languages.json directly though, because the language codes need to match the codes from Transifex, and there we use "en" as the "source language" and "en_US" as one of the "target languages", so we can't make any changes there.

@Eism
Copy link
Contributor

Eism commented Nov 24, 2022

@cbjeukendrup
There are other problematic languages in the list of available languages, for example zh (there are zh_CN, zh_HK, zh_TW, but no zh).

Maybe instead of

if (m_languagesHash.contains(code)) {
    return code;
}

should be

std::sort(languages.begin(), languages.end(), [](const Language& l, const Language& r) {
        return l.code < r.code;
});

for (const Language& language : languages) {
    if (language.code.startsWith(code)) {
        return language.code;
    }
}

The first found in the list will be selected, for now it is en_GB. (Or does the language have to be US?)

@cbjeukendrup
Copy link
Contributor Author

Yes, the language should preferably be en_US if no other variant is specified explicitly.

Anyway, I will try to come up with a more general mechanism to work around these problems.

@cbjeukendrup cbjeukendrup marked this pull request as ready for review November 25, 2022 17:37
// If the user's system language is just "en", or "en_CY" for example, this will not be found.
// So, for short codes that are at risk, we map them to long codes that we do have.
// Should be kept in sync with languages.json.
static const std::map<QString, QString> SHORT_TO_LONG_CODES {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can move it to configuration
Like fallbacksForLanguages

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 prefer not moving it to configuration, because this relates quite closely to this tryCode algorithm, and actually all logic about which languages we support happens in LanguagesService. I hope this is okay :)

…we do have

For some languages, we only have long, specific codes in LanguagesHash / languages.json. If the user's system language is just "en", or "en_CY" for example, this will not be found. So, for short codes that are at risk, we map them to long codes that we do have.
@Eism Eism merged commit 4a6476c into musescore:master Nov 30, 2022
@Eism
Copy link
Contributor

Eism commented Nov 30, 2022

should be merged to RC

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MU4 Issue] Musescore UI not in System Default language
2 participants