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

feat: Warn the user if the posting language might be incorrect #792

Merged
merged 5 commits into from
Jul 2, 2024

Conversation

nikclayton
Copy link
Contributor

@nikclayton nikclayton commented Jul 1, 2024

The user has to specify the language they're posting in, and sometimes they might get it wrong (e.g., replying to a post that also had the language set incorrectly, forgetfulness, etc).

This has accessiblity issues (only following statuses in a given language fails, translation can fail, etc).

Prevent this by trying to detect the language the status is written in when the user tries to post it. If the detected language and the set language do not match, and the detection is 60+% confident, warn the user the status language might be incorrect, and offer to correct it before posting.

How this works differs by device and API level.

  • API 23 - 28, fdroid and github build flavours
    • Not supported. A no-op language detector is used.
  • API 29 and above, fdroid and github build flavours
    • Uses Android TextClassifier to detect the likely language
  • AP 23 and above, google build flavour
    • Uses ML Kit language identification

To do this:

  • Add LanguageIdentifier, with methods to do the identification, and LanguageIdentifier.Factory to create the identifiers.
  • Inject the factory in ComposeActivity
  • Detect the language when the user posts, showing a dialog if there's a sufficiently large discrepancy.

The ML Kit dependencies (language models) will be installed by the Play libraries, so there's some machinery to check that they're installed, and kick off the installation if not. If they can't be installed then the language check is bypassed.

Update the privacy policy, as the ML Kit libraries may send some data to Google.

The user has to specify the language they're posting in, and sometimes
they might get it wrong (e.g., replying to a post that also had the
language set incorrectly, forgetfulness, etc).

This has accessiblity issues (only following statuses in a given
language fails, translation can fail, etc).

Prevent this by trying to detect the language the status is written in
when the user tries to post it. If the detected language and the set
language do not match, and the detection is 60+% confident, warn the
user the status language might be incorrect, and offer to correct it
before posting.

This is currently implemented using Google's ML Kit, and therefore only
available in the `google` store flavour.

To do this:

- Add `LanguageIdentifier`, with methods to do the identification,
  and `LanguageIdentifier.Factory` to create the identifiers.
- Inject the factory in `ComposeActivity`
- Detect the language when the user posts, showing a dialog if there's
  a sufficiently large discrepency.

The ML Kit dependencies (language models) will be installed by the Play
libraries, so there's some machinery to check that they're installed,
and kick off the installation if not. If they can't be installed then
the language check is bypassed.

Update the privacy policy, as the MLKit libraries may send some data
to Google.
- Move the language identifiers for API 29 and NOP in to the primary
  code, as they don't have dependency issues.

- Provide a default language detector factory for all devices.

- Return Result<> from language detection to cover possible exceptions.

- Pay attention to trying to use the language detector after close.
@nikclayton nikclayton merged commit 4fc52f9 into pachli:main Jul 2, 2024
23 checks passed
@nikclayton nikclayton deleted the detect-language branch July 2, 2024 18:22
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 this pull request may close these issues.

1 participant