Skip to content

Commit 312c4f5

Browse files
authored
Merge pull request #15 from jmpsec/i8n-locale-fr
Adding locale for FR and some changes to ES
2 parents 9f5914e + 02e3034 commit 312c4f5

6 files changed

Lines changed: 935 additions & 79 deletions

File tree

backend/cmd/map/handlers/login_i18n_test.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestLoginHandlerRendersConfiguredLocale(t *testing.T) {
5757
{
5858
name: "spanish",
5959
lang: "es",
60-
want: []string{`<html lang="es">`, "Jugar CTF", "Usuario", "Contraseña", "Acceder"},
60+
want: []string{`<html lang="es">`, "Jugar CTF", "Nombre de usuario", "Contraseña", "Iniciar sesión"},
6161
},
6262
{
6363
name: "english default",
@@ -125,7 +125,7 @@ func TestRegistrationHandlerRendersConfiguredLocale(t *testing.T) {
125125

126126
require.Equal(t, http.StatusOK, rr.Code, "body: %s", rr.Body.String())
127127
body := rr.Body.String()
128-
for _, want := range []string{`<html lang="es">`, "Jugar CTF", "Nombre completo", "Nombre del equipo", "Registrarse"} {
128+
for _, want := range []string{`<html lang="es">`, "Jugar CTF", "Nombre completo", "Nombre de equipo", "Regístrate"} {
129129
require.Contains(t, body, want)
130130
}
131131
}
@@ -150,7 +150,7 @@ func TestGameboardHandlerRendersConfiguredLocale(t *testing.T) {
150150
body := rr.Body.String()
151151
for _, want := range []string{
152152
`<html lang="es">`,
153-
"Clasificación",
153+
"Ranking",
154154
"Actividad",
155155
"Sin equipo",
156156
"Posición",
@@ -200,7 +200,28 @@ func TestAdminUsersHandlerRendersConfiguredLocale(t *testing.T) {
200200

201201
require.Equal(t, http.StatusOK, rr.Code, "body: %s", rr.Body.String())
202202
body := rr.Body.String()
203-
for _, want := range []string{`<html lang="es">`, "Administración del juego", "Gestión de usuarios", "Añadir usuario", `window.MCTF_LANG = "es"`} {
203+
for _, want := range []string{`<html lang="es">`, "Administración del juego", "Administrar usuarios", "Añadir usuario", `window.MCTF_LANG = "es"`} { //nolint:misspell // "Administrar" is a valid Spanish word
204+
require.Contains(t, body, want)
205+
}
206+
}
207+
208+
func TestLoginHandlerRendersFrenchLocale(t *testing.T) {
209+
if _, err := os.Stat(filepath.Join("..", "templates", "login.html")); err != nil {
210+
t.Skipf("login template not available: %v", err)
211+
}
212+
handler, sessions := newLoginI18nHandler(t, "fr")
213+
214+
req := newTemplateRequestWithUUID(http.MethodGet, "/"+jsonTestUUID+"/login", jsonTestUUID)
215+
ctx, err := sessions.Load(req.Context(), "")
216+
require.NoError(t, err)
217+
req = req.WithContext(ctx)
218+
219+
rr := httptest.NewRecorder()
220+
handler.LocaleMiddleware(http.HandlerFunc(handler.LoginHandler)).ServeHTTP(rr, req)
221+
222+
require.Equal(t, http.StatusOK, rr.Code, "body: %s", rr.Body.String())
223+
body := rr.Body.String()
224+
for _, want := range []string{`<html lang="fr">`, "Jouer au CTF", "Nom d'utilisateur", "Mot de passe", "Connexion", `window.MCTF_LANG = "fr"`} {
204225
require.Contains(t, body, want)
205226
}
206227
}

backend/cmd/map/templates/static/inc/modals/action-delete-all-logos.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ <h4><span data-i18n="modal.status_kicker">status_</span><span class="highlighted
55
</header>
66

77
<div class="action-main">
8-
<p><span data-i18n="admin.modal.delete_all_logos_lead">Delete all</span> <strong data-i18n="admin.logos.custom_type">custom</strong> <span data-i18n="admin.modal.delete_all_logos_trail">logos? Platform badges stay in the catalog. This cannot be undone.</span></p>
8+
<p data-i18n="admin.modal.confirm_delete_all_logos">Delete all custom logos? Platform badges stay in the catalog. This cannot be undone.</p>
99

1010
<div class="action-actionable">
1111
<a href="#" class="mctf-cta cta--red js-close-modal" data-i18n="admin.modal.no">No</a>

backend/pkg/i18n/i18n_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ func TestTranslateFallsBackToEnglishThenKey(t *testing.T) {
3434
c, err := New()
3535
require.NoError(t, err)
3636
es := c.Resolve("es")
37-
require.Equal(t, "Usuario", c.Translate(es, "login.username_label"))
38-
// Unsupported locale falls back to English.
37+
require.Equal(t, "Nombre de usuario", c.Translate(es, "login.username_label"))
38+
// French is supported and translates.
3939
fr := c.Resolve("fr")
40-
require.Equal(t, "Play CTF", c.Translate(fr, "nav.play_ctf"))
40+
require.Equal(t, "Jouer au CTF", c.Translate(fr, "nav.play_ctf"))
41+
// Unsupported locale falls back to English.
42+
de := c.Resolve("de")
43+
require.Equal(t, "Play CTF", c.Translate(de, "nav.play_ctf"))
4144
// Unknown key returns the key itself.
4245
require.Equal(t, "no.such.key", c.Translate(es, "no.such.key"))
4346
// Regional variant resolves to the base catalog tag so lookup succeeds.
44-
require.Equal(t, "Usuario", c.Translate(c.Resolve("es-AR"), "login.username_label"))
47+
require.Equal(t, "Nombre de usuario", c.Translate(c.Resolve("es-AR"), "login.username_label"))
4548
}

backend/pkg/i18n/locales/en.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@
423423
"admin.modal.confirm_delete_all_users": "Are you sure you want to delete all users? This cannot be undone.",
424424
"admin.modal.confirm_delete_all_categories": "Are you sure you want to delete all categories? Challenges must be deleted first.",
425425
"admin.modal.confirm_delete_all_countries": "Are you sure you want to delete all countries? This cannot be undone and will clear country assignments from challenges.",
426-
"admin.modal.confirm_delete_all_logos": "Are you sure you want to delete all custom logos? This cannot be undone.",
426+
"admin.modal.confirm_delete_all_logos": "Delete all custom logos? Platform badges stay in the catalog. This cannot be undone.",
427427
"admin.modal.confirm_disable_all_users": "Are you sure you want to disable all users? This cannot be undone.",
428428
"admin.activity.kicker": "Admin Activity Log",
429429
"admin.activity.subject": "Subject",
@@ -451,8 +451,6 @@
451451
"admin.category.name": "Name",
452452
"admin.category.description": "Description",
453453
"admin.category.logo": "Logo",
454-
"admin.modal.delete_all_logos_lead": "Delete all",
455-
"admin.modal.delete_all_logos_trail": "logos? Platform badges stay in the catalog. This cannot be undone.",
456454
"admin.modal.reset_settings_title": "Reset Settings",
457455
"admin.modal.confirm_reset_settings": "Are you sure you want to reset all settings to default values?",
458456
"admin.modal.confirm_logout": "Are you sure you want to logout?",

0 commit comments

Comments
 (0)