feat: soporte multi idioma en la web (infraestructura)
i18next + react-i18next con es-AR (fuente), es-419, pt-BR y en; el idioma sale del dispositivo (fallback a inglés) y se puede cambiar en Ajustes. La elección se guarda en localStorage y, para el profe, en users.locale. Las validaciones de shared pasan a claves y los errores de la API se traducen por code (con params para límites de plan y cupo). Migrados: layout, Ajustes, auth, PWA y lib/format. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ export * from './schemas/enums.js';
|
||||
export * from './schemas/groups.js';
|
||||
export * from './schemas/health-check.js';
|
||||
export * from './schemas/home.js';
|
||||
export * from './schemas/locale.js';
|
||||
export * from './schemas/mp.js';
|
||||
export * from './schemas/onboarding.js';
|
||||
export * from './schemas/pagination.js';
|
||||
|
||||
@@ -5,5 +5,8 @@ export type ProblemDetails = {
|
||||
detail?: string;
|
||||
instance?: string;
|
||||
code?: string;
|
||||
/** Values the client needs to word the error in its own language (e.g. the
|
||||
* plan limit). `detail` keeps the server-side wording. */
|
||||
params?: Record<string, string | number>;
|
||||
errors?: Record<string, string[]>;
|
||||
};
|
||||
@@ -84,7 +84,7 @@ const EditableAttendeeFieldsSchema = z.object({
|
||||
email: z
|
||||
.string()
|
||||
.trim()
|
||||
.email('Ingresá un email válido')
|
||||
.email('email.invalid')
|
||||
.or(z.literal(''))
|
||||
.nullable(),
|
||||
notes: z.string().trim().nullable(),
|
||||
@@ -92,7 +92,7 @@ const EditableAttendeeFieldsSchema = z.object({
|
||||
|
||||
export const UpdateAttendeeSchema = EditableAttendeeFieldsSchema.partial().refine(
|
||||
(value) => Object.keys(value).length > 0,
|
||||
'Enviá al menos un campo para actualizar',
|
||||
'update.empty',
|
||||
);
|
||||
export type UpdateAttendee = z.output<typeof UpdateAttendeeSchema>;
|
||||
|
||||
@@ -116,10 +116,10 @@ export const AttendeeListSchema = z.object({
|
||||
export type AttendeeList = z.output<typeof AttendeeListSchema>;
|
||||
|
||||
export const CreateAttendeeSchema = z.object({
|
||||
firstName: z.string().trim().min(1, 'El nombre es obligatorio'),
|
||||
firstName: z.string().trim().min(1, 'name.required'),
|
||||
lastName: z.string().trim().optional().default(''),
|
||||
phone: z.string().trim().min(6, 'Ingresa un número de teléfono válido'),
|
||||
email: z.string().trim().email('Email inválido').optional().or(z.literal('')),
|
||||
phone: z.string().trim().min(6, 'phone.invalid'),
|
||||
email: z.string().trim().email('email.invalid').optional().or(z.literal('')),
|
||||
notes: z.string().trim().optional(),
|
||||
/* Adds an existing person of the teacher (found by phone) instead of creating
|
||||
a new one: the name/email fields are ignored then. */
|
||||
@@ -140,10 +140,10 @@ export const CreateAttendeeResultSchema = z.discriminatedUnion('outcome', [
|
||||
export type CreateAttendeeResult = z.output<typeof CreateAttendeeResultSchema>;
|
||||
|
||||
export const JoinGroupViaInviteSchema = z.object({
|
||||
firstName: z.string().trim().min(1, 'El nombre es obligatorio'),
|
||||
firstName: z.string().trim().min(1, 'name.required'),
|
||||
lastName: z.string().trim().min(1, 'El apellido es obligatorio'),
|
||||
phone: z.string().trim().min(6, 'Ingresa un número de teléfono válido'),
|
||||
email: z.string().trim().email('Email inválido').optional().or(z.literal('')),
|
||||
phone: z.string().trim().min(6, 'phone.invalid'),
|
||||
email: z.string().trim().email('email.invalid').optional().or(z.literal('')),
|
||||
});
|
||||
export type JoinGroupViaInvite = z.output<typeof JoinGroupViaInviteSchema>;
|
||||
|
||||
@@ -155,11 +155,11 @@ export const JoinGroupViaInviteResultSchema = z.object({
|
||||
export type JoinGroupViaInviteResult = z.output<typeof JoinGroupViaInviteResultSchema>;
|
||||
|
||||
export const BulkAttendeeItemSchema = z.object({
|
||||
firstName: z.string().trim().min(1, 'El nombre es obligatorio'),
|
||||
firstName: z.string().trim().min(1, 'name.required'),
|
||||
lastName: z.string().trim().optional().default(''),
|
||||
fullName: z.string().trim().optional(),
|
||||
phone: z.string().trim().min(6, 'Ingresa un número de teléfono válido'),
|
||||
email: z.string().trim().email('Email inválido').optional().or(z.literal('')),
|
||||
phone: z.string().trim().min(6, 'phone.invalid'),
|
||||
email: z.string().trim().email('email.invalid').optional().or(z.literal('')),
|
||||
notes: z.string().trim().optional(),
|
||||
});
|
||||
export type BulkAttendeeItem = z.output<typeof BulkAttendeeItemSchema>;
|
||||
|
||||
@@ -100,7 +100,7 @@ export type BillingStatusDto = z.output<typeof BillingStatusDtoSchema>;
|
||||
|
||||
// Mercado Pago requires the payer to log in with this exact email; Stripe asks
|
||||
// for it in its own checkout, so it is only mandatory for Mercado Pago.
|
||||
const payerEmailSchema = z.string().trim().email('Ingresá un email válido');
|
||||
const payerEmailSchema = z.string().trim().email('email.invalid');
|
||||
|
||||
export const SubscribeInputSchema = z.strictObject({
|
||||
payerEmail: payerEmailSchema.optional(),
|
||||
|
||||
@@ -13,7 +13,7 @@ const timeZoneSchema = z
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}, 'Zona horaria IANA inválida');
|
||||
}, 'timezone.invalid');
|
||||
|
||||
export { timeZoneSchema };
|
||||
|
||||
|
||||
32
packages/shared/src/schemas/locale.ts
Normal file
32
packages/shared/src/schemas/locale.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
// UI languages. es-AR is rioplatense Spanish (Argentina and Uruguay, voseo),
|
||||
// es-419 is neutral Latin American Spanish (tuteo). Anything else falls back
|
||||
// to English.
|
||||
export const SUPPORTED_LOCALES = ['es-AR', 'es-419', 'pt-BR', 'en'] as const;
|
||||
export const appLocaleSchema = z.enum(SUPPORTED_LOCALES);
|
||||
export type AppLocale = z.output<typeof appLocaleSchema>;
|
||||
|
||||
export const FALLBACK_LOCALE: AppLocale = 'en';
|
||||
|
||||
/** Maps one BCP 47 tag to a supported locale, or null if the language isn't
|
||||
* supported. Any Spanish outside Argentina/Uruguay is es-419 (including
|
||||
* es-ES), any Portuguese is pt-BR. */
|
||||
export function matchLocale(tag: string): AppLocale | null {
|
||||
const [language = '', ...rest] = tag.trim().toLowerCase().replace(/_/g, '-').split('-');
|
||||
const region = rest.find((part) => /^([a-z]{2}|\d{3})$/.test(part));
|
||||
if (language === 'es') return region === 'ar' || region === 'uy' ? 'es-AR' : 'es-419';
|
||||
if (language === 'pt') return 'pt-BR';
|
||||
if (language === 'en') return 'en';
|
||||
return null;
|
||||
}
|
||||
|
||||
/** First supported locale among the device's preferred languages, in order;
|
||||
* English when none matches. */
|
||||
export function resolveLocale(tags: readonly string[]): AppLocale {
|
||||
for (const tag of tags) {
|
||||
const match = matchLocale(tag);
|
||||
if (match) return match;
|
||||
}
|
||||
return FALLBACK_LOCALE;
|
||||
}
|
||||
@@ -17,25 +17,25 @@ export const CreateFirstGroupSchema = z.strictObject({
|
||||
name: z
|
||||
.string()
|
||||
.trim()
|
||||
.min(3, 'El nombre debe tener al menos 3 caracteres')
|
||||
.max(60, 'El nombre es demasiado largo (máximo 60 caracteres)'),
|
||||
days: z.array(weekdaySchema).min(1, 'Elegí al menos un día de clase'),
|
||||
.min(3, 'group.nameMin')
|
||||
.max(60, 'group.nameMax'),
|
||||
days: z.array(weekdaySchema).min(1, 'group.daysMin'),
|
||||
time: z
|
||||
.string()
|
||||
.regex(/^([01]?\d|2[0-3]):[0-5]\d$/, 'Elegí un horario válido (ej: 09:00)'),
|
||||
.regex(/^([01]?\d|2[0-3]):[0-5]\d$/, 'group.timeInvalid'),
|
||||
capacity: z
|
||||
.number({ invalid_type_error: 'Ingresá un cupo válido' })
|
||||
.int({ message: 'El cupo debe ser un número entero' })
|
||||
.min(1, 'El cupo debe ser al menos 1'),
|
||||
.number({ invalid_type_error: 'group.capacityInvalid' })
|
||||
.int({ message: 'group.capacityInt' })
|
||||
.min(1, 'group.capacityMin'),
|
||||
price: z
|
||||
.number({ invalid_type_error: 'Ingresá un precio válido' })
|
||||
.min(0, 'El precio no puede ser negativo'),
|
||||
.number({ invalid_type_error: 'group.priceInvalid' })
|
||||
.min(0, 'group.priceMin'),
|
||||
billingType: billingTypeSchema,
|
||||
dueDay: z
|
||||
.number({ invalid_type_error: 'Ingresá un día válido' })
|
||||
.int({ message: 'El día debe ser un número entero' })
|
||||
.min(1, 'El día de vencimiento debe estar entre 1 y 28')
|
||||
.max(28, 'El día de vencimiento debe estar entre 1 y 28'),
|
||||
.number({ invalid_type_error: 'group.dueDayInvalid' })
|
||||
.int({ message: 'group.dueDayInt' })
|
||||
.min(1, 'group.dueDayRange')
|
||||
.max(28, 'group.dueDayRange'),
|
||||
country: countryCodeSchema.default(DEFAULT_COUNTRY),
|
||||
});
|
||||
export type CreateFirstGroup = z.output<typeof CreateFirstGroupSchema>;
|
||||
|
||||
@@ -45,7 +45,7 @@ export type PaymentList = z.output<typeof PaymentListSchema>;
|
||||
// triggers it from the group page for a period (e.g. June's monthly fee).
|
||||
export const CreatePaymentsBatchSchema = z.strictObject({
|
||||
dueDate: isoDateTimeSchema,
|
||||
description: z.string().trim().max(120, 'La descripción es demasiado larga').optional(),
|
||||
description: z.string().trim().max(120, 'payment.descriptionMax').optional(),
|
||||
attendeeIds: z.array(z.string().min(1)).min(1).optional(),
|
||||
});
|
||||
export type CreatePaymentsBatch = z.output<typeof CreatePaymentsBatchSchema>;
|
||||
|
||||
@@ -8,5 +8,6 @@ export const ProblemDetailsSchema: z.ZodType<ProblemDetails> = z.object({
|
||||
detail: z.string().optional(),
|
||||
instance: z.string().optional(),
|
||||
code: z.string().optional(),
|
||||
params: z.record(z.string(), z.union([z.string(), z.number()])).optional(),
|
||||
errors: z.record(z.string(), z.array(z.string())).optional(),
|
||||
});
|
||||
@@ -44,10 +44,10 @@ export const GroupWaitlistEntryDtoSchema = z.object({
|
||||
export type GroupWaitlistEntryDto = z.output<typeof GroupWaitlistEntryDtoSchema>;
|
||||
|
||||
export const CreateGroupWaitlistEntrySchema = z.object({
|
||||
firstName: z.string().trim().min(1, 'El nombre es obligatorio'),
|
||||
firstName: z.string().trim().min(1, 'name.required'),
|
||||
lastName: z.string().trim().optional().default(''),
|
||||
phone: z.string().trim().min(6, 'Ingresa un número de teléfono válido'),
|
||||
email: z.string().trim().email('Email inválido').optional().or(z.literal('')),
|
||||
phone: z.string().trim().min(6, 'phone.invalid'),
|
||||
email: z.string().trim().email('email.invalid').optional().or(z.literal('')),
|
||||
notes: z.string().trim().optional(),
|
||||
});
|
||||
export type CreateGroupWaitlistEntry = z.output<typeof CreateGroupWaitlistEntrySchema>;
|
||||
|
||||
@@ -55,7 +55,7 @@ export type WhatsappConnectResultDto = z.output<typeof WhatsappConnectResultDtoS
|
||||
// scanned. National or international format; the server normalizes it with the
|
||||
// teacher's country.
|
||||
export const WhatsappPairingCodeSchema = z.strictObject({
|
||||
phoneNumber: z.string().trim().min(6, 'Ingresá tu número de WhatsApp').max(30),
|
||||
phoneNumber: z.string().trim().min(6, 'whatsapp.phoneRequired').max(30),
|
||||
});
|
||||
export type WhatsappPairingCode = z.output<typeof WhatsappPairingCodeSchema>;
|
||||
|
||||
@@ -116,7 +116,7 @@ export const UpdateGroupAutomationsSchema = z
|
||||
autoReengagement: z.boolean().optional(),
|
||||
})
|
||||
.refine((value) => value.autoPaymentReminders !== undefined || value.autoReengagement !== undefined, {
|
||||
message: 'Indicá al menos una automatización',
|
||||
message: 'whatsapp.automationRequired',
|
||||
});
|
||||
export type UpdateGroupAutomations = z.output<typeof UpdateGroupAutomationsSchema>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user