Skip to content

Commit 1f0a302

Browse files
authored
[UI/UX:System] Localization repository (#1)
Configure localization repository.
1 parent 64032bd commit 1f0a302

File tree

9 files changed

+229
-0
lines changed

9 files changed

+229
-0
lines changed

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
max-line-length=100
3+
exclude=
4+
.git,
5+
.venv

.github/workflows/bump-submitty.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Bump Submitty
2+
3+
on:
4+
repository_dispatch:
5+
types: [version-up]
6+
workflow_dispatch:
7+
8+
jobs:
9+
update-submitty:
10+
runs-on: ubuntu-latest
11+
name: Update Submitty
12+
steps:
13+
- name: Checkout Submitty Repository
14+
uses: actions/checkout@v3
15+
with:
16+
repository: ${{ github.repository_owner }}/Submitty
17+
sparse-checkout: |
18+
site/app/templates
19+
sparse-checkout-cone-mode: false
20+
ref: ${{ github.event.client_payload.ref }}
21+
path: Submitty
22+
23+
- name: Checkout Localization Repository
24+
uses: actions/checkout@v3
25+
with:
26+
path: Localization
27+
28+
- name: Get version
29+
id: version
30+
uses: notiz-dev/[email protected]
31+
with:
32+
path: Localization/config.json
33+
prop_path: submitty_version
34+
35+
- uses: actions/setup-python@v4
36+
with:
37+
python-version: 3.11
38+
39+
- name: Run Version Update
40+
run: python3 Localization/bin/update-version.py -v ${{ github.event.client_payload.ref_name }}
41+
42+
- name: Create Pull Request
43+
uses: Submitty/[email protected]
44+
with:
45+
token: ${{ secrets.SUBMITTYBOT_DEPENDENCY_TOKEN }}
46+
path: Localization
47+
commit-message: update version and base lang to ${{ github.event.client_payload.ref_name }}
48+
branch: bump-submitty/${{ github.event.client_payload.ref_name }}
49+
title: "[Dependency] Update Submitty from ${{ steps.version.outputs.prop }} to ${{ github.event.client_payload.ref_name }}"
50+
body: "Bumps [Submitty](https://github.com/${{ github.repository_owner }}/Submitty) from version [${{ steps.version.outputs.prop }}](https://github.com/${{ github.repository_owner }}/Submitty/releases/tag/${{ steps.version.outputs.prop }}) to [${{ github.event.client_payload.ref_name }}](https://github.com/${{ github.repository_owner }}/Submitty/releases/tag/${{ github.event.client_payload.ref_name }})."

.github/workflows/localization-ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Localization CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
yaml-lint:
12+
name: YAML Lint
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Install yamllint
17+
run: sudo apt-get install -y yamllint
18+
- name: Run yamllint
19+
run: yamllint .
20+
21+
python-lint:
22+
name: Python Lint
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v3
26+
- uses: actions/setup-python@v4
27+
with:
28+
python-version: 3.11
29+
- name: Install flake8
30+
run: |
31+
python3 -m pip install --upgrade pip
32+
python3 -m pip install flake8 flake8-bugbear
33+
- name: Run flake8
34+
run: python3 -m flake8

.github/workflows/pr-title.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: 'Submitty PR Title Check'
2+
on:
3+
pull_request:
4+
# check when PR
5+
# * is created,
6+
# * title is edited, and
7+
# * new commits are added (to ensure failing title blocks merging)
8+
types: [opened, reopened, edited, synchronize]
9+
10+
jobs:
11+
title-check:
12+
runs-on: ubuntu-latest
13+
steps:
14+
#
15+
# pull request titles format rules here:
16+
# https://submitty.org/developer/how_to_contribute#how-to-make-a-pull-request-pr-to-submitty
17+
#
18+
# [<TYPE>:<MODULE>] <SUBJECT>
19+
#
20+
- uses: submitty/action-pr-title@main

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.venv/

.yamllint

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extends: default
2+
3+
rules:
4+
line-length: disable
5+
truthy: disable
6+
document-start: disable
7+
8+
ignore:
9+
.git
10+
.venv

bin/update-version.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import json
2+
import re
3+
from argparse import ArgumentParser, Namespace
4+
from collections import OrderedDict
5+
from pathlib import Path
6+
7+
8+
def get_args() -> Namespace:
9+
parser = ArgumentParser(prog='update-version')
10+
parser.add_argument('-v', '--version', required=True)
11+
return parser.parse_args()
12+
13+
14+
def get_template_data() -> dict:
15+
pattern = re.compile(r"localize\s*?\(\s*?(?P<q1>[\'\"])(?P<key>[\w\.]+?)\s*?(?P=q1)"
16+
r",\s*?(?P<q2>[\'\"])(?P<val>.+?)(?<!\\\\)(?P=q2)\s*?.*?\)")
17+
18+
template_path = Path(__file__).parent.parent.parent / 'Submitty' / 'site' / 'app' / 'templates'
19+
if not template_path.is_dir():
20+
raise NotADirectoryError('Could not locate template directory.')
21+
22+
data = dict()
23+
24+
# Loop through template files
25+
for child in template_path.iterdir():
26+
if not child.is_file() or child.suffix != '.twig':
27+
continue
28+
29+
# Split into template blocks {{ }}
30+
body = child.read_text()
31+
parts = [part.split('}}')[0] for part in body.split('{{')[1:]]
32+
33+
for part in parts:
34+
for match in re.finditer(pattern, part):
35+
group = match.groupdict()
36+
tree = group.get('key').split('.')
37+
val = group.get('val')
38+
39+
last_key = tree.pop()
40+
41+
loc = data # Current location in tree (should always be dict)
42+
for key in tree:
43+
if key in loc:
44+
loc = loc[key]
45+
if not isinstance(loc, dict):
46+
raise KeyError('Duplicate template key found: ' + key)
47+
else:
48+
loc[key] = dict()
49+
loc = loc[key]
50+
51+
if not isinstance(loc, dict):
52+
raise KeyError('Duplicate template key found: ' + key)
53+
loc[last_key] = val
54+
55+
return data
56+
57+
58+
def update_data(original: OrderedDict, updated: dict) -> OrderedDict:
59+
result = OrderedDict()
60+
61+
# Update existing keys
62+
for key, val in original.items():
63+
if key not in updated:
64+
continue
65+
66+
if isinstance(val, OrderedDict) and isinstance(updated[key], dict):
67+
result[key] = update_data(val, updated[key])
68+
else:
69+
result[key] = updated[key]
70+
71+
# Add new keys
72+
for key, val in updated.items():
73+
if key not in original:
74+
if isinstance(val, dict):
75+
result[key] = OrderedDict(val)
76+
else:
77+
result[key] = val
78+
79+
return result
80+
81+
82+
def main():
83+
args = get_args()
84+
85+
repo_path = Path(__file__).parent.parent
86+
if not repo_path.is_dir():
87+
raise NotADirectoryError('Could not locate repository.')
88+
89+
# Update version in JSON file
90+
with (repo_path / 'config.json').open() as file:
91+
data = json.load(file, object_pairs_hook=OrderedDict)
92+
data['submitty_version'] = args.version
93+
with (repo_path / 'config.json').open('w') as file:
94+
json.dump(data, file, indent=2)
95+
96+
# Update default lang data
97+
with (repo_path / 'lang' / 'en_US.json').open() as file:
98+
json_data = json.load(file, object_pairs_hook=OrderedDict)
99+
json_data = update_data(json_data, get_template_data())
100+
with (repo_path / 'lang' / 'en_US.json').open('w') as file:
101+
json.dump(json_data, file, indent=4)
102+
103+
104+
if __name__ == '__main__':
105+
main()

config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"submitty_version": "v23.08.00"
3+
}

lang/en_US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)