O que mudou
Infra (por app):
i18n/locales.ts — lista de locales (pt, en), default pt, labels para o seletor
i18n/request.ts — lê o cookie NEXT_LOCALE, carrega as mensagens
messages/pt.json + messages/en.json — todas as strings extraídas
next.config.ts — envolvido com withNextIntl (operator-pwa: withPWA(withNextIntl(...)))
app/layout.tsx — <html lang={locale}> dinâmico, NextIntlClientProvider
app/language-switcher.tsx — seletor PT | EN (cookie + router.refresh())
23 ficheiros de UI atualizados — todos os textos visíveis agora usam t('...') ou getTranslations.
Datas no relatório passaram de toLocaleString('pt-PT') fixo para useFormatter() do next-intl — localizam-se automaticamente.
Plurais em ICU no sync-chip: {count, plural, one {# pedido...} other {# pedidos...}}.
Resultado dos testes:
pnpm test:e2e — 3/3 ✓
pnpm test:e2e:auth — 4/4 ✓
tsc --noEmit em ambas as apps — limpo ✓
Para adicionar uma língua futura: criar messages/<locale>.json + adicionar o locale a i18n/locales.ts em cada app. O seletor aparece automaticamente.
34 lines
966 B
TypeScript
34 lines
966 B
TypeScript
'use client';
|
|
|
|
import { useRouter } from 'next/navigation';
|
|
import { useLocale } from 'next-intl';
|
|
import { LOCALES, LOCALE_LABELS, type Locale } from '@/i18n/locales';
|
|
|
|
export function LanguageSwitcher() {
|
|
const router = useRouter();
|
|
const current = useLocale() as Locale;
|
|
|
|
function switchTo(locale: Locale) {
|
|
document.cookie = `NEXT_LOCALE=${locale}; path=/; max-age=31536000; SameSite=Lax`;
|
|
router.refresh();
|
|
}
|
|
|
|
return (
|
|
<div className="flex items-center gap-1 rounded-full border border-border bg-muted p-0.5">
|
|
{LOCALES.map((l) => (
|
|
<button
|
|
key={l}
|
|
onClick={() => switchTo(l)}
|
|
className={`rounded-full px-2.5 py-0.5 text-xs font-medium transition-colors ${
|
|
l === current
|
|
? 'bg-card text-foreground shadow-sm'
|
|
: 'text-muted-foreground hover:text-foreground'
|
|
}`}
|
|
>
|
|
{LOCALE_LABELS[l]}
|
|
</button>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|