-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically sync changes to the "app_en.arb" to crowdin
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Add Crowdin Translation Strings | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
types: | ||
- closed | ||
|
||
jobs: | ||
check_changes: | ||
if: github.event.pull_request.merged == true | ||
runs-on: ubuntu-latest | ||
env: | ||
CROWDIN_API: ${{ secrets.CROWDIN_API }} | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 2 | ||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.11 | ||
- name: Watching for changes in app_en.arb and run Python script | ||
run: | | ||
CHANGED_FILES=$(git diff --name-only -r HEAD^1 HEAD) | ||
# Check if the specific file is in the changed files list | ||
if echo "$CHANGED_FILES" | grep -q 'app_en.arb'; then | ||
FILE=$(git diff HEAD^1:chameleonultragui/lib/l10n/app_en.arb HEAD:chameleonultragui/lib/l10n/app_en.arb --no-ext-diff --unified=0 -a --no-prefix | egrep "^\+") | ||
python chameleonultragui/lib/l10n/updateCrowdin.py "$FILE" | ||
else | ||
echo "The file 'app_en.arb' has not changed." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import sys | ||
import os | ||
import json | ||
from urllib.request import Request, urlopen | ||
|
||
def progressbar(it, prefix='', size=60, out=sys.stdout): | ||
count = len(it) | ||
|
||
def show(j): | ||
x = int(size * j / count) | ||
print(f"{prefix}[{u'█' * x}{('.' * (size - x))}] {j}/{count}", end='\r', file=out, flush=True) | ||
|
||
show(0) | ||
for i, item in enumerate(it): | ||
yield item | ||
show(i + 1) | ||
print('\n', flush=True, file=out) | ||
|
||
|
||
def request(method, url, data=None): | ||
if not data: | ||
data = {} | ||
return json.loads(urlopen(Request(url, method=method, data=json.dumps(data).encode(), | ||
headers={'Accept': 'application/json', | ||
'Authorization': 'Bearer ' + str(os.getenv('CROWDIN_API')), | ||
'Content-Type': 'application/json'})).read().decode()) | ||
|
||
def add_string_to_source(string): | ||
projectId = 611911 | ||
sourceId = 33 | ||
|
||
try: | ||
string_parsed = string.split('+++ chameleonultragui/lib/l10n/app_en.arb ', 1)[1].replace(' ', '').replace(',', '').replace('\n','').split('+')[1:] | ||
for s in string_parsed: | ||
data = {'identifier': key.replace('"', ''), 'text': value.replace('"', ''), 'fileId': sourceId} | ||
try: | ||
key, value = s.split(':') | ||
request('POST', f"https://api.crowdin.com/api/v2/projects/{projectId}/strings", data) | ||
print("Added: ", key) | ||
except Exception as e: | ||
print(e) | ||
|
||
except: | ||
print(e) | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) < 2: | ||
print("Uso: python script.py <cadena_a_agregar>") | ||
sys.exit(1) | ||
|
||
string_to_be_added = sys.argv[1] | ||
add_string_to_source(string_to_be_added) |