-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add locale checker to CI * Just pip install Django * Add gettext package to OS * Add sudo to apt-get * Use @2ykwang 's updated script * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Only update on push to master * To avoid pain points of PRs and histories being split * Trying to use Andrew's username for pushing to see if that works * Use separate workflow file Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1ea72de
commit 6587c2a
Showing
3 changed files
with
128 additions
and
1 deletion.
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,61 @@ | ||
name: Locale Updater | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
|
||
jobs: | ||
locale-updater: | ||
name: Locale updater | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
|
||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.9' | ||
|
||
- name: Get pip cache dir | ||
id: pip-cache | ||
run: | | ||
echo "::set-output name=dir::$(pip cache dir)" | ||
- name: Cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.pip-cache.outputs.dir }} | ||
key: | ||
3.9-v1-${{ hashFiles('**/setup.py') }} | ||
restore-keys: | | ||
3.9-v1- | ||
- name: Install dependencies | ||
run: | | ||
sudo apt-get install -y gettext | ||
python -m pip install --upgrade pip wheel setuptools | ||
pip install -e .[dev] | ||
- name: Run locale | ||
working-directory: rest_framework_simplejwt | ||
run: | | ||
python ../scripts/i18n_updater.py | ||
- name: Commit locale changes | ||
uses: stefanzweifel/git-auto-commit-action@v4 | ||
id: auto-commit-action | ||
with: | ||
commit_message: "Update locale files" | ||
file_pattern: rest_framework_simplejwt/locale/** | ||
commit_user_name: Andrew-Chen-Wang | ||
commit_user_email: acwangpython@gmail.com | ||
commit_author: Andrew-Chen-Wang | ||
|
||
- name: Tell whether locale updated | ||
if: steps.auto-commit-action.outputs.changes_detected == 'true' | ||
run: echo "Locale files updated" |
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
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,58 @@ | ||
import contextlib | ||
import os | ||
import subprocess | ||
|
||
|
||
def get_list_of_files(dir_name: str, extension: str): | ||
file_list = os.listdir(dir_name) | ||
|
||
result = [] | ||
for entry in file_list: | ||
full_path = os.path.join(dir_name, entry) | ||
if os.path.isdir(full_path): | ||
result = result + get_list_of_files(full_path, extension) | ||
else: | ||
if entry[-len(extension) : len(entry)] == extension: | ||
result.append(full_path) | ||
|
||
return result | ||
|
||
|
||
@contextlib.contextmanager | ||
def cache_creation(): | ||
# DO NOT cache the line number; the file may change | ||
cache: dict[str, str] = {} | ||
for file in get_list_of_files("./", ".po"): | ||
if os.path.isdir(file): | ||
continue | ||
|
||
with open(file) as f: | ||
for line in f.readlines(): | ||
if line.startswith('"POT-Creation-Date: '): | ||
cache[file] = line | ||
break | ||
yield | ||
for file, line_cache in cache.items(): | ||
with open(file, "r+") as f: | ||
lines = f.readlines() | ||
# clear file | ||
f.seek(0) | ||
f.truncate() | ||
|
||
# find line | ||
index = [ | ||
lines.index(x) for x in lines if x.startswith('"POT-Creation-Date: ') | ||
][0] | ||
|
||
lines[index] = line_cache | ||
f.writelines(lines) | ||
|
||
|
||
def main(): | ||
with cache_creation(): | ||
subprocess.run(["django-admin", "makemessages", "-a"]) | ||
subprocess.run(["django-admin", "compilemessages"]) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |