Skip to content

Commit 15dcbf9

Browse files
feat(ui): update LanguageScreen layout, texts, and dynamic i18n
1 parent cde6671 commit 15dcbf9

2 files changed

Lines changed: 158 additions & 14 deletions

File tree

src/edit_python_pe/main.py

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,38 +105,77 @@ def compose(self) -> ComposeResult:
105105
class LanguageScreen(Screen):
106106
def compose(self) -> ComposeResult:
107107
with Vertical(id="lang-container"):
108-
yield Static("Select your language / Seleccione su idioma:")
108+
yield Static(
109+
_("Welcome aboard to Python Perú"),
110+
id="welcome-header",
111+
classes="header",
112+
)
113+
yield Static(_("Select your language"), id="lang-label")
109114
yield OptionList(
110115
"English",
111116
"Español",
112117
"Français",
113118
"Italiano",
114119
"Português",
115-
"Runa Simi (Quechua)",
120+
"Runa Simi",
116121
id="lang-select",
117122
)
118-
yield Button("Continue / Continuar", id="lang-continue")
123+
with Horizontal(id="lang-actions"):
124+
yield Button(_("Quit"), id="lang-quit", variant="error")
125+
yield Button(
126+
_("Continue"), id="lang-continue", variant="primary"
127+
)
128+
yield Static(
129+
_("Proudly built with 🤍 in Perú"),
130+
id="footer-msg",
131+
classes="footer",
132+
)
133+
134+
def on_option_list_option_highlighted(
135+
self, event: OptionList.OptionHighlighted
136+
) -> None:
137+
lang_map = {
138+
0: "en",
139+
1: "es",
140+
2: "fr",
141+
3: "it",
142+
4: "pt",
143+
5: "qu",
144+
}
145+
lang_code = (
146+
lang_map.get(event.option_index, "en")
147+
if event.option_index is not None
148+
else "en"
149+
)
150+
151+
set_language(lang_code)
152+
153+
# Update labels dynamically
154+
self.query_one("#welcome-header", Static).update(
155+
_("Welcome aboard to Python Perú")
156+
)
157+
self.query_one("#lang-label", Static).update(_("Select your language"))
158+
self.query_one("#lang-continue", Button).label = _("Continue")
159+
self.query_one("#lang-quit", Button).label = _("Quit")
160+
self.query_one("#footer-msg", Static).update(
161+
_("Proudly built with 🤍 in Perú")
162+
)
119163

120164
def on_button_pressed(self, event: Button.Pressed) -> None:
121-
if event.button.id == "lang-continue":
122-
lang_map = {
123-
0: "en",
124-
1: "es",
125-
2: "fr",
126-
3: "it",
127-
4: "pt",
128-
5: "qu",
129-
}
165+
if event.button.id == "lang-quit":
166+
self.app.exit()
167+
elif event.button.id == "lang-continue":
168+
# If the user clicks continue without highlighting an option,
169+
# make sure we set default
130170
opt_list = self.query_one("#lang-select", OptionList)
131171
selected_idx = opt_list.highlighted
172+
lang_map = {0: "en", 1: "es", 2: "fr", 3: "it", 4: "pt", 5: "qu"}
132173
lang_code = (
133174
lang_map.get(selected_idx, "en")
134175
if selected_idx is not None
135176
else "en"
136177
)
137-
138178
set_language(lang_code)
139-
140179
self.app.push_screen(AuthScreen())
141180

142181

src/edit_python_pe/styles.tcss

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/* styles.tcss */
2+
3+
LabeledInput {
4+
height: auto;
5+
}
6+
7+
LabeledInput Static {
8+
width: 25%;
9+
}
10+
11+
LabeledInput Input {
12+
width: 100%;
13+
}
14+
15+
SocialEntry Select {
16+
width: 25%;
17+
}
18+
19+
SocialEntry Input {
20+
width: 50%;
21+
}
22+
23+
SocialEntry Button {
24+
width: 25%;
25+
}
26+
27+
AliasEntry Input {
28+
width: 75%;
29+
}
30+
31+
AliasEntry Button {
32+
width: 25%;
33+
}
34+
35+
/* Base styles for screens and structure */
36+
37+
Screen {
38+
align: center middle;
39+
}
40+
41+
#form-container {
42+
padding: 1;
43+
}
44+
45+
#auth-container {
46+
width: 50%;
47+
height: auto;
48+
border: solid green;
49+
padding: 1;
50+
align: center middle;
51+
}
52+
53+
#auth-container Static {
54+
text-align: center;
55+
margin-bottom: 1;
56+
}
57+
58+
#lang-container {
59+
width: 50%;
60+
height: auto;
61+
border: solid blue;
62+
padding: 1;
63+
align: center middle;
64+
}
65+
66+
#lang-container Static {
67+
text-align: center;
68+
margin-bottom: 1;
69+
}
70+
71+
#lang-actions {
72+
align: center middle;
73+
height: auto;
74+
width: 100%;
75+
}
76+
77+
#lang-actions Button {
78+
margin: 1;
79+
}
80+
81+
.footer {
82+
text-align: center;
83+
color: gray;
84+
margin-top: 1;
85+
}
86+
87+
LoadingIndicator {
88+
margin-top: 1;
89+
}
90+
91+
.header {
92+
text-align: center;
93+
text-style: bold;
94+
margin-bottom: 1;
95+
}
96+
97+
.subheader {
98+
text-style: bold;
99+
margin-top: 1;
100+
}
101+
102+
.label {
103+
text-align: right;
104+
margin-right: 1;
105+
}

0 commit comments

Comments
 (0)