Multilingual typing: main locale is not guaranteed to be dictionaryGroups[0] (HashSet in getUsedLocales)

Geschlossen
#762 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
Ein halber Tag
Anfängerfreundlichkeit
62/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
android, kotlin

Rechercherichtung

Start in DictionaryFacilitatorImpl.getUsedLocales(), where hashSetOf(mainLocale) is built, and in getNewDictGroupsAndDictsToCleanup(), which creates the groups in that set's iteration order. Then check the dictionaryGroups[0] call sites the issue lists: mainLocale, currentlyPreferredDictionaryGroup, getSuggestionResults(), isActive() and LatinIME.resetSuggestMainDict(). Done when the main locale is always group 0 regardless of Locale.hashCode(), for example with a linkedSetOf change, and a test or debug output confirms the order for en_US with de.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Describe the bug
With a secondary language (multilingual typing), the main locale of the layout is not guaranteed to be the first dictionary group. DictionaryFacilitatorImpl.getUsedLocales() collects the locales in a HashSet:

val locales = hashSetOf(mainLocale)
locales.addAll(getSecondaryLocales(selectedSubtype.extraValue))

getNewDictGroupsAndDictsToCleanup() creates the groups in the iteration order of that set, and a HashSet doesn't keep insertion order. But a lot of code assumes dictionaryGroups[0] is the main locale:

  • mainLocale = dictionaryGroups[0].locale, also used by LatinIME.resetSuggestMainDict(), which calls resetDictionaries(this, dictionaryFacilitator.mainLocale, ...). If that is the secondary locale, getUsedLocales() goes into the "called from the spell checker" branch, and as far as I can see the keyboard can end up with only the secondary language.
  • currentlyPreferredDictionaryGroup = maxBy { it.confidence } returns the first group on a tie. At the start all groups have confidence 1, so the tie goes to whichever locale the HashSet put first.
  • getSuggestionResults() queries only group 0 synchronously and waits at most 120 ms for the others.
  • isActive(), isValidSuggestionWord(), the personal-dictionary check in addToUserHistory() and dumpDictionaryForDebug() also use group 0.

Which pairs are affected depends on Locale.hashCode(). A quick check on a desktop JVM (Java 21) shows the secondary locale first for 7 of 12 common pairs, e.g. main en_US + secondary de, fr or es, and main nl or pl + secondary en_US. On our devices (Android 15/17), de_DE + en_US happened to come out in the right order, so Android's order differs from the JVM, but it is still not defined.

Possible fix
Keep the insertion order (that's what we did):

val locales = linkedSetOf(mainLocale)

To Reproduce

  1. Set up a layout with a secondary language via Multilingual typing, e.g. English (US) with German.
  2. Depending on the pair, the secondary locale becomes dictionaryGroups[0]. With debug mode on, the space bar shows the order of the locales (localesAndConfidences()).

Expected behavior
The layout's main locale is always the first dictionary group.

App version & Flavor
Found in GlassType, my fork, now based on LeanType 4.3.1 (0e673e1). The code is unchanged in current main.

Device Info

  • Model: Samsung Galaxy Z Fold 3 (SM-F926B) and Galaxy S23 Ultra (SM-S918B)
  • OS version: Android 15 / Android 17
Vorherrschende Sprache
Kotlin
Sterne
1k
Forks
59
Ø Merge
14 Std. 9 Min.
Gemergte PRs (30 T.)
56

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus LeanBitLab/LeanType

Alle Issues in LeanBitLab/LeanType

Ähnliche Issues

Weitere Issues zu Kotlin

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.