diff --git a/app.py b/app.py index 0b00a49..fddf1a2 100644 --- a/app.py +++ b/app.py @@ -2,10 +2,21 @@ import math from flask import Flask, render_template, request, send_file from weasyprint import HTML +from flask_babel import Babel, _ + import io app = Flask(__name__) +app.config['BABEL_DEFAULT_LOCALE'] = 'en' +app.config['BABEL_SUPPORTED_LOCALES'] = ['en', 'pl'] # Add supported languages here +app.config['BABEL_DEFAULT_TIMEZONE'] = 'UTC' +babel = Babel(app) + +@babel.localeselector +def get_locale(): + return request.accept_languages.best_match(app.config['BABEL_SUPPORTED_LOCALES']) + SHOOTOFF_DISTANCE = 1200 SHOOTOFF_GAP = 100 IPSC_DISTANCE = 914 @@ -213,6 +224,7 @@ def generate_pdf_ipsc(): distance = int(request.form.get('distance', 1) or 1) size = request.form.get('size') distance_type = request.form.get('distance_type') + target_type = request.form.get('target_type') scale = distance / IPSC_DISTANCE wall_extra_space_for_paper = 29.7 if size == 'a3' else 21.0 if distance_type == 'wall': @@ -236,7 +248,8 @@ def generate_pdf_ipsc(): preview_target_width=preview_scale * IPSC_TARGET_WIDTH, preview_margin=preview_margin, preview_gap=preview_scale * IPSC_GAP + preview_margin, - box_position=box_position + box_position=box_position, + target_type=target_type ) # return rendered_html diff --git a/babel.cfg b/babel.cfg new file mode 100644 index 0000000..fdff2e5 --- /dev/null +++ b/babel.cfg @@ -0,0 +1,2 @@ +[python: **.py] +[jinja2: templates/**.html] \ No newline at end of file diff --git a/messages.pot b/messages.pot new file mode 100644 index 0000000..8d7c120 --- /dev/null +++ b/messages.pot @@ -0,0 +1,18 @@ +# Translations template for PROJECT. +# Copyright (C) 2024 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# FIRST AUTHOR , 2024. +# +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2024-09-18 09:15+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.16.0\n" + diff --git a/static/images/idpa_el_presidente.webp b/static/images/idpa_el_presidente.webp new file mode 100644 index 0000000..fcdccce Binary files /dev/null and b/static/images/idpa_el_presidente.webp differ diff --git a/static/images/ipsc_el_presidente.webp b/static/images/ipsc_el_presidente.webp new file mode 100644 index 0000000..fdb5841 Binary files /dev/null and b/static/images/ipsc_el_presidente.webp differ diff --git a/templates/base.html b/templates/base.html index 6b98b5d..2572585 100644 --- a/templates/base.html +++ b/templates/base.html @@ -26,9 +26,9 @@ -
+

Paper Challenge

-

Wygeneruj tor {% block title %}{% endblock %}

+

{% trans %}Generate stage for{% endtrans %} {% block title %}{% endblock %}

+ {% block content %}{% endblock %}
+ diff --git a/templates/idpa_preview_svg.html b/templates/idpa_preview_svg.html new file mode 100644 index 0000000..f518c8d --- /dev/null +++ b/templates/idpa_preview_svg.html @@ -0,0 +1,7 @@ +
+ + + + + +
\ No newline at end of file diff --git a/templates/idpa_svg.html b/templates/idpa_svg.html new file mode 100644 index 0000000..8a8e2b8 --- /dev/null +++ b/templates/idpa_svg.html @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/templates/ipsc.html b/templates/ipsc.html index 37a8efe..38c16df 100644 --- a/templates/ipsc.html +++ b/templates/ipsc.html @@ -1,21 +1,35 @@ {% extends "base.html" %} -{% block title %}IPSC - El Presidente{% endblock %} +{% block title %}El Presidente{% endblock %} {% block content %}
{% include 'setup.html' %}
-

IPSC - El Presidente

+

{%trans%}Select the stage{%endtrans%}

-
- IPSC - El Presidente +
+
+ +
+
+ +
diff --git a/templates/ipsc_preview_svg.html b/templates/ipsc_preview_svg.html new file mode 100644 index 0000000..7fb0d77 --- /dev/null +++ b/templates/ipsc_preview_svg.html @@ -0,0 +1,7 @@ +
+ + + + + +
\ No newline at end of file diff --git a/templates/ipsc_svg.html b/templates/ipsc_svg.html new file mode 100644 index 0000000..635b127 --- /dev/null +++ b/templates/ipsc_svg.html @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/templates/pdf_template.html b/templates/pdf_template.html index b5140d4..3215817 100644 --- a/templates/pdf_template.html +++ b/templates/pdf_template.html @@ -82,17 +82,15 @@ {% endfor %}
-

Wymagana długość ściany: {{ wall_length/10 }}cm

