259 lines
7.7 KiB
TypeScript
259 lines
7.7 KiB
TypeScript
import type { SupportedLanguage, Translation } from '@avanzacast/shared-types';
|
|
|
|
const LANGUAGE_KEY = 'avanzacast_language';
|
|
|
|
// Traducciones por idioma
|
|
const translations: Record<SupportedLanguage, Translation> = {
|
|
es: {
|
|
common: {
|
|
login: 'Iniciar sesión',
|
|
logout: 'Cerrar sesión',
|
|
register: 'Registrarse',
|
|
email: 'Correo electrónico',
|
|
password: 'Contraseña',
|
|
name: 'Nombre',
|
|
save: 'Guardar',
|
|
cancel: 'Cancelar',
|
|
delete: 'Eliminar',
|
|
edit: 'Editar',
|
|
loading: 'Cargando...',
|
|
error: 'Error',
|
|
success: 'Éxito',
|
|
},
|
|
nav: {
|
|
home: 'Inicio',
|
|
features: 'Características',
|
|
pricing: 'Precios',
|
|
contact: 'Contacto',
|
|
dashboard: 'Panel',
|
|
broadcasts: 'Transmisiones',
|
|
studio: 'Estudio',
|
|
settings: 'Configuración',
|
|
},
|
|
landing: {
|
|
hero_title: 'La manera más sencilla de transmitir en vivo y grabar',
|
|
hero_subtitle: 'AvanzaCast es un estudio profesional para grabar y hacer transmisiones en vivo desde tu navegador',
|
|
get_started: 'Empecemos',
|
|
continue_google: 'Continuar con Google',
|
|
features_title: 'Todo lo que necesitas para transmitir',
|
|
testimonials_title: 'transmisiones realizadas',
|
|
},
|
|
auth: {
|
|
login_title: 'Inicia sesión en tu cuenta',
|
|
register_title: 'Crea tu cuenta',
|
|
forgot_password: '¿Olvidaste tu contraseña?',
|
|
no_account: '¿No tienes cuenta?',
|
|
already_account: '¿Ya tienes cuenta?',
|
|
terms_accept: 'Al continuar, aceptas nuestros',
|
|
terms_service: 'Términos de Servicio',
|
|
privacy_policy: 'Política de Privacidad',
|
|
},
|
|
},
|
|
en: {
|
|
common: {
|
|
login: 'Log in',
|
|
logout: 'Log out',
|
|
register: 'Sign up',
|
|
email: 'Email',
|
|
password: 'Password',
|
|
name: 'Name',
|
|
save: 'Save',
|
|
cancel: 'Cancel',
|
|
delete: 'Delete',
|
|
edit: 'Edit',
|
|
loading: 'Loading...',
|
|
error: 'Error',
|
|
success: 'Success',
|
|
},
|
|
nav: {
|
|
home: 'Home',
|
|
features: 'Features',
|
|
pricing: 'Pricing',
|
|
contact: 'Contact',
|
|
dashboard: 'Dashboard',
|
|
broadcasts: 'Broadcasts',
|
|
studio: 'Studio',
|
|
settings: 'Settings',
|
|
},
|
|
landing: {
|
|
hero_title: 'The easiest way to live stream and record',
|
|
hero_subtitle: 'AvanzaCast is a professional studio for recording and live streaming from your browser',
|
|
get_started: 'Get started',
|
|
continue_google: 'Continue with Google',
|
|
features_title: 'Everything you need to broadcast',
|
|
testimonials_title: 'streams created',
|
|
},
|
|
auth: {
|
|
login_title: 'Log in to your account',
|
|
register_title: 'Create your account',
|
|
forgot_password: 'Forgot password?',
|
|
no_account: "Don't have an account?",
|
|
already_account: 'Already have an account?',
|
|
terms_accept: 'By continuing, you agree to our',
|
|
terms_service: 'Terms of Service',
|
|
privacy_policy: 'Privacy Policy',
|
|
},
|
|
},
|
|
pt: {
|
|
common: {
|
|
login: 'Entrar',
|
|
logout: 'Sair',
|
|
register: 'Cadastrar',
|
|
email: 'E-mail',
|
|
password: 'Senha',
|
|
name: 'Nome',
|
|
save: 'Salvar',
|
|
cancel: 'Cancelar',
|
|
delete: 'Excluir',
|
|
edit: 'Editar',
|
|
loading: 'Carregando...',
|
|
error: 'Erro',
|
|
success: 'Sucesso',
|
|
},
|
|
nav: {
|
|
home: 'Início',
|
|
features: 'Recursos',
|
|
pricing: 'Preços',
|
|
contact: 'Contato',
|
|
dashboard: 'Painel',
|
|
broadcasts: 'Transmissões',
|
|
studio: 'Estúdio',
|
|
settings: 'Configurações',
|
|
},
|
|
landing: {
|
|
hero_title: 'A maneira mais fácil de transmitir ao vivo e gravar',
|
|
hero_subtitle: 'AvanzaCast é um estúdio profissional para gravar e fazer transmissões ao vivo do seu navegador',
|
|
get_started: 'Começar',
|
|
continue_google: 'Continuar com Google',
|
|
features_title: 'Tudo que você precisa para transmitir',
|
|
testimonials_title: 'transmissões realizadas',
|
|
},
|
|
auth: {
|
|
login_title: 'Entre na sua conta',
|
|
register_title: 'Crie sua conta',
|
|
forgot_password: 'Esqueceu a senha?',
|
|
no_account: 'Não tem uma conta?',
|
|
already_account: 'Já tem uma conta?',
|
|
terms_accept: 'Ao continuar, você concorda com nossos',
|
|
terms_service: 'Termos de Serviço',
|
|
privacy_policy: 'Política de Privacidade',
|
|
},
|
|
},
|
|
fr: {
|
|
common: {
|
|
login: 'Se connecter',
|
|
logout: 'Se déconnecter',
|
|
register: "S'inscrire",
|
|
email: 'E-mail',
|
|
password: 'Mot de passe',
|
|
name: 'Nom',
|
|
save: 'Enregistrer',
|
|
cancel: 'Annuler',
|
|
delete: 'Supprimer',
|
|
edit: 'Modifier',
|
|
loading: 'Chargement...',
|
|
error: 'Erreur',
|
|
success: 'Succès',
|
|
},
|
|
nav: {
|
|
home: 'Accueil',
|
|
features: 'Fonctionnalités',
|
|
pricing: 'Tarifs',
|
|
contact: 'Contact',
|
|
dashboard: 'Tableau de bord',
|
|
broadcasts: 'Diffusions',
|
|
studio: 'Studio',
|
|
settings: 'Paramètres',
|
|
},
|
|
landing: {
|
|
hero_title: 'La façon la plus simple de diffuser en direct et enregistrer',
|
|
hero_subtitle: 'AvanzaCast est un studio professionnel pour enregistrer et diffuser en direct depuis votre navigateur',
|
|
get_started: 'Commencer',
|
|
continue_google: 'Continuer avec Google',
|
|
features_title: 'Tout ce dont vous avez besoin pour diffuser',
|
|
testimonials_title: 'diffusions créées',
|
|
},
|
|
auth: {
|
|
login_title: 'Connectez-vous à votre compte',
|
|
register_title: 'Créez votre compte',
|
|
forgot_password: 'Mot de passe oublié?',
|
|
no_account: "Vous n'avez pas de compte?",
|
|
already_account: 'Vous avez déjà un compte?',
|
|
terms_accept: 'En continuant, vous acceptez nos',
|
|
terms_service: 'Conditions de service',
|
|
privacy_policy: 'Politique de confidentialité',
|
|
},
|
|
},
|
|
};
|
|
|
|
/**
|
|
* Guarda el idioma seleccionado en localStorage
|
|
*/
|
|
export const saveLanguage = (language: SupportedLanguage): void => {
|
|
if (typeof window === 'undefined') return;
|
|
localStorage.setItem(LANGUAGE_KEY, language);
|
|
};
|
|
|
|
/**
|
|
* Obtiene el idioma guardado o detecta el del navegador
|
|
*/
|
|
export const getLanguage = (): SupportedLanguage => {
|
|
if (typeof window === 'undefined') return 'es';
|
|
|
|
const saved = localStorage.getItem(LANGUAGE_KEY) as SupportedLanguage;
|
|
if (saved && ['es', 'en', 'pt', 'fr'].includes(saved)) {
|
|
return saved;
|
|
}
|
|
|
|
// Detectar idioma del navegador
|
|
const browserLang = navigator.language.split('-')[0];
|
|
if (['es', 'en', 'pt', 'fr'].includes(browserLang)) {
|
|
return browserLang as SupportedLanguage;
|
|
}
|
|
|
|
return 'es'; // Idioma por defecto
|
|
};
|
|
|
|
/**
|
|
* Obtiene una traducción específica
|
|
*/
|
|
export const translate = (key: string, language?: SupportedLanguage): string => {
|
|
const lang = language || getLanguage();
|
|
const keys = key.split('.');
|
|
let value: any = translations[lang];
|
|
|
|
for (const k of keys) {
|
|
if (value && typeof value === 'object') {
|
|
value = value[k];
|
|
} else {
|
|
return key; // Retorna la key si no encuentra traducción
|
|
}
|
|
}
|
|
|
|
return typeof value === 'string' ? value : key;
|
|
};
|
|
|
|
/**
|
|
* Hook helper para obtener función de traducción
|
|
*/
|
|
export const useTranslate = (language: SupportedLanguage) => {
|
|
return (key: string) => translate(key, language);
|
|
};
|
|
|
|
/**
|
|
* Obtiene todas las traducciones de un idioma
|
|
*/
|
|
export const getTranslations = (language: SupportedLanguage): Translation => {
|
|
return translations[language];
|
|
};
|
|
|
|
/**
|
|
* Lista de idiomas disponibles
|
|
*/
|
|
export const AVAILABLE_LANGUAGES: Array<{ code: SupportedLanguage; name: string; flag: string }> = [
|
|
{ code: 'es', name: 'Español', flag: '🇪🇸' },
|
|
{ code: 'en', name: 'English', flag: '🇺🇸' },
|
|
{ code: 'pt', name: 'Português', flag: '🇧🇷' },
|
|
{ code: 'fr', name: 'Français', flag: '🇫🇷' },
|
|
];
|