mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2025-12-28 05:14:28 +00:00
add & use .scripts/locales.py for localeConfig
This commit is contained in:
parent
b9f380a2b8
commit
025be0e5e3
36
.scripts/locales.py
Executable file
36
.scripts/locales.py
Executable file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import subprocess
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
root = ET.parse("app/src/main/res/values/settings.xml").getroot()
|
||||
for e in root.findall("string-array"):
|
||||
if e.get("name") == "locale_values":
|
||||
locales = [x.text for x in e if x.text]
|
||||
break
|
||||
|
||||
locales = [
|
||||
# e.g. de or es-rAR (not es-AR)
|
||||
loc.replace("-", "-r") if "-" in loc and loc[loc.index("-") + 1] != "r" else loc
|
||||
for loc in locales
|
||||
]
|
||||
|
||||
res = ", ".join(f'"{loc}"' for loc in locales)
|
||||
sed = [
|
||||
"sed",
|
||||
"-i",
|
||||
f"s/resourceConfigurations .*/resourceConfigurations += [{res}]/",
|
||||
"app/build.gradle"
|
||||
]
|
||||
subprocess.run(sed, check=True)
|
||||
|
||||
with open("app/src/main/res/xml/locales_config.xml", "w") as fh:
|
||||
fh.write('<?xml version="1.0" encoding="utf-8"?>\n')
|
||||
fh.write('<locale-config xmlns:android="http://schemas.android.com/apk/res/android">\n')
|
||||
fh.write(' <locale android:name="en-US" />\n')
|
||||
for loc in locales:
|
||||
if loc != "en":
|
||||
# e.g. de or en-AR (not es-rAR)
|
||||
loc = loc.replace("-r", "-")
|
||||
fh.write(f' <locale android:name="{loc}" />\n')
|
||||
fh.write('</locale-config>\n')
|
||||
@ -24,6 +24,8 @@ android {
|
||||
|
||||
vectorDrawables.useSupportLibrary true
|
||||
multiDexEnabled true
|
||||
|
||||
resourceConfigurations += ["ar", "bg", "bn", "bn-rIN", "bs", "ca", "cs", "cy", "da", "de", "el-rGR", "en", "eo", "es", "es-rAR", "fi", "fr", "he-rIL", "hi", "hr", "hu", "in-rID", "is", "it", "ja", "ko", "lt", "lv", "nb-rNO", "nl", "oc", "pl", "pt", "ro-rRO", "ru", "sk", "sl", "sv", "tr", "uk", "zh-rTW", "zh-rCN"]
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
@ -81,11 +83,6 @@ android {
|
||||
lintConfig file('lint.xml')
|
||||
}
|
||||
namespace 'protect.card_locker'
|
||||
|
||||
androidResources {
|
||||
generateLocaleConfig true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@ -27,7 +27,8 @@
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
android:theme="@style/AppTheme"
|
||||
android:localeConfig="@xml/locales_config">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
@ -184,4 +185,4 @@
|
||||
</intent-filter>
|
||||
</service>
|
||||
</application>
|
||||
</manifest>
|
||||
</manifest>
|
||||
|
||||
45
app/src/main/res/xml/locales_config.xml
Normal file
45
app/src/main/res/xml/locales_config.xml
Normal file
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<locale android:name="en-US" />
|
||||
<locale android:name="ar" />
|
||||
<locale android:name="bg" />
|
||||
<locale android:name="bn" />
|
||||
<locale android:name="bn-IN" />
|
||||
<locale android:name="bs" />
|
||||
<locale android:name="ca" />
|
||||
<locale android:name="cs" />
|
||||
<locale android:name="cy" />
|
||||
<locale android:name="da" />
|
||||
<locale android:name="de" />
|
||||
<locale android:name="el-GR" />
|
||||
<locale android:name="eo" />
|
||||
<locale android:name="es" />
|
||||
<locale android:name="es-AR" />
|
||||
<locale android:name="fi" />
|
||||
<locale android:name="fr" />
|
||||
<locale android:name="he-IL" />
|
||||
<locale android:name="hi" />
|
||||
<locale android:name="hr" />
|
||||
<locale android:name="hu" />
|
||||
<locale android:name="in-ID" />
|
||||
<locale android:name="is" />
|
||||
<locale android:name="it" />
|
||||
<locale android:name="ja" />
|
||||
<locale android:name="ko" />
|
||||
<locale android:name="lt" />
|
||||
<locale android:name="lv" />
|
||||
<locale android:name="nb-NO" />
|
||||
<locale android:name="nl" />
|
||||
<locale android:name="oc" />
|
||||
<locale android:name="pl" />
|
||||
<locale android:name="pt" />
|
||||
<locale android:name="ro-RO" />
|
||||
<locale android:name="ru" />
|
||||
<locale android:name="sk" />
|
||||
<locale android:name="sl" />
|
||||
<locale android:name="sv" />
|
||||
<locale android:name="tr" />
|
||||
<locale android:name="uk" />
|
||||
<locale android:name="zh-TW" />
|
||||
<locale android:name="zh-CN" />
|
||||
</locale-config>
|
||||
Loading…
Reference in New Issue
Block a user