levix-bot 4.6.0 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/views/login.ejs CHANGED
@@ -1,25 +1,26 @@
1
1
  <!DOCTYPE html>
2
- <html lang="en" data-theme="dark">
2
+ <html data-brand="<%= brand.name %>">
3
3
  <head>
4
+ <script src="/ui-boot.js"></script>
4
5
  <meta charset="UTF-8" />
5
6
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
- <title><%= brand.name %> · Sign in</title>
7
+ <title data-i18n="titleLogin"><%= brand.name %> · Sign in</title>
7
8
  <link rel="icon" type="image/png" sizes="32x32" href="/brand/icon-32.png" />
8
9
  <link rel="apple-touch-icon" href="/brand/apple-touch-icon.png" />
9
10
  <link rel="stylesheet" href="/dashboard.css" />
10
11
  </head>
11
12
  <body class="gateway-page">
12
13
  <main class="gateway-shell">
13
- <section class="gateway-story" aria-label="About <%= brand.name %>">
14
+ <section class="gateway-story" aria-label="About <%= brand.name %>" data-i18n-aria-label="storyAbout">
14
15
  <div class="brand-lockup" aria-label="<%= brand.name %>">
15
16
  <img src="/brand/mark.svg" alt="" />
16
- <span><strong><%= brand.name %></strong><small><%= brand.tagline %></small></span>
17
+ <span><strong><%= brand.name %></strong><small data-i18n="tagline"><%= brand.tagline %></small></span>
17
18
  </div>
18
19
 
19
20
  <div class="gateway-copy">
20
- <span class="eyebrow">Self-hosted by design</span>
21
- <h2>The quiet control room behind every chat.</h2>
22
- <p>Connection, commands, memory, and moderation stay together—on your server and within reach.</p>
21
+ <span class="eyebrow" data-i18n="selfHosted">Self-hosted by design</span>
22
+ <h2 data-i18n="loginHeadline">The quiet control room behind every chat.</h2>
23
+ <p data-i18n="loginLede">Connection, commands, memory, and moderation stay together—on your server and within reach.</p>
23
24
  </div>
24
25
 
25
26
  <div class="gateway-mark" aria-hidden="true">
@@ -27,7 +28,7 @@
27
28
  <img src="/brand/mark.svg" alt="" />
28
29
  </div>
29
30
 
30
- <p class="gateway-trust"><span></span> Private workspace · direct control</p>
31
+ <p class="gateway-trust" data-i18n-html="loginTrust"><span></span> Private workspace · direct control</p>
31
32
  </section>
32
33
 
33
34
  <section class="gateway-panel">
@@ -35,26 +36,27 @@
35
36
  <form class="card auth-card" id="login-card" action="/login" method="post">
36
37
  <button type="button" class="gateway-back-btn" id="login-back-app" hidden>
37
38
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
38
- <span>Back to app</span>
39
+ <span data-i18n="backToApp">Back to app</span>
39
40
  </button>
40
41
  <div class="auth-head">
41
- <span class="eyebrow">Secure access</span>
42
- <h1>Welcome back</h1>
43
- <p class="sub">Sign in to manage your Levix workspace.</p>
42
+ <span class="eyebrow" data-i18n="secureAccess">Secure access</span>
43
+ <h1 data-i18n="welcomeBack">Welcome back</h1>
44
+ <p class="sub" data-i18n="loginSub">Sign in to manage your Levix workspace.</p>
44
45
  </div>
45
46
 
46
47
  <label class="field">
47
- <span>Control panel password</span>
48
+ <span data-i18n="passwordLabel">Control panel password</span>
48
49
  <div class="input-wrap">
49
50
  <input
50
- type="password"
51
+ type="password" dir="ltr" spellcheck="false" autocapitalize="off" autocorrect="off"
51
52
  name="password"
52
53
  autocomplete="current-password"
53
54
  placeholder="Enter your password"
55
+ data-i18n-placeholder="passwordPlaceholder"
54
56
  autofocus
55
57
  required
56
58
  />
57
- <button type="button" class="eye-btn" aria-label="Show password">
59
+ <button type="button" class="eye-btn" aria-label="Show password" data-i18n-aria-label="showPassword" aria-pressed="false">
58
60
  <svg class="eye-on" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
59
61
  <svg class="eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c6.5 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3.5 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
60
62
  </button>
