Fix: Ultimate SSR safety for CyberTheme and i18n
This commit is contained in:
parent
6e3aca8f15
commit
0c4b299b0b
1 changed files with 4 additions and 4 deletions
|
|
@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
|
||||||
|
|
||||||
export type Language = 'pt' | 'en' | 'es';
|
export type Language = 'pt' | 'en' | 'es';
|
||||||
|
|
||||||
const translations = {
|
const translations: Record<Language, any> = {
|
||||||
pt: {
|
pt: {
|
||||||
nav: { home: 'Início', articles: 'Artigos', contact: 'Contato', language: 'Idioma' },
|
nav: { home: 'Início', articles: 'Artigos', contact: 'Contato', language: 'Idioma' },
|
||||||
footer: { rights: 'Todos os direitos reservados', builtWith: 'Construído com' }
|
footer: { rights: 'Todos os direitos reservados', builtWith: 'Construído com' }
|
||||||
|
|
@ -23,7 +23,7 @@ export function useLanguage() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
const saved = localStorage.getItem('lang');
|
const saved = localStorage.getItem('lang');
|
||||||
if (saved && (translations as any)[saved]) {
|
if (saved && translations[saved as Language]) {
|
||||||
setLangState(saved as Language);
|
setLangState(saved as Language);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -32,7 +32,7 @@ export function useLanguage() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleLangChange = (e: Event) => {
|
const handleLangChange = (e: Event) => {
|
||||||
const detail = (e as CustomEvent).detail;
|
const detail = (e as CustomEvent).detail;
|
||||||
if (detail && (translations as any)[detail]) {
|
if (detail && translations[detail as Language]) {
|
||||||
setLangState(detail);
|
setLangState(detail);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -52,6 +52,6 @@ export function useLanguage() {
|
||||||
lang,
|
lang,
|
||||||
setLanguage: setLang,
|
setLanguage: setLang,
|
||||||
setLang,
|
setLang,
|
||||||
t: (translations as any)[lang] || translations.pt
|
t: translations[lang] || translations.pt
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue