From b8cbd2b382217f1d4a4fd7a4e5f949f79f290f22 Mon Sep 17 00:00:00 2001 From: Mihir Patel Date: Sat, 25 Mar 2023 19:25:39 +0000 Subject: [PATCH] Adding support for per-app language preferences on Android 13 and later Android 13 added the ability to select languages on a per-app basis. Supporting this feature simply requires us to provide a listing of all of the locales supported by the app: https://developer.android.com/guide/topics/resources/app-languages This change adds a locales_config.xml file to list the locales and references this file in the application manifest --- AndroidManifest.xml | 1 + StaticMessages.sh | 26 +++++++++++++++++++- res/xml/locales_config.xml | 50 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 res/xml/locales_config.xml diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 5c9f16a8..d6e26675 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -57,6 +57,7 @@ android:allowBackup="false" android:dataExtractionRules="@xml/data_extraction_rules" android:networkSecurityConfig="@xml/network_security_config" + android:localeConfig="@xml/locales_config" android:theme="@style/KdeConnectTheme.NoActionBar" android:name="org.kde.kdeconnect.MyApplication"> diff --git a/StaticMessages.sh b/StaticMessages.sh index 4c8fba6a..11659712 100644 --- a/StaticMessages.sh +++ b/StaticMessages.sh @@ -22,6 +22,30 @@ function import_po_files # First parameter will be a path that will contain seve # https://github.com/python-babel/babel/issues/566 find "$podir" -name '*.po' -exec msgattrib --no-obsolete -o {} {} \; ANSI_COLORS_DISABLED=1 a2po import --ignore-fuzzy --android res/ --gettext $podir + + # Generate the locales_config.xml + pushd res + echo '' > xml/locales_config.xml + echo '' >> xml/locales_config.xml + transform_locale_regex='(\w+)-r(\w+)' + # Add en-US as the first locale so that is the fallback, and also because it won't be handled in the following loop + echo -e '\t' >> xml/locales_config.xml + for i in values-*; do + if [ -d "${i}" ]; then + if [ -e "${i}/strings.xml" ]; then + locale="${i:7}" + if [[ "${locale}" =~ $transform_locale_regex ]]; then + # Special case to turn locales like "en-rUS", "en-rGB" into "en-US" and "en-GB" + transformed_locale="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}" + echo -e "\t" >> xml/locales_config.xml + else + echo -e "\t" >> xml/locales_config.xml + fi + fi + fi + done + + echo "" >> xml/locales_config.xml + popd } - diff --git a/res/xml/locales_config.xml b/res/xml/locales_config.xml new file mode 100644 index 00000000..4a69c554 --- /dev/null +++ b/res/xml/locales_config.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +