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

Remove usage of Locale from LanguageDialogFragment & for audio language selection flow via options #3791

Open
BenHenning opened this issue Sep 15, 2021 · 0 comments
Labels
bug End user-perceivable behaviors which are not desirable. Impact: Low Low perceived user impact (e.g. edge cases). Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet. Z-ibt Temporary label for Ben to keep track of issues he's triaged.

Comments

@BenHenning
Copy link
Member

This is a tracker issue for unchanged code that will soon be changed in upcoming PRs.

LanguageDialogFragment relies on Locale & it shouldn't. Part of removing this dependency involves properly piping audio language information from LocaleController & TranslationController to the fragment. Some artifacts that were developed before I decided to stop trying to solve this since it's not an immediate need:

arguments.proto:

// Fragment arguments for creating instances of LanguageDialogFragment.
message LanguageDialogFragmentArguments {
  // The current audio language selected by the user.
  OppiaLanguage current_audio_language = 1;

  // The list of languages that may be selected by the user.
  repeated SelectableLanguage selectable_languages = 2;

  // Represents a language that can be selected for playing audio.
  message SelectableLanguage {
    // The language to select.
    OppiaLanguage language = 1;

    // A human-presentable string representation of the language that can be shown on UIs to users.
    // This has already been localized appropriately for the given language (i.e. 'English' will
    // appear as 'English', but 'Arabic' will appear localized such as 'عربي').
    string language_display_name = 2;
  }
}

LocaleController.kt:

  // TODO: document that this returns the name of the specified display language in that language's locale (so that the name is always readable by a native speaker of that language.
  fun retrieveAudioLanguageDisplayName(language: OppiaLanguage): DataProvider<String> {
    val providerId = AUDIO_TRANSLATIONS_DISPLAY_LANGUAGE_DATA_PROVIDER_ID
    return retrieveAudioTranslationsLocale(language).transform(providerId) { locale ->
      // Compute an Android locale for the audio language if one exists, otherwise default.
      val androidLocale =
        androidLocaleFactory.createAndroidLocale(locale.localeContext, forceLocale = false)
      return@transform androidLocale?.getDisplayLanguage(androidLocale)
        ?: locale.localeContext.getDisplayLanguage()
    }
  }

OppiaLocaleContextExtensions.kt:

fun OppiaLocaleContext.getDisplayLanguage(): String {
  return languageDefinition.getHumanReadableMacaronicLanguageName()
    ?: fallbackLanguageDefinition.getHumanReadableMacaronicLanguageName()
    ?: getLanguageId().toMachineLanguageCode()
    ?: getFallbackLanguageId().toMachineLanguageCode()
    ?: "Unknown language"
}

private fun LanguageSupportDefinition.getHumanReadableMacaronicLanguageName(): String? {
  return when (language) {
    // Top-level languages should rely on the system locale to provide the name.
    OppiaLanguage.ARABIC, OppiaLanguage.ENGLISH, OppiaLanguage.HINDI, OppiaLanguage.PORTUGUESE,
    OppiaLanguage.BRAZILIAN_PORTUGUESE -> null
    // TODO(#52): Consider moving this to an untranslated strings.xml file.
    OppiaLanguage.HINGLISH -> "Hinglish"
    OppiaLanguage.LANGUAGE_UNSPECIFIED, OppiaLanguage.UNRECOGNIZED, null -> null
  }
}

private fun LanguageId.toMachineLanguageCode(): String? {
  return when (languageTypeCase) {
    LanguageId.LanguageTypeCase.IETF_BCP47_ID -> ietfBcp47Id.ietfLanguageTag
    LanguageId.LanguageTypeCase.MACARONIC_ID -> macaronicId.combinedLanguageCode
    LanguageId.LanguageTypeCase.LANGUAGETYPE_NOT_SET, null -> null
  }
}

& a bunch of changes will be needed throughout AudioViewModel & the audio selection UI. The above was a work-in-progress, but my thinking is that we probably want to introduce a VoiceoverTranslationContext through EphemeralState that contains plug-and-play contexts for content & feedbacks. This can significantly simplify the audio view logic since it doesn't need to make any decisions about language selection or fallbacks (which really ought to be done by the translation system), and it provides an easy place to carry along the display language context that we're trying to replace per LanguageDialogFragment's Locale dependency.