@@ -62,41 +64,41 @@
62
64
  </label>
63
65
 
64
66
  <button type="submit" class="btn btn-primary auth-submit">
65
- Open workspace
67
+ <span data-i18n="openWorkspace">Open workspace</span>
66
68
  <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
67
69
  </button>
68
70
 
69
71
  <% if (error) { %>
70
- <div class="error" role="alert"><%= error %></div>
72
+ <div class="error" role="alert" data-i18n-error="<%= errorCode %>" data-i18n-n="<%= minLength %>"><%= error %></div>
71
73
  <% } %>
72
74
 
73
75
  <div class="auth-alt">
74
- <button type="button" class="link-btn" id="forgot-link">Forgot password?</button>
76
+ <button type="button" class="link-btn" id="forgot-link" data-i18n="forgotPassword">Forgot password?</button>
75
77
  </div>
76
78
  </form>
77
79
 
78
80
  <div class="card auth-card" id="reset-card" hidden>
79
81
  <button type="button" class="gateway-back-btn" id="reset-back">
80
82
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
81
- <span>Back to sign in</span>
83
+ <span data-i18n="backToSignIn">Back to sign in</span>
82
84
  </button>
83
85
  <div class="auth-head">
84
- <span class="eyebrow">Password reset</span>
85
- <h1>Reset your password</h1>
86
- <p class="sub">
86
+ <span class="eyebrow" data-i18n="resetEyebrow">Password reset</span>
87
+ <h1 data-i18n="resetTitle">Reset your password</h1>
88
+ <p class="sub" data-i18n="resetSubtitle">
87
89
  Levix sends a one-time code to your WhatsApp — the linked account's own chat.
88
90
  The code works for 10 minutes.
89
91
  </p>
90
92
  </div>
91
93
 
92
94
  <button type="button" class="btn btn-primary auth-submit" id="reset-send">
93
- Send code to WhatsApp
95
+ <span data-i18n="resetSend">Send code to WhatsApp</span>
94
96
  <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
95
97
  </button>
96
98
 
97
99
  <form id="reset-form" hidden>
98
100
  <label class="field">
99
- <span>Reset code</span>
101
+ <span data-i18n="resetCodeLabel">Reset code</span>
100
102
  <input
101
103
  type="text"
102
104
  id="reset-code"
@@ -104,22 +106,25 @@
104
106
  autocomplete="one-time-code"
105
107
  maxlength="6"
106
108
  placeholder="6 digits"
109
+ data-i18n-placeholder="resetCodePlaceholder"
107
110
  required
108
111
  />
109
112
  </label>
110
113
 
111
114
  <label class="field">
112
- <span>New password</span>
115
+ <span data-i18n="newPassword">New password</span>
113
116
  <div class="input-wrap">
114
117
  <input
115
- type="password"
118
+ type="password" dir="ltr" spellcheck="false" autocapitalize="off" autocorrect="off"
116
119
  id="reset-pass"
117
120
  autocomplete="new-password"
118
121
  placeholder="At least <%= minLength %> characters"
122
+ data-i18n-placeholder="minLengthPlaceholder"
123
+ data-i18n-n="<%= minLength %>"
119
124
  minlength="<%= minLength %>"
120
125
  required
121
126
  />
122
- <button type="button" class="eye-btn" aria-label="Show password">
127
+ <button type="button" class="eye-btn" aria-label="Show password" data-i18n-aria-label="showPassword" aria-pressed="false">
123
128
  <svg class="eye-on" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
124
129
  <svg class="eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c6.5 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3.5 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
125
130
  </button>
@@ -127,17 +132,18 @@
127
132
  </label>
128
133
 
129
134
  <label class="field">
130
- <span>Repeat password</span>
135
+ <span data-i18n="repeatPassword">Repeat password</span>
131
136
  <div class="input-wrap">
132
137
  <input
133
- type="password"
138
+ type="password" dir="ltr" spellcheck="false" autocapitalize="off" autocorrect="off"
134
139
  id="reset-confirm"
135
140
  autocomplete="new-password"
136
141
  placeholder="Type it again"
142
+ data-i18n-placeholder="repeatPlaceholder"
137
143
  minlength="<%= minLength %>"
138
144
  required
139
145
  />