-

Odległość od ściany: {{ distance|round(1,'ceil') }}cm

-

Przygotowanie toru:

+

{%trans%}Wall length required{%endtrans%}: {{ wall_length/10 }}cm

+

{%trans%}Distance from wall{%endtrans%}: {{ distance|round(1,'ceil') }}cm

+

{%trans%}Stage preparation{%endtrans%}:

    -
  • Umieść z lewej strony ściany pierwszy cel ze znacznikiem "punkt ZERO"
  • -
  • Wyznacz pole startowe {{ box_position }}cm od punktu "zero" (wzdłuż ściany) oraz w odległości {{distance}}cm od ściany
  • -
  • Upewnij się, że pole startowe znjaduje się w dogodnym miejscu, pomieszczenia, tak aby nic nie przeszkazdało - w swobodnym dobyciu i składaniu do celów na całej szerokości ściany -
  • -
  • W razie potrzeby dostosuj pierwszy cel wraz z punktem ZERO i powtórz dwa powyższe kroki
  • -
  • Umieść na ścianie pozostałe cele zgodnie z odległościami podanymi na znacznikach pozycji na dole każdego celu. Upewnij się, że wszystkie cele są umieszczone w jednej linii równoległej do podłoża
  • +
  • {%trans%}Place the first target with the 'ZERO point' marker on the left side of the wall{%endtrans%}
  • +
  • {%trans%}Set shooting box{%endtrans%} {{ box_position }}cm {%trans%}from 'ZERO' point (along the wall) and{%endtrans%} {{distance}}cm {%trans%}from the wall{%endtrans%}
  • +
  • {%trans%}Ensure that the starting field is positioned in a convenient location within the room, so that nothing obstructs the drawing and aiming at targets across the entire width of the wall{%endtrans%}
  • +
  • {%trans%}If necessary, adjust the first target along with the ZERO point and repeat the two previous steps{%endtrans%}
  • +
  • {%trans%}Place the remaining targets on the wall according to the distances indicated on the position markers at the bottom of each target. Ensure that all targets are aligned in a single line parallel to the ground{%endtrans%}
@@ -111,9 +109,9 @@ {% if target.target == 't1' %} -
punkt ZERO ({{ stage.split('_') | map('capitalize') | join(' ') }})
+
{%trans%}ZERO point{%endtrans%} ({{ stage.split('_') | map('capitalize') | join(' ') }})
{% else %} -
{{ target.position / 10 }}cm od punktu ZERO ({{ stage.split('_') | map('capitalize') | join(' ') }})
+
{{ target.position / 10 }}cm {%trans%}from ZERO point{%endtrans%} ({{ stage.split('_') | map('capitalize') | join(' ') }})
{% endif %}
diff --git a/templates/pdf_template_ipsc.html b/templates/pdf_template_ipsc.html index 5ba4b31..d36a3a7 100644 --- a/templates/pdf_template_ipsc.html +++ b/templates/pdf_template_ipsc.html @@ -66,44 +66,44 @@

IPSC - El Presidente

{% for i in range(3) %} -
- - - - - -
+ {% with preview_target_width = preview_target_width, preview_target_height = preview_target_height, preview_margin = preview_margin, preview_gap = preview_gap %} + {%if target_type == 'ipsc' %} + {%include 'ipsc_preview_svg.html'%} + {%else%} + {%include 'idpa_preview_svg.html'%} + {%endif%} + {% endwith %} {% endfor %}
-

Wymagana długość ściany: {{ wall_length|round(1,'ceil') }}cm

-

Odległość od ściany: {{ distance|round(1,'ceil') }}cm

-

Przygotowanie toru:

+

{%trans%}Wall length required{%endtrans%}: {{ wall_length|round(1,'ceil') }}cm

+

{%trans%}Distance from wall{%endtrans%}: {{ distance|round(1,'ceil') }}cm

+

{%trans%}Stage preparation{%endtrans%}:

    -
  • Umieść z lewej lub prawej strony ściany pierwszy cel ze znacznikiem "punkt ZERO"
  • -
  • Wyznacz pole startowe {{ box_position|round(1,'ceil') }}cm od punktu "zero" (wzdłuż ściany) oraz w odległości {{distance}}cm od ściany
  • -
  • Upewnij się, że pole startowe znjaduje się w dogodnym miejscu, pomieszczenia, tak aby nic nie - przeszkazdało - w swobodnym dobyciu i składaniu do celów na całej szerokości ściany -
  • -
  • W razie potrzeby dostosuj pierwszy cel wraz z punktem ZERO i powtórz dwa powyższe kroki
  • -
  • Umieść na ścianie pozostałe cele zgodnie z odległościami podanymi na znacznikach pozycji na dole każdego - celu. Upewnij się, że wszystkie cele są umieszczone w jednej linii równoległej do podłoża
  • +
  • {%trans%}Place the first target with the 'ZERO point' marker on the left or right side of the wall{%endtrans%}
  • +
  • {%trans%}Set shooting box{%endtrans%} {{ box_position|round(1,'ceil') }}cm {%trans%}from 'ZERO' point (along the wall) and{%endtrans%} {{distance}}cm {%trans%}from the wall{%endtrans%}
  • +
  • {%trans%}Ensure that the starting field is positioned in a convenient location within the room, so that nothing obstructs the drawing and aiming at targets across the entire width of the wall{%endtrans%}
  • +
  • {%trans%}If necessary, adjust the first target along with the ZERO point and repeat the two previous steps{%endtrans%}
  • +
  • {%trans%}Place the remaining targets on the wall according to the distances indicated on the position markers at the bottom of each target. Ensure that all targets are aligned in a single line parallel to the ground{%endtrans%}
