Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial translation mechanism setup #13

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/**
!requirements.txt
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ end_of_line = lf
indent_style = space
insert_final_newline = true
indent_size = 2

[*.py]
indent_size = 4
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: test

on:
push:
pull_request:

permissions:
contents: read

jobs:
test-schemas:
runs-on: ubuntu-latest
name: Test if schemas were generated
steps:
- uses: actions/checkout@v4

- uses: isbang/[email protected]
with:
up-flags: "--build"
down-flags: "--volumes"

- name: Generate images
run: docker exec -i ship-it-boardgame-renderer-1 python render.py

- name: Verify diff
run: git diff --exit-code
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.12-alpine

WORKDIR /app

COPY . .

RUN pip install --no-cache-dir -r requirements.txt

CMD [ "sleep", "infinity" ]
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ Thanks a lot to my friends, who helped me with ideas, testing, and rules.

Please, add yourself to `AUTHORS` if you contributed in anyway :)

## Render Schemas Locally

To render the schemas locally you just need a working [Docker](https://www.docker.com) installation:
```shell
# Run required services to render
docker compose up -d

# Tells our renderer service to render everything
docker exec -it ship-it-boardgame-renderer-1 python render.py

# Teardown the renderer environment
docker compose down --remove-orphans
```

## LICENSE

[CC BY-NC-SA 4.0](https://github.com/sobolevn/ship-it-boardgame/blob/master/LICENSE)
Expand Down
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3'
services:
renderer:
build:
dockerfile: Dockerfile
depends_on:
image-export:
condition: service_healthy
volumes:
- "./render.py:/app/render.py"
- "./ru:/app/ru"
image-export:
image: jgraph/export-server
healthcheck:
test: [ "CMD-SHELL", "if [ $(curl -o /dev/null -s -w '%{http_code}\n' http://localhost:8000) -ne '400' ]; then exit 1; fi;" ]
interval: 2s
timeout: 5s
retries: 5
ports:
- "8000:8000"
52 changes: 52 additions & 0 deletions render.py
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this file to tools/
and name it render-diagram.py

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import shutil
import logging
from typing import Final

import yaml
import requests
from jinja2 import Environment, FileSystemLoader, select_autoescape

logging.basicConfig(
format='%(asctime)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
level=logging.INFO,
)
logger = logging.getLogger(__name__)

# Add your language folder below when it's ready to be rendered
LANGUAGE_FOLDERS: Final = {'ru'}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LANGUAGE_FOLDERS: Final = {'ru'}
LANGUAGE_FOLDERS: Final = frozenset({'ru'})



def render_schemas(language: str) -> None:
logger.info('[%s] rendering language', language)

with open(f'{language}/schemas-info.yml') as f:
info = yaml.safe_load(f)

for template_name in env.list_templates():
logger.info('[%s] rendering template "%s"', language, template_name)

rendered = env.get_template(template_name).render(**info)

logger.info('[%s] generating schema image from template', language)
response = requests.post(
'http://image-export:8000/',
json={'format': 'jpg', 'xml': rendered},
stream=True,
)
assert response.status_code == 200, response.text
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert response.status_code == 200, response.text
response.raise_for_status()


image_name, *_ = template_name.split('.')
logger.info('[%s] saving image %s.jpg', language, image_name)
with open(f'{language}/schemas/{image_name}.jpg', 'wb') as f:
shutil.copyfileobj(response.raw, f)


if __name__ == '__main__':
env = Environment(
loader=FileSystemLoader('ru/schema-sources'),
autoescape=select_autoescape(),
)

for language in LANGUAGE_FOLDERS:
render_schemas(language)
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
certifi==2024.2.2
charset-normalizer==3.3.2
idna==3.6
Jinja2==3.1.3
MarkupSafe==2.1.5
PyYAML==6.0.1
requests==2.31.0
urllib3==2.2.1
30 changes: 15 additions & 15 deletions ru/schema-sources/atack1-1.drawio
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,43 @@
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="2" value="Рука Алисы" style="swimlane;whiteSpace=wrap" parent="1" vertex="1">
<mxCell id="2" value="{{ attack.first_player_hand }}" style="swimlane;whiteSpace=wrap" parent="1" vertex="1">
<mxGeometry x="444.5" y="128" width="280" height="570" as="geometry" />
</mxCell>
<mxCell id="dYky7ozjCTGvR8onbQTt-42" value="&lt;div&gt;Закрытая карта&lt;/div&gt;" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=-180;" parent="2" vertex="1">
<mxCell id="dYky7ozjCTGvR8onbQTt-42" value="&lt;div&gt;{{ attack.face_down_card }}&lt;/div&gt;" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=-180;" parent="2" vertex="1">
<mxGeometry x="40" y="102" width="200" height="122" as="geometry" />
</mxCell>
<mxCell id="dYky7ozjCTGvR8onbQTt-43" value="&lt;div&gt;Закрытая карта&lt;/div&gt;" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=-180;" parent="2" vertex="1">
<mxCell id="dYky7ozjCTGvR8onbQTt-43" value="&lt;div&gt;{{ attack.face_down_card }}&lt;/div&gt;" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=-180;" parent="2" vertex="1">
<mxGeometry x="40" y="225" width="200" height="122" as="geometry" />
</mxCell>
<mxCell id="3" value="Стол Алисы" style="swimlane;whiteSpace=wrap" parent="1" vertex="1">
<mxCell id="3" value="{{ attack.first_player_table }}" style="swimlane;whiteSpace=wrap" parent="1" vertex="1">
<mxGeometry x="724.5" y="128" width="280" height="570" as="geometry" />
</mxCell>
<mxCell id="dYky7ozjCTGvR8onbQTt-59" value="&lt;div&gt;Компонент&lt;/div&gt;" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=-180;fillColor=#e1d5e7;strokeColor=#9673a6;" parent="3" vertex="1">
<mxCell id="dYky7ozjCTGvR8onbQTt-59" value="&lt;div&gt;{{ card.component.name }}&lt;/div&gt;" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=-180;fillColor=#e1d5e7;strokeColor=#9673a6;" parent="3" vertex="1">
<mxGeometry x="40.5" y="224" width="200" height="122" as="geometry" />
</mxCell>
<mxCell id="dYky7ozjCTGvR8onbQTt-60" value="&lt;div align=&quot;center&quot; style=&quot;font-size: 20px;&quot;&gt;&lt;font style=&quot;font-size: 20px;&quot;&gt;Бекенд&lt;br&gt;&lt;/font&gt;&lt;/div&gt;&lt;div align=&quot;center&quot;&gt;&lt;br&gt;&lt;/div&gt;" style="text;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;rotation=-270;" parent="dYky7ozjCTGvR8onbQTt-59" vertex="1">
<mxCell id="dYky7ozjCTGvR8onbQTt-60" value="&lt;div align=&quot;center&quot; style=&quot;font-size: 20px;&quot;&gt;&lt;font style=&quot;font-size: 20px;&quot;&gt;{{ card.component.types.backend }}&lt;br&gt;&lt;/font&gt;&lt;/div&gt;&lt;div align=&quot;center&quot;&gt;&lt;br&gt;&lt;/div&gt;" style="text;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;rotation=-270;" parent="dYky7ozjCTGvR8onbQTt-59" vertex="1">
<mxGeometry x="26" y="46" width="140" height="30" as="geometry" />
</mxCell>
<mxCell id="dYky7ozjCTGvR8onbQTt-41" value="Сброс" style="swimlane;whiteSpace=wrap" parent="1" vertex="1">
<mxCell id="dYky7ozjCTGvR8onbQTt-41" value="{{ attack.discard }}" style="swimlane;whiteSpace=wrap" parent="1" vertex="1">
<mxGeometry x="1004.5" y="128" width="280" height="570" as="geometry" />
</mxCell>
<mxCell id="-ga4N_1VcacRzFCh5T7P-6" value="&lt;div&gt;Сброс&lt;/div&gt;" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=90;" vertex="1" parent="dYky7ozjCTGvR8onbQTt-41">
<mxCell id="-ga4N_1VcacRzFCh5T7P-6" value="&lt;div&gt;{{ attack.discard }}&lt;/div&gt;" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=90;" vertex="1" parent="dYky7ozjCTGvR8onbQTt-41">
<mxGeometry x="40" y="225" width="200" height="122" as="geometry" />
</mxCell>
<mxCell id="dYky7ozjCTGvR8onbQTt-74" value="Рука Бориса" style="swimlane;whiteSpace=wrap" parent="1" vertex="1">
<mxCell id="dYky7ozjCTGvR8onbQTt-74" value="{{ attack.second_player_hand }}" style="swimlane;whiteSpace=wrap" parent="1" vertex="1">
<mxGeometry x="1284.5" y="128" width="280" height="570" as="geometry" />
</mxCell>
<mxCell id="dYky7ozjCTGvR8onbQTt-75" value="&lt;div&gt;Закрытая карта&lt;/div&gt;" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=0;" parent="dYky7ozjCTGvR8onbQTt-74" vertex="1">
<mxCell id="dYky7ozjCTGvR8onbQTt-75" value="&lt;div&gt;{{ attack.face_down_card }}&lt;/div&gt;" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=0;" parent="dYky7ozjCTGvR8onbQTt-74" vertex="1">
<mxGeometry x="40" y="102" width="200" height="122" as="geometry" />
</mxCell>
<mxCell id="dYky7ozjCTGvR8onbQTt-76" value="&lt;div&gt;Закрытая карта&lt;/div&gt;" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=0;" parent="dYky7ozjCTGvR8onbQTt-74" vertex="1">
<mxCell id="dYky7ozjCTGvR8onbQTt-76" value="&lt;div&gt;{{ attack.face_down_card }}&lt;/div&gt;" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=0;" parent="dYky7ozjCTGvR8onbQTt-74" vertex="1">
<mxGeometry x="40" y="225" width="200" height="122" as="geometry" />
</mxCell>
<mxCell id="RGcuCvIUBXCjisr0QKUh-6" value="Атака" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=0;fillColor=#f8cecc;strokeColor=#b85450;" parent="dYky7ozjCTGvR8onbQTt-74" vertex="1">
<mxCell id="RGcuCvIUBXCjisr0QKUh-6" value="{{ card.attack.name }}" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=0;fillColor=#f8cecc;strokeColor=#b85450;" parent="dYky7ozjCTGvR8onbQTt-74" vertex="1">
<mxGeometry x="5.5" y="392" width="200" height="122" as="geometry" />
</mxCell>
<mxCell id="RGcuCvIUBXCjisr0QKUh-7" value="&lt;div align=&quot;center&quot; style=&quot;font-size: 20px;&quot;&gt;&lt;font style=&quot;font-size: 20px;&quot;&gt;Ошибка&lt;br&gt;&lt;/font&gt;&lt;/div&gt;&lt;div align=&quot;center&quot;&gt;&lt;br&gt;&lt;/div&gt;" style="text;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;rotation=-90;" parent="RGcuCvIUBXCjisr0QKUh-6" vertex="1">
<mxCell id="RGcuCvIUBXCjisr0QKUh-7" value="&lt;div align=&quot;center&quot; style=&quot;font-size: 20px;&quot;&gt;&lt;font style=&quot;font-size: 20px;&quot;&gt;{{ card.attack.types.error }}&lt;br&gt;&lt;/font&gt;&lt;/div&gt;&lt;div align=&quot;center&quot;&gt;&lt;br&gt;&lt;/div&gt;" style="text;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;rotation=-90;" parent="RGcuCvIUBXCjisr0QKUh-6" vertex="1">
<mxGeometry x="30" y="46" width="140" height="30" as="geometry" />
</mxCell>
<mxCell id="-ga4N_1VcacRzFCh5T7P-5" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;strokeWidth=3;" edge="1" parent="1" source="-ga4N_1VcacRzFCh5T7P-3" target="RGcuCvIUBXCjisr0QKUh-6">
Expand All @@ -49,10 +49,10 @@
<mxCell id="-ga4N_1VcacRzFCh5T7P-9" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=1;entryY=0.75;entryDx=0;entryDy=0;strokeWidth=3;" edge="1" parent="1" source="-ga4N_1VcacRzFCh5T7P-3" target="-ga4N_1VcacRzFCh5T7P-6">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="-ga4N_1VcacRzFCh5T7P-3" value="&lt;div&gt;Защита&lt;/div&gt;" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=-180;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
<mxCell id="-ga4N_1VcacRzFCh5T7P-3" value="&lt;div&gt;{{ card.defense.name }}&lt;/div&gt;" style="swimlane;horizontal=0;whiteSpace=wrap;html=1;rotation=-180;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
<mxGeometry x="520" y="520" width="200" height="122" as="geometry" />
</mxCell>
<mxCell id="-ga4N_1VcacRzFCh5T7P-4" value="&lt;div align=&quot;center&quot; style=&quot;font-size: 20px;&quot;&gt;&lt;font style=&quot;font-size: 20px;&quot;&gt;Отговорка&lt;br&gt;&lt;/font&gt;&lt;/div&gt;" style="text;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;rotation=-270;" vertex="1" parent="-ga4N_1VcacRzFCh5T7P-3">
<mxCell id="-ga4N_1VcacRzFCh5T7P-4" value="&lt;div align=&quot;center&quot; style=&quot;font-size: 20px;&quot;&gt;&lt;font style=&quot;font-size: 20px;&quot;&gt;{{ card.defense.types.escape }}&lt;br&gt;&lt;/font&gt;&lt;/div&gt;" style="text;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;rotatable=0;whiteSpace=wrap;html=1;rotation=-270;" vertex="1" parent="-ga4N_1VcacRzFCh5T7P-3">
<mxGeometry x="30" y="46" width="140" height="30" as="geometry" />
</mxCell>
<mxCell id="-ga4N_1VcacRzFCh5T7P-10" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.25;exitDx=0;exitDy=0;entryX=1;entryY=0.25;entryDx=0;entryDy=0;strokeWidth=3;" edge="1" parent="1" source="RGcuCvIUBXCjisr0QKUh-6" target="-ga4N_1VcacRzFCh5T7P-6">
Expand Down
Loading