@BenHenning BenHenning added this to the Beta MR2 milestone Jun 11, 2022
@Broppia Broppia added issue_type_infrastructure Impact: Low Low perceived user impact (e.g. edge cases). labels Jul 7, 2022
BenHenning added a commit that referenced this issue Aug 19, 2022
…lpha MR5 fixes (#4506)

## Explanation
Fixes #4495
Fixes part of #3088
Fixes #4467
Fixes #4505
Fixes #4266
Fixes #4446

This PR fixes a number of key blockers for the upcoming Alpha MR5 release of the app. In particular:
- It fixes #4266 by reformatting one XML file that Rajat left a comment for during his post-merge reviews of Alpha MR4 PRs.
- It mitigates #4495 by introducing a banner for when correct audio can't be played (I did run into an actual bug where the wrong audio played once, but I couldn't repro it--most of the time the app will stop autoplaying if it can't find the correct language). This also fixes part of #3088 since the mitigation will help make that situation better.
- It addresses #4467 by logging stringified versions of all supported answer types upon answer submission (rather than just whether the answer is correct).
- It addresses #4446 by (1) introducing a new default hint text for text input, and (2) by ensuring hint text is fully readable by wrapping it when it extends to more than one line. However, another issue was discovered which would be really nice to fix (but is not feasible given the amount of time available for this PR). #4509 is tracking this future work.
- It addresses #4505 by disabling profile name verification when the learner study is enabled (as a stop-gap).

Note that there are no new tests being added in this PR since the fixes are mostly trivial and have been manually verified during development. #4510 is tracking adding automated tests for long-term app health.

Furthermore, AudioViewModel was allow-listed to reference Locale directly so that it can it include a localized language name in the fail-to-play audio notice. #3791 will fix this in the long-term.

This PR also includes version code & minor version bumps to prepare for the upcoming release. It also fixes the Kenya-specific alpha build flavor (which was unfortunately checked in as broken in #4507), and adds it to CI since the assumption in #4507 that it doesn't need to be covered is incorrect. The Gradle workaround for the new flavor was removed since it was a legitimate failure that wasn't being picked up by Bazel builds in CI.

## Essential Checklist
- [x] The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
- [x] Any changes to [scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets) files have their rationale included in the PR explanation.
- [x] The PR follows the [style guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android Studio ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

## For UI-specific PRs only
Creating profile names with normally forbidden characters (in this case, numbers):

https://user-images.githubusercontent.com/12983742/185594638-3bd653a4-916a-4471-963a-d00ab987f378.mp4

Demonstrating when English audio is sometimes unavailable & the new notice to make this clearer:

https://user-images.githubusercontent.com/12983742/185594719-896e428c-96b8-42f3-b53f-721352a90f14.mp4

Audio not being available can occur in all languages, not just English:

![audio_unavailable](https://user-images.githubusercontent.com/12983742/185594834-6f6127db-e54b-4a23-a734-7b3a6b849184.png)

Text input hints can now be multi-line to ensure that they're not cut off:

![oppia_multiline_text_input_hint](https://user-images.githubusercontent.com/12983742/185594908-4b4a07f3-cff7-44f7-a2c9-8dfb7a8ca784.png)

Commits:

* Address
#4274 (comment).

This is part of addressing #4266.

* Add audio notice for when language is missing.

* Disable invalid profile name rules for studies.

* Add analytics logging for submitted answers.

* Code health fixes.

* Add hint wrapping, and default text input hint.

* Fix broken tests.

* Test fixes.

* Fix broken Kenya-specific alpha build.

Also, bump version codes & minor versions in preparation for the
release.
@BenHenning BenHenning changed the title Remove usage of Locale from LanguageDialogFragment Remove usage of Locale from LanguageDialogFragment & for audio language selection flow via options Sep 9, 2022
@BenHenning BenHenning added Z-ibt Temporary label for Ben to keep track of issues he's triaged. issue_user_developer labels Sep 15, 2022
@BenHenning BenHenning removed this from the Beta MR2 milestone Sep 16, 2022
@seanlip seanlip added bug End user-perceivable behaviors which are not desirable. and removed issue_type_infrastructure labels Mar 28, 2023
@MohitGupta121 MohitGupta121 added the Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet. label Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug End user-perceivable behaviors which are not desirable. Impact: Low Low perceived user impact (e.g. edge cases). Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet. Z-ibt Temporary label for Ben to keep track of issues he's triaged.
Development

No branches or pull requests

4 participants