+ {% for i in range(3) %}
- - - - - + {% with target_width=target_width, target_height=target_height %} + {%if target_type == 'ipsc' %} + {%include 'ipsc_svg.html'%} + {%else%} + {%include 'idpa_svg.html'%} + {%endif%} + {% endwith %} + {% if i==0 %} -
punkt ZERO (El Presidente)
+
{%trans%}ZERO point{%endtrans%} (El Presidente)
{% else %} -
{{ i * gap|round(1,'ceil') }}cm od punktu ZERO (El Presidente)
+
{{ i * gap|round(1,'ceil') }}cm {%trans%}from ZERO point{%endtrans%} (El Presidente)
{% endif %}
diff --git a/templates/pdf_template_shootoff.html b/templates/pdf_template_shootoff.html index e343de8..a1a8c86 100644 --- a/templates/pdf_template_shootoff.html +++ b/templates/pdf_template_shootoff.html @@ -109,22 +109,16 @@ {% endif %} {% endfor %}
- -

Wymagana długość ściany: {{ wall_length|round(1,'ceil') }}cm

-

Odległość od ściany: {{ distance|round(1,'ceil') }}cm

-

Przygotowanie toru:

+

{%trans%}Wall length required{%endtrans%}: {{ wall_length|round(1,'ceil') }}cm

+

{%trans%}Distance from wall{%endtrans%}: {{ distance|round(1,'ceil') }}cm

+

{%trans%}Stage preparation{%endtrans%}:

    -
  • Umieść z lewej lub prawej strony ściany pierwszy cel ze znacznikiem "punkt ZERO"
  • -
  • Wyznacz pole startowe {{ box_position|round(1,'ceil') }}cm od punktu "zero" (wzdłuż ściany) oraz w odległości {{distance}}cm od ściany
  • -
  • Upewnij się, że pole startowe znjaduje się w dogodnym miejscu, pomieszczenia, tak aby nic nie - przeszkazdało - w swobodnym dobyciu i składaniu do celów na całej szerokości ściany -
  • -
  • W razie potrzeby dostosuj pierwszy cel wraz z punktem ZERO i powtórz dwa powyższe kroki
  • -
  • Umieść na ścianie pozostałe cele zgodnie z odległościami podanymi na znacznikach pozycji na dole każdego - celu. Upewnij się, że wszystkie cele są umieszczone w jednej linii równoległej do podłoża
  • +
  • {%trans%}Place the first target with the 'ZERO point' marker on the left or right side of the wall{%endtrans%}
  • +
  • {%trans%}Set shooting box{%endtrans%} {{ box_position|round(1,'ceil') }}cm {%trans%}from 'ZERO' point (along the wall) and{%endtrans%} {{distance}}cm {%trans%}from the wall{%endtrans%}
  • +
  • {%trans%}Ensure that the starting field is positioned in a convenient location within the room, so that nothing obstructs the drawing and aiming at targets across the entire width of the wall{%endtrans%}
  • +
  • {%trans%}If necessary, adjust the first target along with the ZERO point and repeat the two previous steps{%endtrans%}
  • +
  • {%trans%}Place the remaining targets on the wall according to the distances indicated on the position markers at the bottom of each target. Ensure that all targets are aligned in a single line parallel to the ground{%endtrans%}
- {% for i in range(target_count) %}
@@ -158,9 +152,9 @@ {% endif %} {% if i==0 %} -
punkt ZERO (Shootoff)
+
{%trans%}ZERO point{%endtrans%} (Shootoff)
{% else %} -
{{ i * gap|round(1,'ceil') }}cm od punktu ZERO (Shootoff)
+
{{ i * gap|round(1,'ceil') }}cm {%trans%}from ZERO point{%endtrans%} (Shootoff)
{% endif %}
diff --git a/templates/sc.html b/templates/sc.html index 87f16e9..c1607c0 100644 --- a/templates/sc.html +++ b/templates/sc.html @@ -6,7 +6,7 @@ {% include 'setup.html' %}
-

Tor

+

{%trans%}Select the stage{%endtrans%}