HeliBoard icon indicating copy to clipboard operation
HeliBoard copied to clipboard

Feature request: Language Auto-Detection and Contextual Suggestions

Open emavgl opened this issue 1 month ago • 17 comments

Hi, I have installed Heliboard Keyboard and I found it great. I write in Italian, English and German and I have added all of them in the settings under the same layout.

It meets my expectation, which is that, I don't have to choose the Keyboard layout every time I want to type something, but I just start writing in a language and I get suggested words and correction based on the language I am writing.

From my experience however, activating those options causes a big mess of having in the suggestions the dictionaries of all 3 languages, and it happens very frequently that I get a word in a language auto-corrected in a word of another language.

Proposal

My proposal is the following, based on what I already started typing, use only the dictionaries and auto-corrections for that language only.

emavgl avatar Nov 21 '25 12:11 emavgl

Hi, I've looked into this and have an idea for a "Language Auto-Detection" heuristic.

The idea is to modify DictionaryFacilitatorImpl.kt so that if the typed word has an exact match in one of the active dictionary groups (languages), we filter out suggestions from all other groups for that specific input. This effectively "locks" the suggestions to the detected language, reducing cross-language noise while still allowing multilingual support for ambiguous or unknown words.

Could you please assign this issue to me? I'd like to work on implementing this feature.

subha0319 avatar Nov 21 '25 15:11 subha0319

Hi @subha0319, thanks for your help. Unfortunately it seems I don't have the rights to assign this issue to you. But it seems a good plan to me. If you need any help for trying this out, I am happy to test this functionality

emavgl avatar Nov 21 '25 16:11 emavgl

Hi @emavgl, Thanks for offering to help! I've implemented the logic where if you type a word that is an exact match in one of your enabled languages, suggestions from the other languages are temporarily hidden to reduce noise.

I have built a debug APK with these changes for you to test: Link Scroll to the bottom "Artifacts" section and click HeliBoard-debug. The download will be a .zip file. You need to be logged into GitHub to download. You must extract/unzip it to find the app-debug.apk file.

Instructions:

  1. Extract/unzip the zip file to find the app-debug.apk file.
  2. Uninstall your current version of HeliBoard (this is necessary because my debug build has a different signature).
  3. Install the APK.
  4. Go to Settings -> Languages and enable your 3 languages (Italian, English, German).
  5. Try typing a word that exists only in one language (e.g., a purely Italian word) and see if the "confusing" corrections from German/English disappear from the suggestion strip. Let me know if the suggestion filtering works for you!

subha0319 avatar Nov 21 '25 17:11 subha0319

My proposal is the following, based on what I already started typing, use only the dictionaries and auto-corrections for that language only.

if the typed word has an exact match in one of the active dictionary groups (languages), we filter out suggestions from all other groups

This doesn't seem like a solution that only affects autocorrect, but seems be much more restrictive. As far as I understand it would only work in tap-typing, but not in glide typing where we don't have a typed word.

Helium314 avatar Nov 22 '25 08:11 Helium314

Hi @subha0319 it does not seem to work in my case. See the image attached. I am writing in english but keep receiving suggestions from Italian dictionary (which quality is very low anyway)

Image

emavgl avatar Nov 23 '25 07:11 emavgl

My proposal is the following, based on what I already started typing, use only the dictionaries and auto-corrections for that language only.

if the typed word has an exact match in one of the active dictionary groups (languages), we filter out suggestions from all other groups

This doesn't seem like a solution that only affects autocorrect, but seems be much more restrictive. As far as I understand it would only work in tap-typing, but not in glide typing where we don't have a typed word.

You are right, the current implementation relies on mTypedWord, so it acts as a heuristic specifically for tap-typing. For glide typing, mTypedWord is usually empty, so the filter is skipped (preserving default behavior as a fallback).

regarding restrictiveness: It effectively "locks" the context to the detected language when an exact match is found. This aligns with the user's request to "use only the dictionaries for that language," but it does reduce discovery of cross-lingual words.

