[android] Implement automatic-per-app-languages #5665

Open
Nimausfi wants to merge 1 commit from Nimausfi/new-changes into master
6 changed files with 4 additions and 83 deletions

View file

@ -64,7 +64,6 @@
android:dataExtractionRules="@xml/backup_content_v31"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:localeConfig="@xml/locales_config"
android:theme="@style/MwmTheme"
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config"

View file

@ -159,7 +159,6 @@ android {
buildConfigField 'String', 'SUPPORT_MAIL', '"android@organicmaps.app"'
// Should be customized in flavors.
buildConfigField 'String', 'REVIEW_URL', '""'
resourceConfigurations += [project.ext.supportedLocalizations]
multiDexEnabled true
multiDexKeepFile file('multidex-config.txt')
@ -408,6 +407,9 @@ android {
androidResources {
ignoreAssetsPattern '!.svn:!.git:!.DS_Store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~'
noCompress 'txt', 'bin', 'html', 'png', 'json', 'mwm', 'ttf', 'sdf', 'ui', 'config', 'csv', 'spv', 'obj'
// Turn automatic per-app language feature on
generateLocaleConfig true
}
compileOptions {

View file

@ -11,5 +11,3 @@ android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
# Autogenerated by tools/unix/generate_localizations.sh
supportedLocalizations=af,ar,be,bg,ca,cs,da,de,el,en,en_GB,es,es_MX,et,eu,fa,fi,fr,fr_CA,iw,hi,hu,in,it,ja,ko,lt,mr,nb,nl,pl,pt,pt_BR,ro,ru,sk,sv,sw,th,tr,uk,vi,zh,zh_HK,zh_MO,zh_TW

View file

@ -0,0 +1 @@
unqualifiedResLocale=en-US
biodranik commented 2023-08-07 21:18:21 +00:00 (Migrated from github.com)
Review

Should it be en instead? Does it work with different languages?

Should it be en instead? Does it work with different languages?
Nimausfi commented 2023-08-07 22:53:08 +00:00 (Migrated from github.com)
Review

I chose en-US following the provided example here https://developer.android.com/build/releases/gradle-plugin#groovy, and I can change it based on your preference.
I haven't used different languages, but it is expected to work correctly.

I chose en-US following the provided example here https://developer.android.com/build/releases/gradle-plugin#groovy, and I can change it based on your preference. I haven't used different languages, but it is expected to work correctly.
biodranik commented 2023-08-07 23:57:22 +00:00 (Migrated from github.com)
Review

Please test all your changes on a real device.

Please test all your changes on a real device.
Nimausfi commented 2023-08-08 20:59:13 +00:00 (Migrated from github.com)
Review

It's working with other languages. Can you please verify using your device?

It's working with other languages. Can you please verify using your device?
biodranik commented 2023-08-08 22:31:19 +00:00 (Migrated from github.com)
Review

No, I can't. Did you test it with en-GB, en-AU, en-CA, etc.?

No, I can't. Did you test it with en-GB, en-AU, en-CA, etc.?
Nimausfi commented 2023-08-08 23:22:53 +00:00 (Migrated from github.com)
Review

Yes, I followed the steps in INSTALL.md for testing (using WSL)

Yes, I followed the steps in INSTALL.md for testing (using WSL)

View file

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
<locale android:name="en" />
<locale android:name="af" />
<locale android:name="ar" />
<locale android:name="be" />
<locale android:name="bg" />
<locale android:name="ca" />
<locale android:name="cs" />
<locale android:name="da" />
<locale android:name="de" />
<locale android:name="el" />
<locale android:name="en-GB" />
<locale android:name="es" />
<locale android:name="es-MX" />
<locale android:name="et" />
<locale android:name="eu" />
<locale android:name="fa" />
<locale android:name="fi" />
<locale android:name="fr" />
<locale android:name="fr-CA" />
<locale android:name="iw" />
<locale android:name="hi" />
<locale android:name="hu" />
<locale android:name="in" />
<locale android:name="it" />
<locale android:name="ja" />
<locale android:name="ko" />
<locale android:name="lt" />
<locale android:name="mr" />
<locale android:name="nb" />
<locale android:name="nl" />
<locale android:name="pl" />
<locale android:name="pt" />
<locale android:name="pt-BR" />
<locale android:name="ro" />
<locale android:name="ru" />
<locale android:name="sk" />
<locale android:name="sv" />
<locale android:name="sw" />
<locale android:name="th" />
<locale android:name="tr" />
<locale android:name="uk" />
<locale android:name="vi" />
<locale android:name="zh" />
<locale android:name="zh-HK" />
<locale android:name="zh-MO" />
<locale android:name="zh-TW" />
</locale-config>

View file

@ -67,33 +67,3 @@ cat "$STRINGS_PATH"/{strings,types_strings}.txt> "$MERGED_FILE"
"$TWINE" generate-all-localization-files --format jquery "$OMIM_PATH/data/strings/sound.txt" "$OMIM_PATH/data/sound-strings/"
rm "$MERGED_FILE"
# Generate list of languages and add list in gradle.properties to be used in build.gradle in resConfig
SUPPORTED_LOCALIZATIONS="supportedLocalizations="$(sed -nEe "s/ +([a-zA-Z]{2}(-[a-zA-Z]{2,})?) = .*$/\1/p" "data/strings/strings.txt" | sort -u | tr '\n' ',' | sed -e 's/-/_/g' -e 's/,$//')
# Chinese locales should correspond to Android codes.
SUPPORTED_LOCALIZATIONS=${SUPPORTED_LOCALIZATIONS/zh_Hans/zh}
SUPPORTED_LOCALIZATIONS=${SUPPORTED_LOCALIZATIONS/zh_Hant/zh_HK,zh_MO,zh_TW}
SUPPORTED_LOCALIZATIONS=${SUPPORTED_LOCALIZATIONS/he/iw}
SUPPORTED_LOCALIZATIONS=${SUPPORTED_LOCALIZATIONS/id/in}
GRADLE_PROPERTIES="$OMIM_PATH/android/gradle.properties"
if [ "$SUPPORTED_LOCALIZATIONS" != "$(grep supportedLocalizations "$GRADLE_PROPERTIES")" ]; then
sed -i .bak 's/supportedLocalizations.*/'"$SUPPORTED_LOCALIZATIONS"'/' "$GRADLE_PROPERTIES"
rm "$GRADLE_PROPERTIES.bak"
fi
# Generate locales_config.xml to allow users change app's language on Android 13+
LOCALES_CONFIG="$OMIM_PATH/android/res/xml/locales_config.xml"
SUPPORTED_LOCALIZATIONS=${SUPPORTED_LOCALIZATIONS/supportedLocalizations=/en,}
SUPPORTED_LOCALIZATIONS=${SUPPORTED_LOCALIZATIONS/,en,/,}
SUPPORTED_LOCALIZATIONS=${SUPPORTED_LOCALIZATIONS//_/-}
LOCALES_CONTENT='<?xml version="1.0" encoding="utf-8"?>
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">'
set +x
for lang in ${SUPPORTED_LOCALIZATIONS//,/ }; do
LOCALES_CONTENT="$LOCALES_CONTENT"$'\n'" <locale android:name=\"$lang\" />"
done
LOCALES_CONTENT="$LOCALES_CONTENT"$'\n''</locale-config>'
if [ "$LOCALES_CONTENT" != "$(cat "$LOCALES_CONFIG")" ]; then
echo "$LOCALES_CONTENT" > "$LOCALES_CONFIG"
echo Updated "$LOCALES_CONFIG" file
fi