Skip to content

Commit c058c26

Browse files
authored
Merge pull request #2799 from element-hq/feature/bma/explicitLanguageListSupport
Add Explicit list of supported languages, generated from Localazy data.
2 parents 3435803 + 6ff1af3 commit c058c26

File tree

6 files changed

+119
-4
lines changed

6 files changed

+119
-4
lines changed

.github/workflows/sync-localazy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
- name: Run Localazy script
3434
run: |
3535
./tools/localazy/downloadStrings.sh --all
36+
./tools/localazy/importSupportedLocalesFromLocalazy.py
3637
./tools/test/generateAllScreenshots.py
3738
- name: Create Pull Request for Strings
3839
uses: peter-evans/create-pull-request@v6

app/build.gradle.kts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import extension.allServicesImpl
2323
import extension.gitBranchName
2424
import extension.gitRevision
2525
import extension.koverDependencies
26+
import extension.locales
2627
import extension.setupKover
2728

2829
plugins {
@@ -74,6 +75,10 @@ android {
7475
isUniversalApk = true
7576
}
7677
}
78+
79+
defaultConfig {
80+
resourceConfigurations += locales
81+
}
7782
}
7883

7984
signingConfigs {
@@ -165,10 +170,6 @@ android {
165170
buildConfigField("String", "FLAVOR_DESCRIPTION", "\"FDroid\"")
166171
}
167172
}
168-
169-
androidResources {
170-
generateLocaleConfig = true
171-
}
172173
}
173174

174175
androidComponents {

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
android:fullBackupContent="@xml/backup_rules"
3030
android:icon="@mipmap/ic_launcher"
3131
android:label="@string/app_name"
32+
android:localeConfig="@xml/locales_config"
3233
android:networkSecurityConfig="@xml/network_security_config"
3334
android:roundIcon="@mipmap/ic_launcher_round"
3435
android:supportsRtl="true"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!-- File generated by importSupportedLocalesFromLocalazy.py, do not edit -->
2+
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
3+
<locale android:name="be"/>
4+
<locale android:name="bg"/>
5+
<locale android:name="cs"/>
6+
<locale android:name="de"/>
7+
<locale android:name="en"/>
8+
<locale android:name="es"/>
9+
<locale android:name="fr"/>
10+
<locale android:name="hu"/>
11+
<locale android:name="in"/>
12+
<locale android:name="it"/>
13+
<locale android:name="ro"/>
14+
<locale android:name="ru"/>
15+
<locale android:name="sk"/>
16+
<locale android:name="sv"/>
17+
<locale android:name="uk"/>
18+
<locale android:name="zh-TW"/>
19+
</locale-config>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// File generated by importSupportedLocalesFromLocalazy.py, do not edit
2+
3+
package extension
4+
5+
val locales = setOf(
6+
"be",
7+
"bg",
8+
"cs",
9+
"de",
10+
"en",
11+
"es",
12+
"fr",
13+
"hu",
14+
"in",
15+
"it",
16+
"ro",
17+
"ru",
18+
"sk",
19+
"sv",
20+
"uk",
21+
"zh-rTW",
22+
)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import subprocess
5+
6+
7+
def getLocalesFromLocalazy():
8+
command = subprocess.run(
9+
["localazy languages --read-key a7876306080832595063-aa37154bb3772f6146890fca868d155b2228b492c56c91f67abdcdfb74d6142d --csv"],
10+
shell=True,
11+
capture_output=True,
12+
text=True,
13+
)
14+
data = command.stdout
15+
result = []
16+
for line in data.split("\n"):
17+
if line:
18+
line = line.split(",")
19+
if (line[6] == "true"):
20+
result.append(line[0])
21+
return sorted(result)
22+
23+
24+
def normalizeForResourceConfigurations(locale):
25+
match locale:
26+
case "id":
27+
return "in"
28+
case "zh_TW#Hant":
29+
return "zh-rTW"
30+
case _:
31+
return locale
32+
33+
34+
def normalizeForLocalConfig(locale):
35+
match locale:
36+
case "id":
37+
return "in"
38+
case "zh_TW#Hant":
39+
return "zh-TW"
40+
case _:
41+
return locale
42+
43+
44+
def generateLocaleFile(locales, file):
45+
with open("plugins/src/main/kotlin/extension/locales.kt", "w") as f:
46+
f.write("// File generated by " + file + ", do not edit\n\n")
47+
f.write("package extension\n\n")
48+
f.write("val locales = setOf(\n")
49+
for locale in locales:
50+
f.write(" \"" + normalizeForResourceConfigurations(locale) + "\",\n")
51+
f.write(")\n")
52+
53+
54+
def generateLocalesConfigFile(locales, file):
55+
with open("app/src/main/res/xml/locales_config.xml", "w") as f:
56+
f.write("<!-- File generated by " + file + ", do not edit -->\n")
57+
f.write('<locale-config xmlns:android="http://schemas.android.com/apk/res/android">\n')
58+
for locale in locales:
59+
f.write(" <locale android:name=\"" + normalizeForLocalConfig(locale) + "\"/>\n")
60+
f.write("</locale-config>\n")
61+
62+
63+
def main():
64+
file = os.path.basename(__file__)
65+
locales = getLocalesFromLocalazy()
66+
generateLocaleFile(locales, file)
67+
generateLocalesConfigFile(locales, file)
68+
69+
70+
if __name__ == "__main__":
71+
main()

0 commit comments

Comments
 (0)