Do you think we should relax this? For example, instead of hiding non-matching languages entirely, we could just penalize their scores so they don't appear as the primary auto-correction (center candidate) but remain available in the strip?

subha0319 avatar Nov 23 '25 08:11 subha0319

Hi @subha0319 it does not seem to work in my case. See the image attached. I am writing in english but keep receiving suggestions from Italian dictionary (which quality is very low anyway)

Thanks for the screenshot! That is very helpful.

Why it's happening: The logic I added works by checking if the word you typed exists in a specific language. If you type "Give" and the system finds "Give" in the English dictionary, it hides the others.

However, if your Italian dictionary also contains the word "Give" (which is possible if the dictionary quality is low, as you mentioned), the system thinks, "Ah, the user might be typing the Italian word 'Give'!" and therefore keeps the Italian suggestions (like "Già") visible.

Could you verify this for me? If you disable English and enable only Italian, and type "Give", does "Give" still appear as a valid suggestion in the center or left? If yes, that explains why the filter isn't removing Italian, it thinks it's a valid match.

subha0319 avatar Nov 23 '25 08:11 subha0319

Image

"Give" does not appear. (What the hell is "Givenchy" - this dictionary is unusable)

Image

Here, "Hello" is not suggested when typing "Hell" but when typing "Hello" it appears on the left. Does it mean is also on the italian dictionary?

emavgl avatar Nov 23 '25 09:11 emavgl

@emavgl Thanks for testing and sharing your findings.

I have a new build that handles the edge cases you found.

What's improved:

  • Context Awareness: It now checks the previous word to detect the language. This fixes the "Hello how ar..." case, once you type a unique word like "how", it locks the suggestions to English for the rest of the sentence.

  • Supports Glide Typing: Because it relies on the previous word (which is already committed), this filtering now works perfectly for Swipe/Glide typing too, not just tap-typing.

  • Dictionary Overlap: It correctly handles cases where a word (like "Hello") exists in multiple dictionaries.

  • Missing Words: It no longer hides suggestions if the word you typed (like "Give") isn't found in the dictionary, ensuring you don't lose valid corrections.

Download: Link (Same instructions as before for testing)

Instructions:

  1. Extract/unzip the zip file to find the app-debug.apk file.
  2. Uninstall your current version of HeliBoard (this is necessary because my debug build has a different signature).
  3. Install the APK.
  4. Go to Settings -> Languages and enable your 3 languages (Italian, English, German).
  5. Try typing a sentence.

Let me know if this works for you!

subha0319 avatar Nov 23 '25 12:11 subha0319

It seems working but I have noticed two problems:

  • I have lost the suggestions. In some apps it works, in some not. For example, suggestions and auto correction do not work on Firefox.

  • I have disabled the option to learn new words after typing. However, I keep having this wrong suggestions marked as History and assigned to the wrong dictionary (see Hello, coming from history and assigned to German). However, I believe that this issue is unrelated to your changes specifically, as it seems to be also on the latest version of Heliboard.

Image

emavgl avatar Nov 24 '25 10:11 emavgl

Thanks for testing!

Firefox: Browsers usually disable suggestions in the URL bar. Please check if the latest version of Heliboard does the same, it's likely standard behavior rather than a bug in this code.

History: You're right, this is unrelated to the changes. The app previously learned "Hello" as a German word, so the filter correctly sees it as a valid German word and keeps that language active. You can long-press the suggestion to remove it.

subha0319 avatar Nov 24 '25 17:11 subha0319

Thanks for testing!

Firefox: Browsers usually disable suggestions in the URL bar. Please check if the latest version of Heliboard does the same, it's likely standard behavior rather than a bug in this code.

No I am not writing in the URL bar, but in the text-box here on Github. I can confirm I have no issue with the latest version of Heliboard, but just with your version unfortunately.

History: You're right, this is unrelated to the changes. The app previously learned "Hello" as a German word, so the filter correctly sees it as a valid German word and keeps that language active. You can long-press the suggestion to remove it.

