Skip to content

Commit

Permalink
I18N fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
daveearley committed Jun 23, 2024
1 parent defd06d commit 1254267
Show file tree
Hide file tree
Showing 30 changed files with 602 additions and 511 deletions.
8 changes: 4 additions & 4 deletions backend/app/DomainObjects/MessageDomainObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public static function getAllowedSorts(): AllowedSorts
return new AllowedSorts(
[
self::CREATED_AT => [
'asc' => 'Sent Date Oldest',
'desc' => 'Sent Date Newest',
'asc' => __('Sent Date Oldest'),
'desc' => __('Sent Date Newest'),
],
self::SUBJECT => [
'asc' => 'Subject A-Z',
'desc' => 'Subject Z-A',
'asc' => __('Subject A-Z'),
'desc' => __('Subject Z-A'),
],
],
);
Expand Down
9 changes: 7 additions & 2 deletions backend/app/Http/Middleware/SetUserLocaleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

use Closure;
use HiEvents\DomainObjects\UserDomainObject;
use HiEvents\Services\Application\Locale\LocaleService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;

class SetUserLocaleMiddleware
{
public function __construct(private readonly LocaleService $localeService)
{
}

public function handle(Request $request, Closure $next)
{
$this->setLocale($request);
Expand All @@ -34,7 +39,7 @@ protected function setLocale(Request $request): void
protected function setLocaleFromCookie(Request $request): bool
{
if ($locale = $request->cookie('locale')) {
App::setLocale($locale);
App::setLocale($this->localeService->getLocaleOrDefault($locale));
return true;
}

Expand All @@ -56,7 +61,7 @@ protected function setLocaleFromUser(): bool
protected function setLocaleFromAcceptLanguage(Request $request): bool
{
if ($request->hasHeader('Accept-Language')) {
App::setLocale($request->header('Accept-Language'));
App::setLocale($this->localeService->getLocaleOrDefault($request->getPreferredLanguage()));
return true;
}

Expand Down
8 changes: 6 additions & 2 deletions backend/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,9 @@
"To accept the invitation, please click the link below:": "Um die Einladung anzunehmen, klicken Sie bitte auf den unten stehenden Link:",
"Accept Invitation": "Einladung annehmen",
"All rights reserved.": "Alle Rechte vorbehalten.",
"Congratulations 🎉": "Herzlichen Glückwunsch 🎉."
}
"Congratulations 🎉": "Herzlichen Glückwunsch 🎉.",
"Sent Date Oldest": "Gesendet Datum Älteste",
"Sent Date Newest": "Gesendet Datum Neueste",
"Subject A-Z": "Betreff A-Z",
"Subject Z-A": "Betreff Z-A"
}
8 changes: 6 additions & 2 deletions backend/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,9 @@
"To accept the invitation, please click the link below:": "Para aceptar la invitación, haga clic en el siguiente enlace:",
"Accept Invitation": "Aceptar invitación",
"All rights reserved.": "Todos los derechos reservados.",
"Congratulations 🎉": "Enhorabuena 🎉"
}
"Congratulations 🎉": "Enhorabuena 🎉",
"Sent Date Oldest": "Fecha de Envío Más Antigua",
"Sent Date Newest": "Fecha de Envío Más Reciente",
"Subject A-Z": "Asunto A-Z",
"Subject Z-A": "Asunto Z-A"
}
287 changes: 137 additions & 150 deletions backend/lang/es/validation.php

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions backend/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,9 @@
"To accept the invitation, please click the link below:": "Pour accepter l'invitation, veuillez cliquer sur le lien ci-dessous :",
"Accept Invitation": "Accepter l'invitation",
"All rights reserved.": "Tous droits réservés.",
"Congratulations 🎉": "Félicitations 🎉"
}
"Congratulations 🎉": "Félicitations 🎉",
"Sent Date Oldest": "Date d'Envoi la Plus Ancienne",
"Sent Date Newest": "Date d'Envoi la Plus Récente",
"Subject A-Z": "Objet A-Z",
"Subject Z-A": "Objet Z-A"
}
8 changes: 6 additions & 2 deletions backend/lang/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,9 @@
"To accept the invitation, please click the link below:": "Para aceitar o convite, clique no link abaixo:",
"Accept Invitation": "Aceitar convite",
"All rights reserved.": "Todos os direitos reservados.",
"Congratulations 🎉": "Parabéns 🎉"
}
"Congratulations 🎉": "Parabéns 🎉",
"Sent Date Oldest": "Data de Envio Mais Antiga",
"Sent Date Newest": "Data de Envio Mais Recente",
"Subject A-Z": "Assunto A-Z",
"Subject Z-A": "Assunto Z-A"
}
8 changes: 6 additions & 2 deletions backend/lang/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,9 @@
"To accept the invitation, please click the link below:": "Para aceitar o convite, clique na hiperligação abaixo:",
"Accept Invitation": "Aceitar o convite",
"All rights reserved.": "Todos os direitos reservados.",
"Congratulations 🎉": "Parabéns 🎉"
}
"Congratulations 🎉": "Parabéns 🎉",
"Sent Date Oldest": "Data de Envio Mais Antiga",
"Sent Date Newest": "Data de Envio Mais Recente",
"Subject A-Z": "Assunto A-Z",
"Subject Z-A": "Assunto Z-A"
}
7 changes: 6 additions & 1 deletion backend/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,10 @@
"Congratulations! You\\'ve received a new order for ": "",
"What\\'s Next?": "",
"Welcome to :appName! We\\'re excited to have you aboard!": "",
"You\\'ve been invited to join :appName.": ""
"You\\'ve been invited to join :appName.": "",
"Sent Date Oldest": "",
"Sent Date Newest": "",
"Subject A-Z": "",
"Subject Z-A": "",
"There are no tickets available. If you would like to assign this ticket to this attendee, please adjust the ticket\\'s available quantity.": ""
}
8 changes: 6 additions & 2 deletions backend/lang/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,9 @@
"To accept the invitation, please click the link below:": "要接受邀请,请点击下面的链接:",
"Accept Invitation": "接受邀请",
"All rights reserved.": "保留所有权利。",
"Congratulations 🎉": "恭喜 🎉"
}
"Congratulations 🎉": "恭喜 🎉",
"Sent Date Oldest": "发送日期最早",
"Sent Date Newest": "发送日期最新",
"Subject A-Z": "主题 A-Z",
"Subject Z-A": "主题 Z-A"
}
3 changes: 3 additions & 0 deletions frontend/lingui.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const config: LinguiConfig = {
],
sourceLocale: "en",
format: "po",
fallbackLocales: {
"default": "en",
}
};

