feat: add i18n check as gh action

This commit is contained in:
Serhiy Mytrovtsiy
2021-04-20 22:41:28 +02:00
parent 327c543198
commit d8077097bb
3 changed files with 58 additions and 1 deletions

12
.github/workflows/check.yaml vendored Normal file
View File

@@ -0,0 +1,12 @@
name: Tests and checks
on: [push, pull_request]
jobs:
i18n:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: python3 i18n.py

View File

@@ -17,7 +17,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>229</string>
<string>230</string>
<key>Description</key>
<string>Simple macOS system monitor in your menu bar</string>
<key>LSApplicationCategoryType</key>

45
i18n.py Normal file
View File

@@ -0,0 +1,45 @@
import os
import sys
PATH = os.getcwd()+"/Stats/Supporting Files/"
def get_keys(list):
arr = []
for el in list:
if el.startswith("//") or len(el) == 0 or el == "\n":
continue
key = el.replace("\n", "").split(" = ")[0].replace('"', "")
arr.append(key)
return arr
def main():
en_file = open(f"{PATH}/en.lproj/Localizable.strings", "r").readlines()
if en_file == None:
sys.exit("English language not found.")
en_count = len(en_file)
en_keys = get_keys(en_file)
if len(en_keys) == 0:
sys.exit("No English keys found.")
languages = list(filter(lambda x: x.endswith(".lproj"), os.listdir(PATH)))
for lang in languages:
file = open(f"{PATH}/{lang}/Localizable.strings", "r").readlines()
count = len(file)
name = lang.replace(".lproj", "")
keys = get_keys(file)
if len(keys) == 0:
sys.exit(f"No {name} keys found.")
if count != en_count:
print(f"`{lang}` has different number of lines ({count}) than English ({en_count})\n")
for i, el in enumerate(en_keys):
if el != keys[i]:
sys.exit(f"line {i}: en=`{el}`; {name}=`{keys[i]}`\n")
print(f"All fine, found {en_count} lines in {len(languages)} languages.")
if __name__ == "__main__":
main()