I could remove it, but it will likely reappear again or it will be an issue with other words. Do you agree that this is a bug or is it on purpose? Again, the option to add words to the dictionary when typing is disabled. If it is a bug, I'll open a new issue maybe.

emavgl avatar Nov 24 '25 17:11 emavgl

@emavgl To be 100% sure about the Firefox issue, could you please try this "Control Test"?

  1. Install the Official/Store version of HeliBoard.
  2. Go to Settings -> Languages and disable Italian and German (enable only English).
  3. Go to the same text box in Firefox where you had issues.
  4. Type the same words.

Does the suggestion strip look empty/broken in the Official version now?

If yes: It confirms that the English dictionary simply doesn't work well in Firefox. My code is correctly hiding the Italian "backup" suggestions, leaving you with the (empty) English results.

If no (suggestions appear): Then there is a deeper issue with how my version of the code handles that specific text field.

subha0319 avatar Nov 24 '25 17:11 subha0319

No unfortunately it does not look broken on the stable version. Even with just English enabled.

emavgl avatar Nov 24 '25 18:11 emavgl

Image

Your version but just english

emavgl avatar Nov 24 '25 18:11 emavgl

I could remove it, but it will likely reappear again or it will be an issue with other words. Do you agree that this is a bug or is it on purpose? Again, the option to add words to the dictionary when typing is disabled. If it is a bug, I'll open a new issue maybe.

Ok, I find out that there was another option enabled called "Personalized suggestions" and removing that means that typed words are not added to the history and suggested. I am fine with that, if I want to add a word in the dictionary I'll rather do it manually than having false positives.

emavgl avatar Nov 26 '25 14:11 emavgl

Thanks for confirming that 'Personalized suggestions' was the cause of the history mix up.

Regarding lost suggestions issue: I've built a new APK that handles it.

New APK: Link

Could you try typing "Hello " again? You should now see next-word suggestions like "how" in English." Let me know if it works.

Also, in the official version, when you enable only English and try typing "Hello " in Firefox do you see any suggestions?

subha0319 avatar Nov 26 '25 15:11 subha0319

Thanks for confirming that 'Personalized suggestions' was the cause of the history mix up.

Regarding lost suggestions issue: I've built a new APK that handles it.

New APK: Link

Could you try typing "Hello " again? You should now see next-word suggestions like "how" in English." Let me know if it works.

I'll try soon! Thanks.

Also, in the official version, when you enable only English and try typing "Hello " in Firefox do you see any suggestions?

I recently updated to 3.6 and I have lost suggestions on firefox. Even with the option of forcing the input. So it was not a bug introduced with your change.

emavgl avatar Nov 29 '25 07:11 emavgl

I recently updated to 3.6 and I have lost suggestions on firefox. Even with the option of forcing the input. So it was not a bug introduced with your change.

Thanks for confirming that the lost suggestions happens in official versions as well. I think a new issue can be raised for this.

Quick summary of the code changes:

Modified getSuggestionResults in DictionaryFacilitatorImpl.kt with two filtering strategies:

  1. Context Strategy (Primary): If the previous word exists in Language A but not Language B, suggestions are restricted to Language A. (Supports glide typing).

  2. Exact Match Strategy (Fallback): If the current word is an exact match in Language A but not Language B, suggestions are restricted to Language A.

Safety: Filtering is disabled if a word exists in multiple dictionaries (overlap) or is unknown, ensuring valid suggestions are not lost in ambiguous cases.

I will proceed with opening the Pull Request now. Thanks again for all the testing!

subha0319 avatar Nov 29 '25 10:11 subha0319

Hi again, thanks again for your work. It is way better but still I have some problem when typing.

See the attached video

https://github.com/user-attachments/assets/ed67c6ba-6d8b-44c2-8e7b-d910cb68abb6

I can understand

Ciao (maybe also shared in English) come (maybe also shared in English) stai (it seems it was not in the dictionary) io (shared) sto (it also was not suggested) bene (matching italian word)

But then all words from english were suggested.

emavgl avatar Nov 29 '25 12:11 emavgl