140
- <button type="button" class="eye-btn" aria-label="Show password">
146
+ <button type="button" class="eye-btn" aria-label="Show password" data-i18n-aria-label="showPassword" aria-pressed="false">
141
147
  <svg class="eye-on" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
142
148
  <svg class="eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c6.5 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3.5 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
143
149
  </button>
@@ -145,7 +151,7 @@
145
151
  </label>
146
152
 
147
153
  <button type="submit" class="btn btn-primary auth-submit">
148
- Set new password
154
+ <span data-i18n="resetSubmit">Set new password</span>
149
155
  <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
150
156
  </button>
151
157
  </form>
@@ -154,35 +160,25 @@
154
160
 
155
161
  </div>
156
162
 
157
- <div class="foot"><%= brand.name %> by <%= brand.developer %> · <%= brand.studio %></div>
163
+ <div class="foot"><%= brand.name %> <span data-i18n="by">by</span> <%= brand.developer %> · <%= brand.studio %></div>
158
164
  </div>
159
165
  </section>
160
166
  </main>
161
167
 
168
+ <script src="/gateway-i18n.js"></script>
162
169
  <script src="/gateway.js"></script>
163
170
  <script>
164
171
  (function () {
165
- // Android app: show back-to-app buttons, localize labels
172
+ var t = window.LevixGatewayI18n.t;
173
+
174
+ // Android app: show the back-to-app button. Its label is already in
175
+ // whichever language the page loaded in.
166
176
  var inApp = typeof window.LevixHost !== "undefined" && typeof window.LevixHost.closePanel === "function";
167
177
  if (inApp) {
168
- var isAr = false;
169
- try { isAr = localStorage.getItem("levix_lang") === "ar"; } catch(e) {}
170
- var backLabel = isAr ? "العودة للتطبيق" : "Back to app";
171
- var resetBackLabel = isAr ? "العودة لتسجيل الدخول" : "Back to sign in";
172
- ["login-back-app"].forEach(function(id) {
173
- var btn = document.getElementById(id);
174
- if (btn) {
175
- btn.hidden = false;
176
- btn.querySelector("span").textContent = backLabel;
177
- if (isAr) { btn.dir = "rtl"; btn.style.direction = "rtl"; }
178
- btn.addEventListener("click", function() { window.LevixHost.closePanel(); });
179
- }
180
- });
181
- var resetBackBtn = document.getElementById("reset-back");
182
- if (resetBackBtn && isAr) {
183
- resetBackBtn.querySelector("span").textContent = resetBackLabel;
184
- resetBackBtn.dir = "rtl";
185
- resetBackBtn.style.direction = "rtl";
178
+ var backBtn = document.getElementById("login-back-app");
179
+ if (backBtn) {
180
+ backBtn.hidden = false;
181
+ backBtn.addEventListener("click", function() { window.LevixHost.closePanel(); });
186
182
  }
187
183
  }
188
184
 
@@ -201,13 +197,52 @@
201
197
  loginCard.hidden = false;
202
198
  document.getElementById("forgot-link").focus();
203
199
  }
204
- function showError(text) {
205
- errorBox.textContent = text;
200
+ var getT = function () {
201
+ return window.LevixGatewayI18n ? window.LevixGatewayI18n.t : function (k) { return k; };
202
+ };
203
+ var currentErrorState = null;
204
+
205
+ function renderCurrentError() {
206
+ if (!currentErrorState) return;
207
+ var t = getT();
208
+ if (currentErrorState.type === "simple") {
209
+ errorBox.textContent = t(currentErrorState.key, currentErrorState.vars);
210
+ } else if (currentErrorState.type === "wrong_code") {
211
+ var msg = t("resetErrWrongCode");
212
+ if (currentErrorState.attemptsLeft) {
213
+ msg += " " + t("resetErrAttemptsLeft", { n: currentErrorState.attemptsLeft });
214
+ }
215
+ errorBox.textContent = msg;
216
+ } else if (currentErrorState.type === "invalid_password") {
217
+ errorBox.textContent =
218
+ window.LevixGatewayI18n && window.LevixGatewayI18n.lang === "ar"
219
+ ? t("resetErrInvalidPassword")
220
+ : currentErrorState.message || t("resetErrInvalidPassword");
221
+ } else if (currentErrorState.type === "raw") {
222
+ errorBox.textContent = currentErrorState.text;
223
+ }
206
224
  errorBox.hidden = false;
207
225
  }
226
+
227
+ function showErrorKey(key, vars) {
228
+ currentErrorState = { type: "simple", key: key, vars: vars };
229
+ renderCurrentError();
230
+ }
231
+ function showError(text) {
232
+ currentErrorState = { type: "raw", text: text };
233
+ renderCurrentError();
234
+ }
208
235
  function hideError() {
236
+ currentErrorState = null;
209
237
  errorBox.hidden = true;
210
238
  }
239
+
240
+ window.addEventListener("levix-gateway-lang", renderCurrentError);
241
+ window.addEventListener("levix-ui-prefs", renderCurrentError);
242
+ window.addEventListener("storage", function (e) {
243
+ if (e.key === "levix_lang") renderCurrentError();
244
+ });
245
+
211
246
  async function postJson(url, body) {
212
247
  const response = await fetch(url, {
213
248
  method: "POST",
@@ -240,19 +275,16 @@
240
275
  form.hidden = false;
241
276
  document.getElementById("reset-code").focus();
242
277
  } else if (result.reason === "throttled") {
243
- showError("Too many requests. Try again in " + (result.retryAfter || 60) + " seconds.");
278
+ showErrorKey("resetErrThrottled", { n: String(result.retryAfter || 60) });
244
279
  } else if (result.reason === "no_session") {
245
- showError(
246
- "WhatsApp isn't connected, so the code can't be sent. " +
247
- "Sign in on the server and run `levix reset-password`, or start the WhatsApp session first."
248
- );
280
+ showErrorKey("resetErrNoSession");
249
281
  } else if (result.reason === "send_failed") {
250
- showError("Couldn't send the WhatsApp message. Try again in a minute.");
282
+ showErrorKey("resetErrSendFailed");
251
283
  } else {
252
- showError("Couldn't start the reset. Try again.");
284
+ showErrorKey("resetErrStart");
253
285
  }
254
286
  } catch {
255
- showError("Couldn't reach the server. Try again.");
287
+ showErrorKey("resetErrServer");
256
288
  }
257
289
  sendBtn.disabled = false;
258
290
  });
@@ -269,34 +301,33 @@
269
301
  if (result.ok) {
270
302
  form.hidden = true;
271
303
  sendBtn.hidden = true;
272
- showError("Password updated. Taking you to sign in…");
304
+ showErrorKey("resetDone");
273
305
  setTimeout(function () {
274
306
  window.location.href = "/";
275
307
  }, 900);
276
308
  return;
277
309
  }
278
310
  if (result.reason === "wrong_code") {
279
- showError(
280
- "Wrong code." +
281
- (result.attemptsLeft ? " " + result.attemptsLeft + " attempts left." : "")
282
- );
311
+ currentErrorState = { type: "wrong_code", attemptsLeft: result.attemptsLeft };
312
+ renderCurrentError();
283
313
  } else if (
284
314
  result.reason === "expired" ||
285
315
  result.reason === "no_pending" ||
286
316
  result.reason === "too_many_attempts"
287
317
  ) {
288
- showError("That code is no longer valid. Send a new one.");
318
+ showErrorKey("resetErrExpired");
289
319
  form.hidden = true;
290
320
  sendBtn.hidden = false;
291
321
  } else if (result.reason === "mismatch") {
292
- showError("The two passwords don't match.");
322
+ showErrorKey("resetErrMismatch");
293
323
  } else if (result.reason === "invalid_password") {
294
- showError(result.message || "That password isn't allowed.");
324
+ currentErrorState = { type: "invalid_password", message: result.message };
325
+ renderCurrentError();
295
326
  } else {
296
- showError("Couldn't reset the password. Try again.");
327
+ showErrorKey("resetErrFailed");
297
328
  }
298
329
  } catch {
299
- showError("Couldn't reach the server. Try again.");
330
+ showErrorKey("resetErrServer");
300
331
  }
301
332
  });
