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

loadCurrentLanguageAsync: languageTag overrides completeTag (wrong beheviour, should be the opposite) #11

Closed
nathanfallet opened this issue Oct 1, 2024 · 0 comments · Fixed by #12

Comments

@nathanfallet
Copy link
Contributor

Hello!
I would like to report a wrong behaviour in the library.

The documentation for loadCurrentLanguageAsync states the following:

Note that for a key contained in both fr and fr_FR, the one in fr_FR will be used

Which later, is wrong because those two segments do the opposite:

fileLocales[languageTag]?.let {
    fileList.addAll(it)
}
// Add the complete tags after the language tag so that if there is the same key
// The complete tag value will override the basic one
fileLocales[completeTag]?.let {
    fileList.addAll(it)
}

And this (same problem also in pluralForKey):

private fun singleForKey(key: String, vararg args: Any?): String? {
    return localeTexts
        .map { it.first }
        .firstOrNull { it.hasTextForKey(key) }
        ?.getText(key, *args)
}

So when iterating on localeTexts (parsed version of fileLocales, in the same order they were added) using firstOrNull, you hit data from languageTag before hitting data from completeTag.

If languageTag is added before completeTag, then firstOrNull should be replaced by lastOrNull.
Or locales have to be loaded in the opposite order (which seems better, because firstOrNull is on average quicker to return than lastOrNull)

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

Successfully merging a pull request may close this issue.

1 participant