Skip to content

Commit

Permalink
Fix #4628, #4667: Add support for filtering languages from builds (#4687
Browse files Browse the repository at this point in the history
)

## Explanation
Fixes #4628
Fixes #4667

The core fix for #4628 is splitting the language configuration between
"all languages the app supports" and "production-ready languages." This
is now configurable per-binary where all pre-beta binaries include all
languages, and the beta & GA binaries only include production-ready
languages (those are, languages for which we always aim to have 100%
content translations). Tests use the "all languages" configuration, by
default, for parity with the developer version of the app. This required
a small change where we define the language proto as part of the shared
``//model`` module rather than as a separate package. As was before,
this proto is only loaded in Bazel builds of the app since our Gradle
pipeline doesn't support automatically textproto->binary proto
conversion during build time.

To ensure that the app strings are filtered out, the supported languages
configuration proto that's included in the app is passed through a new
script that strips out all resources (including non-strings) from the
binary. This has actually removed ~400KiB even from the pre-release
binaries since our third-party assets include a bunch of strings outside
our core languages.

New output now shows when building the app with Bazel to make it clearer
what sorts of resources are being dropped due to incompatible languages:
```
82 resources are being removed that are tied to unsupported languages: [af, am, as, az, be, bg, bn, bs, ca, cs, da, de, el, en-AU, en-CA, en-GB, en-IN, en-XC, es, es-419, es-US, et, eu, fa, fi, fr, fr-CA, gl, gu, hr, hu, hy, in, is, it, iw, ja, ka, kk, km, kn, ko, ky, lo, lt, lv, mk, ml, mn, mr, ms, my, nb, ne, nl, or, pa, pl, pt, pt-PT, ro, ru, si, sk, sl, sq, sr, sr-Latn, sv, ta, te, th, tl, tr, uk, ur, uz, vi, zh-CN, zh-HK, zh-TW, zu] (size reduction: 391239 bytes).
```
(When building oppia_dev)

```
85 resources are being removed that are tied to unsupported languages: [af, am, ar, as, az, be, bg, bn, bs, ca, cs, da, de, el, en-AU, en-CA, en-GB, en-IN, en-XC, es, es-419, es-US, et, eu, fa, fi, fr, fr-CA, gl, gu, hi, hr, hu, hy, in, is, it, iw, ja, ka, kk, km, kn, ko, ky, lo, lt, lv, mk, ml, mn, mr, ms, my, nb, ne, nl, or, pa, pl, pt, pt-PT, ro, ru, si, sk, sl, sq, sr, sr-Latn, sv, sw, ta, te, th, tl, tr, uk, ur, uz, vi, zh-CN, zh-HK, zh-TW, zu] (size reduction: 351087 bytes).
```
(When building oppia_beta)

#4667 is included in this PR despite it being an asset downloader-only
fix out of convenience & since it's a related issue. The problem in the
downloader was that translations were being incorrectly copied over to
the new proto structure for lessons (which isn't used in the app yet,
but is used for image downloading) which led to non-English images not
being scraped from content HTMLs and thus not downloaded and included in
the embedded assets for releases. We'll be adding a manual QA test to
make sure that non-English content images load correctly.

## 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
Screenshots showing how English, Brazilian Portuguese, and Swahili are
handled with the changes in this PR (between developer and beta builds
of the app):

| | Dev flavor -- with PR changes | Beta flavor -- with PR changes |

