diff --git a/README.md b/README.md index 095f26f..6fe1865 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,8 @@ To Be Played is split into three repositories: - **Appearance**: accent color, corner style, wide layout, page background and banner from your own game art. Saved in Auth, so it follows you to every device. - **Language**: kept in the browser and saved in Auth; after the login Auth's language wins when one is saved. Dark - mode stays per device. + mode stays per device. The registration sends the browser language (`de` for a German browser, else `en`): Auth + writes its mails in it and saves it as the user's language. - **Broken pictures**: a Steam cover or achievement icon that does not load shows a placeholder and is reported to Core once per page load (`POST /api/library/broken-images`, only with a session). Core repairs it at night; a repaired cover comes back as `imageUrl`. diff --git a/src/pages/RegistrationPage.jsx b/src/pages/RegistrationPage.jsx index 9204c4d..8340be1 100644 --- a/src/pages/RegistrationPage.jsx +++ b/src/pages/RegistrationPage.jsx @@ -54,6 +54,8 @@ export default function RegistrationPage() { password: values.password, inviteCode: values.inviteCode, displayName: values.displayName, + // Auth's mails use it: a German browser gets German, every other one English. + language: navigator.language?.toLowerCase().startsWith('de') ? 'de' : 'en', }), }); diff --git a/src/pages/RegistrationPage.test.jsx b/src/pages/RegistrationPage.test.jsx index fd73e88..9cf21e2 100644 --- a/src/pages/RegistrationPage.test.jsx +++ b/src/pages/RegistrationPage.test.jsx @@ -30,6 +30,7 @@ function submitValidForm() { describe('RegistrationPage', () => { afterEach(() => { cleanup(); + vi.restoreAllMocks(); }); it('shows the wait time when the IP is blocked', async () => { @@ -50,6 +51,17 @@ describe('RegistrationPage', () => { expect(JSON.parse(fetch.mock.calls[0][1].body)).not.toHaveProperty('steamId'); }); + it.each([['de-DE', 'de'], ['de', 'de'], ['en-US', 'en'], ['fr-FR', 'en'], [undefined, 'en']])( + 'sends the browser language %s as %s, for the mails', async (browser, sent) => { + vi.spyOn(navigator, 'language', 'get').mockReturnValue(browser); + answerRegistration(400, 'INVALID_INVITATION_CODE'); + + submitValidForm(); + + await screen.findByText('REGISTRATION.ERROR_INVALID_INVITE_CODE'); + expect(JSON.parse(fetch.mock.calls[0][1].body).language).toBe(sent); + }); + it('maps a known backend error to its message', async () => { answerRegistration(400, 'INVALID_INVITATION_CODE');