302
333
  })();
package/views/qr.ejs CHANGED
@@ -1,25 +1,26 @@
1
1
  <!DOCTYPE html>
2
- <html lang="en" data-theme="dark">
2
+ <html data-brand="<%= brand.name %>">
3
3
  <head>
4
+ <script src="/ui-boot.js"></script>
4
5
  <meta charset="UTF-8" />
5
6
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
- <title><%= brand.name %> · Link WhatsApp</title>
7
+ <title data-i18n="titleQr"><%= brand.name %> · Link WhatsApp</title>
7
8
  <link rel="icon" type="image/png" sizes="32x32" href="/brand/icon-32.png" />
8
9
  <link rel="apple-touch-icon" href="/brand/apple-touch-icon.png" />
9
10
  <link rel="stylesheet" href="/dashboard.css" />
10
11
  </head>
11
12
  <body class="gateway-page">
12
13
  <main class="gateway-shell">
13
- <section class="gateway-story" aria-label="About <%= brand.name %>">
14
+ <section class="gateway-story" aria-label="About <%= brand.name %>" data-i18n-aria-label="storyAbout">
14
15
  <div class="brand-lockup" aria-label="<%= brand.name %>">
15
16
  <img src="/brand/mark.svg" alt="" />
16
- <span><strong><%= brand.name %></strong><small><%= brand.tagline %></small></span>
17
+ <span><strong><%= brand.name %></strong><small data-i18n="tagline"><%= brand.tagline %></small></span>
17
18
  </div>