|----------------------|-----------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------|
| English |
![image](https://user-images.githubusercontent.com/12983742/200829756-bbae1ab4-c40f-4b96-8404-eb12fdecb418.png)
|
![image](https://user-images.githubusercontent.com/12983742/200831324-0b03a8c5-654d-41b5-bbfd-206a5a4b143f.png)
|
| Brazilian Portuguese |
![image](https://user-images.githubusercontent.com/12983742/200829980-7025ce6b-5861-4a61-aff1-86b4c66fe774.png)
|
![image](https://user-images.githubusercontent.com/12983742/200831480-73ba6d73-2685-4dab-895d-ed915bcb6f65.png)
|
| Swahili |
![image](https://user-images.githubusercontent.com/12983742/200830150-7b3c5568-deaa-46af-83b2-e3da813e984a.png)
|
![image](https://user-images.githubusercontent.com/12983742/200831722-d5cc7ebf-1521-412a-947b-f2d9dc899957.png)
|

As can be seen from the table, all three languages are fully supported
except when using beta with the changes introduced by this PR (where
Swahili is dropped since it's not yet a 100% supported, production-ready
language for the app). Note that in the case of Swahili, it falls back
to English simply because that's how my device was configured at the
time (it will fall back to whatever the system-secondary language is set
to).

Note that other typical screenshots/tests are not included in this PR,
including for Espresso. From a high-level perspective, the main
difference in this PR is which app and content strings are ultimately
included and supported within the app. Given this is
inclusion/exclusion, the screenshots above + manual verification via e2e
tests are sufficient. Beyond that, properly testing these changes would
require e2e tests that can use the production assets (which current
Espresso tests don't have access to).
  • Loading branch information
BenHenning authored Nov 11, 2022
1 parent 76bf81a commit fea5b7e
Show file tree
Hide file tree
Showing 30 changed files with 1,087 additions and 42 deletions.
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ LICENSE @BenHenning
NOTICE @BenHenning

# Language configuration files.
config/**/languages/*.textproto @BenHenning
config/**/alllanguages/*.textproto @BenHenning
config/**/productionlanguages/*.textproto @BenHenning

# Configuration for KitKat-specific curated builds.
config/kitkat_main_dex_class_list.txt @BenHenning
Expand Down
1 change: 1 addition & 0 deletions app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ TEST_DEPS = [
"//app/src/main/java/org/oppia/android/app/testing/activity:test_activity",
"//app/src/main/java/org/oppia/android/app/translation/testing:test_module",
"//app/src/main/java/org/oppia/android/app/utility/math:math_expression_accessibility_util",
"//config/src/java/org/oppia/android/config:all_languages_config",
"//domain",
"//domain/src/main/java/org/oppia/android/domain/audio:audio_player_controller",
"//domain/src/main/java/org/oppia/android/domain/classify/rules/algebraicexpressioninput:algebraic_expression_input_rule_module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ app_test(
"//app/src/main/java/org/oppia/android/app/application:common_application_modules",
"//app/src/main/java/org/oppia/android/app/application/testing:testing_build_flavor_module",
"//app/src/main/java/org/oppia/android/app/translation/testing:test_module",
"//config/src/java/org/oppia/android/config:all_languages_config",
"//data/src/main/java/org/oppia/android/data/backends/gae:prod_module",
"//domain/src/main/java/org/oppia/android/domain/onboarding/testing:retriever_test_module",
"//testing",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ app_test(
"//app/src/main/java/org/oppia/android/app/application:common_application_modules",
"//app/src/main/java/org/oppia/android/app/application/testing:testing_build_flavor_module",
"//app/src/main/java/org/oppia/android/app/translation/testing:test_module",
"//config/src/java/org/oppia/android/config:all_languages_config",
"//data/src/main/java/org/oppia/android/data/backends/gae:prod_module",
"//domain/src/main/java/org/oppia/android/domain/onboarding/testing:retriever_test_module",
"//domain/src/main/java/org/oppia/android/domain/translation:translation_controller",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ app_test(
"//app/src/main/java/org/oppia/android/app/application:application_injector_provider",
"//app/src/main/java/org/oppia/android/app/application:common_application_modules",
"//app/src/main/java/org/oppia/android/app/translation/testing:test_module",
"//config/src/java/org/oppia/android/config:all_languages_config",
"//data/src/main/java/org/oppia/android/data/backends/gae:prod_module",
"//domain/src/main/java/org/oppia/android/domain/onboarding/testing:retriever_test_module",
"//domain/src/main/java/org/oppia/android/domain/translation:translation_controller",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ oppia_android_test(
deps = [
":dagger",
"//app/src/main/java/org/oppia/android/app/translation:app_language_locale_handler",
"//config/src/java/org/oppia/android/config:all_languages_config",
"//domain",
"//domain/src/main/java/org/oppia/android/domain/onboarding/testing:retriever_test_module",
"//domain/src/main/java/org/oppia/android/domain/oppialogger:prod_module",
Expand Down Expand Up @@ -106,6 +107,7 @@ oppia_android_test(
"//app/src/main/java/org/oppia/android/app/application:common_application_modules",
"//app/src/main/java/org/oppia/android/app/application/testing:testing_build_flavor_module",
"//app/src/main/java/org/oppia/android/app/translation/testing:test_module",
"//config/src/java/org/oppia/android/config:all_languages_config",
"//data/src/main/java/org/oppia/android/data/backends/gae:prod_module",
"//domain/src/main/java/org/oppia/android/domain/onboarding/testing:retriever_test_module",
"//domain/src/main/java/org/oppia/android/domain/oppialogger:prod_module",
Expand Down
7 changes: 7 additions & 0 deletions build_flavors.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ _FLAVOR_METADATA = {
"production_release": False,
"deps": [
"//app/src/main/java/org/oppia/android/app/application/dev:developer_application",
"//config/src/java/org/oppia/android/config:all_languages_config",
],
"version_code": OPPIA_DEV_VERSION_CODE,
"application_class": ".app.application.dev.DeveloperOppiaApplication",
Expand All @@ -66,6 +67,7 @@ _FLAVOR_METADATA = {
"production_release": False,
"deps": [
"//app/src/main/java/org/oppia/android/app/application/dev:developer_application",
"//config/src/java/org/oppia/android/config:all_languages_config",
],
"version_code": OPPIA_DEV_KITKAT_VERSION_CODE,
"application_class": ".app.application.dev.DeveloperOppiaApplication",
Expand All @@ -79,6 +81,7 @@ _FLAVOR_METADATA = {
"production_release": True,
"deps": [
"//app/src/main/java/org/oppia/android/app/application/alpha:alpha_application",
"//config/src/java/org/oppia/android/config:all_languages_config",
],
"version_code": OPPIA_ALPHA_VERSION_CODE,
"application_class": ".app.application.alpha.AlphaOppiaApplication",
Expand All @@ -93,6 +96,7 @@ _FLAVOR_METADATA = {
"production_release": True,
"deps": [
"//app/src/main/java/org/oppia/android/app/application/alpha:alpha_application",
"//config/src/java/org/oppia/android/config:all_languages_config",
],
"version_code": OPPIA_ALPHA_KITKAT_VERSION_CODE,
"application_class": ".app.application.alpha.AlphaOppiaApplication",
Expand All @@ -106,6 +110,7 @@ _FLAVOR_METADATA = {
"production_release": True,
"deps": [
"//app/src/main/java/org/oppia/android/app/application/alphakenya:alpha_kenya_application",
"//config/src/java/org/oppia/android/config:all_languages_config",
],
"version_code": OPPIA_ALPHA_KENYA_VERSION_CODE,
"application_class": ".app.application.alphakenya.AlphaKenyaOppiaApplication",
Expand All @@ -119,6 +124,7 @@ _FLAVOR_METADATA = {
"production_release": True,
"deps": [
"//app/src/main/java/org/oppia/android/app/application/beta:beta_application",
"//config/src/java/org/oppia/android/config:production_languages_config",
],
"version_code": OPPIA_BETA_VERSION_CODE,
"application_class": ".app.application.beta.BetaOppiaApplication",
Expand All @@ -132,6 +138,7 @@ _FLAVOR_METADATA = {
"production_release": True,
"deps": [
"//app/src/main/java/org/oppia/android/app/application/ga:general_availability_application",
"//config/src/java/org/oppia/android/config:production_languages_config",
],
"version_code": OPPIA_GA_VERSION_CODE,
"application_class": ".app.application.ga.GaOppiaApplication",
Expand Down
79 changes: 50 additions & 29 deletions config/src/java/org/oppia/android/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,55 @@ This package contains configuration libraries for defining & tweaking app-wide b

load("//model:text_proto_assets.bzl", "generate_proto_binary_assets")

_SUPPORTED_LANGUAGES_CONFIG_ASSETS = generate_proto_binary_assets(
name = "supported_languages_config_assets",
asset_dir = "languages",
name_prefix = "supported_languages_config_assets",
names = ["supported_languages"],
proto_dep_bazel_target_prefix = "//model/src/main/proto",
proto_dep_name = "languages",
proto_package = "model",
proto_type_name = "SupportedLanguages",
)
# Language support levels:
# - all: Indicates all languages/regions technically supported by the app, including ones that may
# not have complete translations. These will be included in prerelease versions of the app.
# - production: Indicates languages for which the team guarantees thorough support (generally nearly
# 100% written translations).
_LANGUAGE_SUPPORT_LEVELS = [
"all",
"production",
]

_SUPPORTED_REGIONS_CONFIG_ASSETS = generate_proto_binary_assets(
name = "supported_regions_config_assets",
asset_dir = "languages",
name_prefix = "supported_regions_config_assets",
names = ["supported_regions"],
proto_dep_bazel_target_prefix = "//model/src/main/proto",
proto_dep_name = "languages",
proto_package = "model",
proto_type_name = "SupportedRegions",
)
_SUPPORTED_LANGUAGES_CONFIG_ASSETS = {
support_level: generate_proto_binary_assets(
name = "%s_supported_languages_config_assets" % support_level,
asset_dir = "%slanguages" % support_level,
name_prefix = "%s_supported_languages_config_assets" % support_level,
names = ["supported_languages"],
proto_dep_bazel_target_prefix = "//model/src/main/proto",
proto_dep_name = "languages",
proto_package = "model",
proto_type_name = "SupportedLanguages",
)
for support_level in _LANGUAGE_SUPPORT_LEVELS
}

android_library(
name = "languages_config",
assets = _SUPPORTED_LANGUAGES_CONFIG_ASSETS + _SUPPORTED_REGIONS_CONFIG_ASSETS,
assets_dir = "languages/",
manifest = "AndroidManifest.xml",
visibility = [
"//domain/src/main/java/org/oppia/android/domain/locale:__pkg__",
],
)
_SUPPORTED_REGIONS_CONFIG_ASSETS = {
support_level: generate_proto_binary_assets(
name = "%s_supported_regions_config_assets" % support_level,
asset_dir = "%slanguages" % support_level,
name_prefix = "%s_supported_regions_config_assets" % support_level,
names = ["supported_regions"],
proto_dep_bazel_target_prefix = "//model/src/main/proto",
proto_dep_name = "languages",
proto_package = "model",
proto_type_name = "SupportedRegions",
)
for support_level in _LANGUAGE_SUPPORT_LEVELS
}

[
android_library(
name = "%s_languages_config" % support_level,
assets = _SUPPORTED_LANGUAGES_CONFIG_ASSETS[support_level] +
_SUPPORTED_REGIONS_CONFIG_ASSETS[support_level],
assets_dir = "%slanguages/" % support_level,
manifest = "AndroidManifest.xml",
visibility = [
"//:oppia_binary_visibility",
"//:oppia_testing_visibility",
],
)
for support_level in _LANGUAGE_SUPPORT_LEVELS
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
language_definitions {
language: ENGLISH
min_android_sdk_version: 1
app_string_id {
ietf_bcp47_id {
ietf_language_tag: "en"
}
android_resources_language_id {
# Note that while English is the default language for Oppia & no special language code is
# needed for it, "en" is still used here for consistency. Technically this will match strings
# against "values-en", but because the team will never define strings with that qualifier they
# will always fallback to the default English strings under "values".
language_code: "en"
}
}
content_string_id {
ietf_bcp47_id {
ietf_language_tag: "en"
}
}
audio_translation_id {
ietf_bcp47_id {
ietf_language_tag: "en"
}
}
}
language_definitions {
language: PORTUGUESE
min_android_sdk_version: 1
content_string_id {
ietf_bcp47_id {
ietf_language_tag: "pt"
}
}
}
language_definitions {
language: BRAZILIAN_PORTUGUESE
fallback_macro_language: PORTUGUESE
min_android_sdk_version: 1
app_string_id {
ietf_bcp47_id {
ietf_language_tag: "pt-BR"
}
android_resources_language_id {
language_code: "pt"
region_code: "BR"
}
}
content_string_id {
ietf_bcp47_id {
ietf_language_tag: "pt-BR"
}
}
audio_translation_id {
ietf_bcp47_id {
ietf_language_tag: "pt-BR"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
region_definitions {
region: BRAZIL
region_id {
ietf_region_tag: "BR"
}
languages: PORTUGUESE
languages: BRAZILIAN_PORTUGUESE
}
region_definitions {
region: UNITED_STATES
region_id {
ietf_region_tag: "US"
}
languages: ENGLISH
}
region_definitions {
region: KENYA
region_id {
ietf_region_tag: "KE"
}
languages: ENGLISH
}
1 change: 1 addition & 0 deletions domain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ TEST_DEPS = [
"//app:crashlytics",
"//app:crashlytics_deps",
"//app/src/main/java/org/oppia/android/app/application/testing:testing_build_flavor_module",
"//config/src/java/org/oppia/android/config:all_languages_config",
"//data/src/main/java/org/oppia/android/data/backends/gae:network_config_prod_module",
"//data/src/main/java/org/oppia/android/data/backends/gae/model",
"//data/src/main/java/org/oppia/android/data/persistence:cache_store",
Expand Down
1 change: 1 addition & 0 deletions domain/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ android {
// exclusion in order to properly work.
def filesToExclude = [
'**/*LanguageConfigRetrieverTest*.kt',
'**/*LanguageConfigRetrieverProductionTest*.kt',
'**/*LocaleControllerTest*.kt',
'**/*TranslationControllerTest*.kt'
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ kt_android_library(
],
deps = [
":dagger",
"//config/src/java/org/oppia/android/config:languages_config",
"//model/src/main/proto:languages_java_proto_lite",
"//utility/src/main/java/org/oppia/android/util/caching:annotations",
"//utility/src/main/java/org/oppia/android/util/caching:asset_repository",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ oppia_android_test(
test_manifest = "//domain:test_manifest",
deps = [
":dagger",
"//config/src/java/org/oppia/android/config:all_languages_config",
"//domain",
"//domain/src/main/java/org/oppia/android/domain/classify:interactions_module",
"//domain/src/main/java/org/oppia/android/domain/classify/rules/algebraicexpressioninput:algebraic_expression_input_rule_module",
Expand Down
29 changes: 29 additions & 0 deletions domain/src/test/java/org/oppia/android/domain/locale/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ oppia_android_test(
test_manifest = "//domain:test_manifest",
deps = [
":dagger",
"//config/src/java/org/oppia/android/config:all_languages_config",
"//domain/src/main/java/org/oppia/android/domain/locale:content_locale_impl",
"//model/src/main/proto:languages_java_proto_lite",
"//third_party:androidx_test_ext_junit",
Expand All @@ -32,6 +33,32 @@ oppia_android_test(
test_manifest = "//domain:test_manifest",
deps = [
":dagger",
"//config/src/java/org/oppia/android/config:all_languages_config",
"//domain/src/main/java/org/oppia/android/domain/locale:language_config_retriever",
"//testing/src/main/java/org/oppia/android/testing/robolectric:test_module",
"//testing/src/main/java/org/oppia/android/testing/threading:test_module",
"//testing/src/main/java/org/oppia/android/testing/time:test_module",
"//third_party:androidx_test_ext_junit",
"//third_party:com_google_truth_extensions_truth-liteproto-extension",
"//third_party:com_google_truth_truth",
"//third_party:junit_junit",
"//third_party:org_robolectric_robolectric",
"//third_party:robolectric_android-all",
"//utility/src/main/java/org/oppia/android/util/caching:asset_prod_module",
"//utility/src/main/java/org/oppia/android/util/locale:prod_module",
"//utility/src/main/java/org/oppia/android/util/logging:prod_module",
],
)

oppia_android_test(
name = "LanguageConfigRetrieverProductionTest",
srcs = ["LanguageConfigRetrieverProductionTest.kt"],
custom_package = "org.oppia.android.domain.locale",
test_class = "org.oppia.android.domain.locale.LanguageConfigRetrieverProductionTest",
test_manifest = "//domain:test_manifest",
deps = [
":dagger",
"//config/src/java/org/oppia/android/config:production_languages_config",
"//domain/src/main/java/org/oppia/android/domain/locale:language_config_retriever",
"//testing/src/main/java/org/oppia/android/testing/robolectric:test_module",
"//testing/src/main/java/org/oppia/android/testing/threading:test_module",
Expand All @@ -56,6 +83,7 @@ oppia_android_test(
test_manifest = "//domain:test_manifest",
deps = [
":dagger",
"//config/src/java/org/oppia/android/config:all_languages_config",
"//domain/src/main/java/org/oppia/android/domain/locale:language_config_retriever",
"//testing/src/main/java/org/oppia/android/testing/robolectric:test_module",
"//testing/src/main/java/org/oppia/android/testing/threading:test_module",
Expand All @@ -77,6 +105,7 @@ oppia_android_test(
test_manifest = "//domain:test_manifest",
deps = [
":dagger",
"//config/src/java/org/oppia/android/config:all_languages_config",
"//domain/src/main/java/org/oppia/android/domain/locale:locale_controller",
"//domain/src/main/java/org/oppia/android/domain/oppialogger:prod_module",
"//domain/src/main/java/org/oppia/android/domain/oppialogger/analytics:prod_module",
Expand Down
Loading

0 comments on commit fea5b7e

Please sign in to comment.