export default config;
18 changes: 10 additions & 8 deletions frontend/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const BASE_URL = isSsr()
? getConfig('VITE_API_URL_SERVER')
: getConfig('VITE_API_URL_CLIENT');
const LOGIN_PATH = "/auth/login";
const PREVIOUS_URL_KEY = 'previous_url'; // Key for storing the previous URL
const PREVIOUS_URL_KEY = 'previous_url';

const ALLOWED_UNAUTHENTICATED_PATHS = [
'auth/login',
Expand All @@ -28,18 +28,14 @@ export const api = axios.create({
withCredentials: true,
});


const existingToken = typeof window !== "undefined" ? window.localStorage.getItem('token') : undefined;
if (existingToken) {
setAuthToken(existingToken);
}

api.interceptors.response.use(
(response) => {
// Securely update the token on each response
// eslint-disable-next-line lingui/no-unlocalized-strings
const token = response?.data?.token || response?.headers["x-auth-token"];

if (token) {
window?.localStorage?.setItem('token', token);
setAuthToken(token);
Expand All @@ -48,20 +44,26 @@ api.interceptors.response.use(
},
(error) => {
const { status } = error.response;
if ((status === 401 || status === 403) && !ALLOWED_UNAUTHENTICATED_PATHS.some(path => window?.location.pathname.includes(path))) {
const currentPath = window?.location.pathname;
const isAllowedUnauthenticatedPath = ALLOWED_UNAUTHENTICATED_PATHS.some(path => currentPath.includes(path));
const isManageEventPath = currentPath.startsWith('/manage/event/');
const isAuthError = status === 401 || status === 403;

if (isAuthError && (!isAllowedUnauthenticatedPath || isManageEventPath)) {
// Store the current URL before redirecting to the login page
window?.localStorage?.setItem(PREVIOUS_URL_KEY, window?.location.href);
window?.location?.replace(LOGIN_PATH);
}

return Promise.reject(error);
}
);

axios.defaults.withCredentials = true
axios.defaults.withCredentials = true;

export const redirectToPreviousUrl = () => {
const previousUrl = window?.localStorage?.getItem(PREVIOUS_URL_KEY) || '/manage/events';
window?.localStorage?.removeItem(PREVIOUS_URL_KEY); // Clean up after redirecting
window?.localStorage?.removeItem(PREVIOUS_URL_KEY);
if (typeof window !== "undefined") {
window.location.href = previousUrl;
}
Expand Down
31 changes: 24 additions & 7 deletions frontend/src/components/common/LanguageSwitcher/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import {Select} from "@mantine/core";
import {
dynamicActivateLocale,
getClientLocale,
getLocaleName,
localeToNameMap,
SupportedLocales
} from "../../../locales.ts";
import {dynamicActivateLocale, getClientLocale, localeToNameMap, SupportedLocales} from "../../../locales.ts";
import {t} from "@lingui/macro";
import {IconWorld} from "@tabler/icons-react";
import {useLingui} from "@lingui/react";

export const LanguageSwitcher = () => {
useLingui();

// Ideally these would be in the locales.ts file, but when they're there they don't translate
const getLocaleName = (locale: SupportedLocales): string => {
switch (locale) {
case "de":
return t`German`;
case "en":
return t`English`;
case "es":
return t`Spanish`;
case "fr":
return t`French`;
case "pt":
return t`Portuguese`;
case "pt-br":
return t`Brazilian Portuguese`;
case "zh-cn":
return t`Chinese (Simplified)`;
}
};

return (
<>
<Select
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/routes/event/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const Messages = () => {
/>
)}>
<Button color={'green'} size={'sm'} onClick={openSendModal} rightSection={<IconSend/>}>
Send Message
{t`Send Message`}
</Button>
</ToolBar>

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/de.js

Large diffs are not rendered by default.

Loading

0 comments on commit 1254267

Please sign in to comment.