18
19
 
19
20
  <div class="gateway-copy">
20
- <span class="eyebrow">A direct line</span>
21
- <h2>Bring your assistant online.</h2>
22
- <p>One scan securely links Levix to the WhatsApp account you choose.</p>
21
+ <span class="eyebrow" data-i18n="directLine">A direct line</span>
22
+ <h2 data-i18n="qrHeadline">Bring your assistant online.</h2>
23
+ <p data-i18n="qrLede">One scan securely links Levix to the WhatsApp account you choose.</p>
23
24
  </div>
24
25
 
25
26
  <div class="gateway-mark" aria-hidden="true">
@@ -27,7 +28,7 @@
27
28
  <img src="/brand/mark.svg" alt="" />
28
29
  </div>
29
30
 
30
- <p class="gateway-trust"><span></span> Live pairing status</p>
31
+ <p class="gateway-trust" data-i18n-html="qrTrust"><span></span> Live pairing status</p>
31
32
  </section>
32
33
 
33
34
  <section class="gateway-panel">
@@ -35,46 +36,53 @@
35
36
  <div class="card auth-card qr-card">
36
37
  <div class="card-head qr-card-head">
37
38
  <div>
38
- <span class="eyebrow">Link device</span>
39
- <h1>Scan with WhatsApp</h1>
39
+ <span class="eyebrow" data-i18n="linkDevice">Link device</span>
40
+ <h1 data-i18n="qrScanTitle">Scan with WhatsApp</h1>
40
41
  </div>
41
- <span class="pill" id="state"><span class="dot"></span>Waiting…</span>
42
+ <span class="pill" id="state"><span class="dot"></span><span data-i18n="qrWaiting">Waiting…</span></span>
42
43
  </div>
43
44
 
44
45
  <div class="qr-box">
45
46
  <div class="qr-frame" id="frame"></div>
46
47
  <ol class="steps">
47
- <li><span>Open</span> WhatsApp on the phone the bot should use.</li>
48
- <li><span>Choose</span> Settings → Linked devices → Link a device.</li>
49
- <li><span>Scan</span> the code shown above.</li>
48
+ <li data-i18n-html="qrStep1"><span>Open</span> WhatsApp on the phone the bot should use.</li>
49
+ <li data-i18n-html="qrStep2"><span>Choose</span> Settings → Linked devices → Link a device.</li>
50
+ <li data-i18n-html="qrStep3"><span>Scan</span> the code shown above.</li>
50
51
  </ol>
51
52
  <div class="callout compact-callout">
52
53
  <span class="callout-icon" aria-hidden="true">i</span>
53
- <p>No code yet? Press <strong>Start session</strong> on the dashboard's Connection screen.</p>
54
+ <p data-i18n-html="qrCallout">No code yet? Press <strong>Start session</strong> on the dashboard's Connection screen.</p>
54
55
  </div>
55
56
  </div>
56
57
 
57
58
  <a class="btn qr-back" href="/">
58
59
  <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M19 12H5M11 6l-6 6 6 6"/></svg>
59
- Back to dashboard
60
+ <span data-i18n="backToDashboard">Back to dashboard</span>
60
61
  </a>
61
62
  </div>
62
63
 
