make CI add langs from weblate

This commit is contained in:
Cloudburst 2022-12-25 19:49:59 +01:00 committed by GitHub
parent 2ba78eb37e
commit 9c956f68f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 32 deletions

47
.github/locales.py vendored Normal file
View file

@ -0,0 +1,47 @@
import re
import glob
import requests
SETTINGS_PATH = "app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsGeneral.kt"
START_MARKER = "/* begin language list */"
END_MARKER = "/* end language list */"
XML_NAME = "app/src/main/res/values-"
ISO_MAP_URL = "https://gist.githubusercontent.com/Josantonius/b455e315bc7f790d14b136d61d9ae469/raw"
INDENT = " "*4
iso_map = requests.get(ISO_MAP_URL, timeout=300).json()
# Load settings file
src = open(SETTINGS_PATH, "r", encoding='utf-8').read()
before_src, rest = src.split(START_MARKER)
rest, after_src = rest.split(END_MARKER)
# Load already added langs
languages = {}
for lang in re.finditer(r'Triple\("(.*)", "(.*)", "(.*)"\)', rest):
flag, name, iso = lang.groups()
languages[iso] = (flag, name)
# Add not yet added langs
for folder in glob.glob(f"{XML_NAME}*"):
iso = folder[len(XML_NAME):]
if iso not in languages.keys():
languages[iso] = ("", iso_map.get(iso.lower(),iso))
# Create triples
triples = []
for iso in sorted(languages.keys()):
flag, name = languages[iso]
triples.append(f'{INDENT}Triple("{flag}", "{name}", "{iso}"),')
# Update settings file
open(SETTINGS_PATH, "w+",encoding='utf-8').write(
before_src +
START_MARKER +
"\n" +
"\n".join(triples) +
"\n" +
END_MARKER +
after_src
)

27
.github/workflows/update_locales.yml vendored Normal file
View file

@ -0,0 +1,27 @@
name: Update locale lists
on:
push:
paths:
- '**.xml'
concurrency:
group: "locale-list"
cancel-in-progress: true
jobs:
create:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Edit files
run: |
python3 .github/locales.py
- name: Commit to the repo
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git add .
# "echo" returns true so the build succeeds, even if no changed files
git commit -m 'chore: update list of locales' || echo
git push

View file

@ -20,33 +20,4 @@
### Supported languages:
<a href="https://hosted.weblate.org/engage/cloudstream/">
<img src="https://hosted.weblate.org/widgets/cloudstream/-/app/multi-auto.svg" alt="Translation status" />
</a>
<!--
***The list of supported languages:***
* 🇱🇧 Arabic
* 🇧🇬 Bulgarian
* 🇨🇳 Chinese Simplified
* 🇹🇼 Chinese Traditional
* 🇭🇷 Croatian
* 🇨🇿 Czech
* 🇳🇱 Dutch
* 🇬🇧 English
* 🇫🇷 French
* 🇩🇪 German
* 🇬🇷 Greek
* 🇮🇳 Hindi
* 🇮🇩 Indonesian
* 🇮🇹 Italian
* 🇲🇰 Macedonian
* 🇮🇳 Malayalam
* 🇳🇴 Norsk
* 🇵🇱 Polish
* 🇧🇷 Portuguese (Brazil)
* 🇷🇴 Romanian
* 🇪🇸 Spanish
* 🇸🇪 Swedish
* 🇵🇭 Tagalog
* 🇹🇷 Turkish
* 🇻🇳 Vietnamese
-->
</a>

View file

@ -116,7 +116,7 @@ object CommonActivity {
* when setting the app language.
**/
val appLanguageExceptions = hashMapOf(
"zh_TW" to Locale.TRADITIONAL_CHINESE
"zh-TW" to Locale.TRADITIONAL_CHINESE
)
fun setLocale(context: Context?, languageCode: String?) {

View file

@ -55,6 +55,7 @@ fun getCurrentLocale(context: Context): String {
// Emoji Character Encoding Data --> C/C++/Java Src
// https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes leave blank for auto
val appLanguages = arrayListOf(
/* begin language list */
Triple("", "Spanish", "es"),
Triple("", "English", "en"),
Triple("", "Viet Nam", "vi"),
@ -76,12 +77,13 @@ val appLanguages = arrayListOf(
Triple("", "Romanian", "ro"),
Triple("", "Italian", "it"),
Triple("", "Chinese Simplified", "zh"),
Triple("\uD83C\uDDF9\uD83C\uDDFC", "Chinese Traditional", "zh_TW"),
Triple("\uD83C\uDDF9\uD83C\uDDFC", "Chinese Traditional", "zh-TW"),
Triple("\uD83C\uDDEE\uD83C\uDDE9", "Indonesian", "in"),
Triple("", "Czech", "cs"),
Triple("", "Croatian", "hr"),
Triple("", "Bulgarian", "bg"),
Triple("", "Bengali", "bn"),
/* end language list */
).sortedBy { it.second } //ye, we go alphabetical, so ppl don't put their lang on top
class SettingsGeneral : PreferenceFragmentCompat() {