Skip to content

Commit 3101d41

Browse files
committed
Translation system (english + french)
1 parent 8ea8f43 commit 3101d41

13 files changed

Lines changed: 884 additions & 70 deletions

File tree

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ coverage.xml
5252
cover/
5353

5454
# Translations
55-
*.mo
56-
*.pot
55+
# *.mo
56+
# *.pot
5757

5858
# Django stuff:
5959
*.log

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include pyproxy/monitoring/messages.pot
2+
recursive-include pyproxy/monitoring/translations *

pyproxy/monitoring/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"""
88

99
import logging
10-
from flask import Flask
10+
from flask import Flask, request
11+
from flask_babel import Babel
1112
from .monitor import ProxyMonitor
1213
from .auth import create_basic_auth
1314
from .routes import register_routes
@@ -30,6 +31,24 @@ def start_flask_server(proxy_server, flask_port, flask_pass, debug) -> None:
3031
auth = create_basic_auth(flask_pass)
3132

3233
app = Flask(__name__, static_folder="static")
34+
app.config["BABEL_DEFAULT_LOCALE"] = "en"
35+
app.config["BABEL_SUPPORTED_LOCALES"] = ["fr", "en"]
36+
app.config["BABEL_DEFAULT_TIMEZONE"] = "Europe/London"
37+
38+
def select_locale():
39+
lang = request.args.get("lang")
40+
if lang in app.config["BABEL_SUPPORTED_LOCALES"]:
41+
return lang
42+
return request.accept_languages.best_match(app.config["BABEL_SUPPORTED_LOCALES"])
43+
44+
Babel(app, locale_selector=select_locale)
45+
46+
@app.context_processor
47+
def inject_globals():
48+
from flask_babel import get_locale
49+
50+
return {"get_locale": get_locale}
51+
3352
if not debug:
3453
log = logging.getLogger("werkzeug")
3554
log.setLevel(logging.ERROR)

pyproxy/monitoring/babel.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[python: **.py]
2+
3+
[jinja2: **/templates/**.html]
4+
encoding = utf-8

pyproxy/monitoring/messages.pot

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
# Translations template for PROJECT.
2+
# Copyright (C) 2025 ORGANIZATION
3+
# This file is distributed under the same license as the PROJECT project.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2025.
5+
#
6+
#, fuzzy
7+
msgid ""
8+
msgstr ""
9+
"Project-Id-Version: PROJECT VERSION\n"
10+
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
11+
"POT-Creation-Date: 2025-10-12 16:04+0200\n"
12+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14+
"Language-Team: LANGUAGE <LL@li.org>\n"
15+
"MIME-Version: 1.0\n"
16+
"Content-Type: text/plain; charset=utf-8\n"
17+
"Content-Transfer-Encoding: 8bit\n"
18+
"Generated-By: Babel 2.17.0\n"
19+
20+
#: routes.py:34 templates/index.html:19
21+
msgid "Next refresh in:"
22+
msgstr ""
23+
24+
#: routes.py:35 templates/index.html:31 templates/index.html:36
25+
msgid "Loading..."
26+
msgstr ""
27+
28+
#: routes.py:36
29+
msgid "Main Process"
30+
msgstr ""
31+
32+
#: routes.py:37
33+
msgid "Subprocesses"
34+
msgstr ""
35+
36+
#: routes.py:38 templates/index.html:23
37+
msgid "Status"
38+
msgstr ""
39+
40+
#: routes.py:39
41+
msgid "Configuration"
42+
msgstr ""
43+
44+
#: routes.py:40 templates/index.html:41
45+
msgid "Active Connections"
46+
msgstr ""
47+
48+
#: routes.py:41 templates/index.html:42
49+
msgid "Search client or target..."
50+
msgstr ""
51+
52+
#: routes.py:42
53+
msgid "Blocked sites"
54+
msgstr ""
55+
56+
#: routes.py:43
57+
msgid "Blocked URLs"
58+
msgstr ""
59+
60+
#: routes.py:44 templates/index.html:62
61+
msgid "Add"
62+
msgstr ""
63+
64+
#: routes.py:45 templates/index.html:51
65+
msgid "Add a domain or URL to block"
66+
msgstr ""
67+
68+
#: routes.py:46 templates/index.html:55
69+
msgid "Domain"
70+
msgstr ""
71+
72+
#: routes.py:47 templates/index.html:56
73+
msgid "URL"
74+
msgstr ""
75+
76+
#: routes.py:48 templates/index.html:59
77+
msgid "Value :"
78+
msgstr ""
79+
80+
#: routes.py:49 templates/index.html:26 templates/index.html:49
81+
msgid "Filtering"
82+
msgstr ""
83+
84+
#: routes.py:50
85+
msgid "No active connections."
86+
msgstr ""
87+
88+
#: routes.py:51
89+
msgid "No blocked sites."
90+
msgstr ""
91+
92+
#: routes.py:52
93+
msgid "No URLs blocked."
94+
msgstr ""
95+
96+
#: routes.py:53
97+
msgid "Error while deleting :"
98+
msgstr ""
99+
100+
#: routes.py:54
101+
msgid "Error adding :"
102+
msgstr ""
103+
104+
#: routes.py:55
105+
msgid "Please enter a value to block."
106+
msgstr ""
107+
108+
#: routes.py:56 routes.py:84
109+
msgid "Network error"
110+
msgstr ""
111+
112+
#: routes.py:57
113+
msgid "Error loading data:"
114+
msgstr ""
115+
116+
#: routes.py:58
117+
msgid "Name:"
118+
msgstr ""
119+
120+
#: routes.py:59
121+
msgid "PID:"
122+
msgstr ""
123+
124+
#: routes.py:60
125+
msgid "Status:"
126+
msgstr ""
127+
128+
#: routes.py:61
129+
msgid "Start Time:"
130+
msgstr ""
131+
132+
#: routes.py:62
133+
msgid "Client"
134+
msgstr ""
135+
136+
#: routes.py:63
137+
msgid "Target"
138+
msgstr ""
139+
140+
#: routes.py:64
141+
msgid "Sent"
142+
msgstr ""
143+
144+
#: routes.py:65
145+
msgid "Received"
146+
msgstr ""
147+
148+
#: routes.py:66
149+
msgid "bytes"
150+
msgstr ""
151+
152+
#: routes.py:67
153+
msgid "Port:"
154+
msgstr ""
155+
156+
#: routes.py:68
157+
msgid "Flask Port:"
158+
msgstr ""
159+
160+
#: routes.py:69
161+
msgid "HTML 403:"
162+
msgstr ""
163+
164+
#: routes.py:70
165+
msgid "Filter Configuration"
166+
msgstr ""
167+
168+
#: routes.py:71
169+
msgid "Blocked Sites File:"
170+
msgstr ""
171+
172+
#: routes.py:72
173+
msgid "Blocked URL File:"
174+
msgstr ""
175+
176+
#: routes.py:73
177+
msgid "Filter Mode:"
178+
msgstr ""
179+
180+
#: routes.py:74
181+
msgid "Logger Configuration"
182+
msgstr ""
183+
184+
#: routes.py:75
185+
msgid "Access Log:"
186+
msgstr ""
187+
188+
#: routes.py:76
189+
msgid "Block Log:"
190+
msgstr ""
191+
192+
#: routes.py:77
193+
msgid "SSL Inspection"
194+
msgstr ""
195+
196+
#: routes.py:78
197+
msgid "Inspect CA Cert:"
198+
msgstr ""
199+
200+
#: routes.py:79
201+
msgid "Inspect CA Key:"
202+
msgstr ""
203+
204+
#: routes.py:80
205+
msgid "Inspect certs folder:"
206+
msgstr ""
207+
208+
#: routes.py:81
209+
msgid "Cancel inspect:"
210+
msgstr ""
211+
212+
#: routes.py:82
213+
msgid "Action"
214+
msgstr ""
215+
216+
#: routes.py:83
217+
msgid "Unblock"
218+
msgstr ""
219+
220+
#: templates/index.html:24
221+
msgid "Settings"
222+
msgstr ""
223+
224+
#: templates/index.html:25
225+
msgid "Connections"
226+
msgstr ""
227+
228+
#: templates/index.html:60
229+
msgid "e.g.: example.com or http://example.com/page"
230+
msgstr ""
231+
232+
#: templates/index.html:65
233+
msgid "Search domain or URLs..."
234+
msgstr ""
235+

pyproxy/monitoring/routes.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
from flask import jsonify, render_template, request
10+
from flask_babel import _
1011

1112

1213
def register_routes(app, auth, proxy_server, ProxyMonitor):
@@ -29,7 +30,60 @@ def index():
2930
Returns:
3031
Response: Rendered HTML page.
3132
"""
32-
return render_template("index.html")
33+
translations = {
34+
"Next refresh in:": _("Next refresh in:"),
35+
"Loading...": _("Loading..."),
36+
"Main Process": _("Main Process"),
37+
"Subprocesses": _("Subprocesses"),
38+
"Status": _("Status"),
39+
"Configuration": _("Configuration"),
40+
"Active Connections": _("Active Connections"),
41+
"Search client or target...": _("Search client or target..."),
42+
"Blocked sites": _("Blocked sites"),
43+
"Blocked URLs": _("Blocked URLs"),
44+
"Add": _("Add"),
45+
"Add a domain or URL to block": _("Add a domain or URL to block"),
46+
"Domain": _("Domain"),
47+
"URL": _("URL"),
48+
"Value :": _("Value :"),
49+
"Filtering": _("Filtering"),
50+
"No active connections.": _("No active connections."),
51+
"No blocked sites.": _("No blocked sites."),
52+
"No URLs blocked.": _("No URLs blocked."),
53+
"Error while deleting :": _("Error while deleting :"),
54+
"Error adding :": _("Error adding :"),
55+
"Please enter a value to block.": _("Please enter a value to block."),
56+
"Network error": _("Network error"),
57+
"Error loading data:": _("Error loading data:"),
58+
"Name:": _("Name:"),
59+
"PID:": _("PID:"),
60+
"Status:": _("Status:"),
61+
"Start Time:": _("Start Time:"),
62+
"Client": _("Client"),
63+
"Target": _("Target"),
64+
"Sent": _("Sent"),
65+
"Received": _("Received"),
66+
"bytes": _("bytes"),
67+
"Port:": _("Port:"),
68+
"Flask Port:": _("Flask Port:"),
69+
"HTML 403:": _("HTML 403:"),
70+
"Filter Configuration": _("Filter Configuration"),
71+
"Blocked Sites File:": _("Blocked Sites File:"),
72+
"Blocked URL File:": _("Blocked URL File:"),
73+
"Filter Mode:": _("Filter Mode:"),
74+
"Logger Configuration": _("Logger Configuration"),
75+
"Access Log:": _("Access Log:"),
76+
"Block Log:": _("Block Log:"),
77+
"SSL Inspection": _("SSL Inspection"),
78+
"Inspect CA Cert:": _("Inspect CA Cert:"),
79+
"Inspect CA Key:": _("Inspect CA Key:"),
80+
"Inspect certs folder:": _("Inspect certs folder:"),
81+
"Cancel inspect:": _("Cancel inspect:"),
82+
"Action": _("Action"),
83+
"Unblock": _("Unblock"),
84+
"Network error:": _("Network error"),
85+
}
86+
return render_template("index.html", translations=translations)
3387

3488
@app.route("/api/status", methods=["GET"])
3589
@auth.login_required

0 commit comments

Comments
 (0)