63
- <div class="foot"><%= brand.name %> by <%= brand.developer %> · <%= brand.studio %></div>
64
+ <div class="foot"><%= brand.name %> <span data-i18n="by">by</span> <%= brand.developer %> · <%= brand.studio %></div>
64
65
  </div>
65
66
  </section>
66
67
  </main>
67
68
 
69
+ <script src="/gateway-i18n.js"></script>
68
70
  <script src="/socket.io.min.js"></script>
69
71
  <script src="/qrcode.min.js"></script>
70
72
  <script>
71
73
  (() => {
74
+ const getT = () => (window.LevixGatewayI18n ? window.LevixGatewayI18n.t : (k) => k);
72
75
  const frame = document.getElementById("frame");
73
76
  const state = document.getElementById("state");
74
77
  let painted = null;
78
+ let currentStatusKey = "qrWaiting";
79
+ let currentStatusKind = "";
80
+ let isLinked = false;
75
81
 
76
- function setState(text, kind) {
77
- state.className = `pill ${kind || ""}`;
82
+ function setState(text, kind, key) {
83
+ if (key) currentStatusKey = key;
84
+ currentStatusKind = kind || "";
85
+ state.className = `pill ${currentStatusKind}`;
78
86
  state.innerHTML = `<span class="dot"></span>${text}`;
79
87
  }
80
88
 
@@ -88,37 +96,58 @@
88
96
  height: 250,
89
97
  correctLevel: QRCode.CorrectLevel.H,
90
98
  });
91
- setState("Scan me", "");
99
+ setState(getT()("qrScanMe"), "", "qrScanMe");
92
100
  }
93
101
 
94
102
  // The QR the server already had when this page was rendered.
95
103
  const initial = <%- JSON.stringify(qr || "") %>;
96
104
  if (initial) render(initial);
97
- else setState("Waiting for a code…", "");
105
+ else setState(getT()("qrWaitingCode"), "", "qrWaitingCode");
98
106
 
99
- function clear(text, kind) {
107
+ function clear(text, kind, key) {
100
108
  painted = null;
101
109
  frame.innerHTML = "";
102
- setState(text, kind || "");
110
+ setState(text, kind || "", key);
103
111
  }
104
112
 
113
+ function repaint() {
114
+ if (currentStatusKey) {
115
+ setState(getT()(currentStatusKey), currentStatusKind, currentStatusKey);
116
+ }
117
+ if (isLinked) {
118
+ frame.innerHTML = `<div class="qr-success">${getT()("qrLinked")}</div>`;
119
+ }
120
+ }
121
+
122
+ window.addEventListener("levix-gateway-lang", repaint);
123
+ window.addEventListener("levix-ui-prefs", repaint);
124
+ window.addEventListener("storage", (e) => {
125
+ if (e.key === "levix_lang") repaint();
126
+ });
127
+
105
128
  const socket = io();
106
129
  socket.on("qr", render);
107
130
 
108
131
  // The backend drops a code the moment it stops being scannable. Without
109
132
  // this the page sat on an expired QR forever, and somebody would keep
110
133
  // pointing a phone at it.
111
- socket.on("qr_cleared", () => clear("Waiting for a code…", ""));
134
+ socket.on("qr_cleared", () => {
135
+ isLinked = false;
136
+ clear(getT()("qrWaitingCode"), "", "qrWaitingCode");
137
+ });
112
138
 
113
- socket.on("session", (state) => {
114
- if (state.state === "connected") {
115
- frame.innerHTML = '<div class="qr-success">Linked ✓</div>';
139
+ socket.on("session", (s) => {
140
+ if (s.state === "connected") {
141
+ isLinked = true;
142
+ frame.innerHTML = `<div class="qr-success">${getT()("qrLinked")}</div>`;
116
143
  painted = null;
117
- setState("Connected", "on");
144
+ setState(getT()("qrConnected"), "on", "qrConnected");
118
145
  return;
119
146
  }
120
- if (state.state === "waiting_for_qr") return; // the qr event paints it
121
- clear(state.canStart ? "Not started — start it from the dashboard" : "Connecting…", "");
147
+ isLinked = false;
148
+ if (s.state === "waiting_for_qr") return; // the qr event paints it
149
+ const key = s.canStart ? "qrNotStarted" : "qrConnecting";
150
+ clear(getT()(key), "", key);
122
151
  });
123
152
  })();
124
153
  </script>