Add i18 support

This commit is contained in:
Urtzi Alfaro
2025-09-22 11:04:03 +02:00
parent ecfc6a1997
commit ee36c45d25
28 changed files with 2307 additions and 565 deletions

View File

@@ -80,8 +80,8 @@ export function useSupplierEnums() {
}),
getSupplierTypeLabel: (type: SupplierType): string => {
if (!type) return 'Tipo no definido';
return t(`types.${type}`);
if (!type) return t('common:status.undefined', 'Type not defined');
return t(`types.${type}`, type);
},
// Supplier Status
@@ -89,8 +89,8 @@ export function useSupplierEnums() {
enumToSelectOptions(SupplierStatus, 'status', t),
getSupplierStatusLabel: (status: SupplierStatus): string => {
if (!status) return 'Estado no definido';
return t(`status.${status}`);
if (!status) return t('common:status.undefined', 'Status not defined');
return t(`status.${status}`, status);
},
// Payment Terms
@@ -101,8 +101,8 @@ export function useSupplierEnums() {
}),
getPaymentTermsLabel: (terms: PaymentTerms): string => {
if (!terms) return 'Sin términos definidos';
return t(`payment_terms.${terms}`);
if (!terms) return t('common:forms.no_terms', 'No terms defined');
return t(`payment_terms.${terms}`, terms);
},
// Purchase Order Status
@@ -110,8 +110,8 @@ export function useSupplierEnums() {
enumToSelectOptions(PurchaseOrderStatus, 'purchase_order_status', t),
getPurchaseOrderStatusLabel: (status: PurchaseOrderStatus): string => {
if (!status) return 'Estado no definido';
return t(`purchase_order_status.${status}`);
if (!status) return t('common:status.undefined', 'Status not defined');
return t(`purchase_order_status.${status}`, status);
},
// Delivery Status
@@ -119,8 +119,8 @@ export function useSupplierEnums() {
enumToSelectOptions(DeliveryStatus, 'delivery_status', t),
getDeliveryStatusLabel: (status: DeliveryStatus): string => {
if (!status) return 'Estado no definido';
return t(`delivery_status.${status}`);
if (!status) return t('common:status.undefined', 'Status not defined');
return t(`delivery_status.${status}`, status);
},
// Quality Rating
@@ -131,8 +131,8 @@ export function useSupplierEnums() {
}),
getQualityRatingLabel: (rating: QualityRating): string => {
if (rating === undefined || rating === null) return 'Sin calificación';
return t(`quality_rating.${rating}`);
if (rating === undefined || rating === null) return t('common:status.no_rating', 'No rating');
return t(`quality_rating.${rating}`, rating.toString());
},
// Delivery Rating
@@ -143,8 +143,8 @@ export function useSupplierEnums() {
}),
getDeliveryRatingLabel: (rating: DeliveryRating): string => {
if (rating === undefined || rating === null) return 'Sin calificación';
return t(`delivery_rating.${rating}`);
if (rating === undefined || rating === null) return t('common:status.no_rating', 'No rating');
return t(`delivery_rating.${rating}`, rating.toString());
},
// Invoice Status
@@ -152,8 +152,8 @@ export function useSupplierEnums() {
enumToSelectOptions(InvoiceStatus, 'invoice_status', t),
getInvoiceStatusLabel: (status: InvoiceStatus): string => {
if (!status) return 'Estado no definido';
return t(`invoice_status.${status}`);
if (!status) return t('common:status.undefined', 'Status not defined');
return t(`invoice_status.${status}`, status);
},
// Field Labels
@@ -197,12 +197,8 @@ export function useOrderEnums() {
enumToSelectOptions(CustomerType, 'customer_types', t),
getCustomerTypeLabel: (type: CustomerType): string => {
if (!type) return 'Tipo no definido';
const translated = t(`customer_types.${type}`);
if (translated === `customer_types.${type}`) {
return type.charAt(0).toUpperCase() + type.slice(1);
}
return translated;
if (!type) return t('common:status.undefined', 'Type not defined');
return t(`customer_types.${type}`, type.charAt(0).toUpperCase() + type.slice(1));
},
// Delivery Method
@@ -210,12 +206,8 @@ export function useOrderEnums() {
enumToSelectOptions(DeliveryMethod, 'delivery_methods', t),
getDeliveryMethodLabel: (method: DeliveryMethod): string => {
if (!method) return 'Método no definido';
const translated = t(`delivery_methods.${method}`);
if (translated === `delivery_methods.${method}`) {
return method.charAt(0).toUpperCase() + method.slice(1);
}
return translated;
if (!method) return t('common:status.undefined', 'Method not defined');
return t(`delivery_methods.${method}`, method.charAt(0).toUpperCase() + method.slice(1));
},
// Payment Terms
@@ -223,8 +215,8 @@ export function useOrderEnums() {
enumToSelectOptions(OrderPaymentTerms, 'payment_terms', t),
getPaymentTermsLabel: (terms: OrderPaymentTerms): string => {
if (!terms) return 'Términos no definidos';
return t(`payment_terms.${terms}`);
if (!terms) return t('common:forms.no_terms', 'Terms not defined');
return t(`payment_terms.${terms}`, terms);
},
// Payment Method
@@ -232,8 +224,8 @@ export function useOrderEnums() {
enumToSelectOptions(PaymentMethod, 'payment_methods', t),
getPaymentMethodLabel: (method: PaymentMethod): string => {
if (!method) return 'Método no definido';
return t(`payment_methods.${method}`);
if (!method) return t('common:status.undefined', 'Method not defined');
return t(`payment_methods.${method}`, method);
},
// Payment Status
@@ -241,8 +233,8 @@ export function useOrderEnums() {
enumToSelectOptions(PaymentStatus, 'payment_status', t),
getPaymentStatusLabel: (status: PaymentStatus): string => {
if (!status) return 'Estado no definido';
return t(`payment_status.${status}`);
if (!status) return t('common:status.undefined', 'Status not defined');
return t(`payment_status.${status}`, status);
},
// Customer Segment
@@ -250,8 +242,8 @@ export function useOrderEnums() {
enumToSelectOptions(CustomerSegment, 'customer_segments', t),
getCustomerSegmentLabel: (segment: CustomerSegment): string => {
if (!segment) return 'Segmento no definido';
return t(`customer_segments.${segment}`);
if (!segment) return t('common:status.undefined', 'Segment not defined');
return t(`customer_segments.${segment}`, segment);
},
// Priority Level
@@ -259,8 +251,8 @@ export function useOrderEnums() {
enumToSelectOptions(PriorityLevel, 'priority_levels', t),
getPriorityLevelLabel: (level: PriorityLevel): string => {
if (!level) return 'Prioridad no definida';
return t(`priority_levels.${level}`);
if (!level) return t('common:priority.undefined', 'Priority not defined');
return t(`priority_levels.${level}`, level);
},
// Order Type
@@ -268,13 +260,8 @@ export function useOrderEnums() {
enumToSelectOptions(OrderType, 'order_types', t),
getOrderTypeLabel: (type: OrderType): string => {
if (!type) return 'Tipo no definido';
const translated = t(`order_types.${type}`);
// If translation failed, return a fallback
if (translated === `order_types.${type}`) {
return type.charAt(0).toUpperCase() + type.slice(1);
}
return translated;
if (!type) return t('common:status.undefined', 'Type not defined');
return t(`order_types.${type}`, type.charAt(0).toUpperCase() + type.slice(1));
},
// Order Status
@@ -282,8 +269,8 @@ export function useOrderEnums() {
enumToSelectOptions(OrderStatus, 'order_status', t),
getOrderStatusLabel: (status: OrderStatus): string => {
if (!status) return 'Estado no definido';
return t(`order_status.${status}`);
if (!status) return t('common:status.undefined', 'Status not defined');
return t(`order_status.${status}`, status);
},
// Order Source
@@ -291,8 +278,8 @@ export function useOrderEnums() {
enumToSelectOptions(OrderSource, 'order_sources', t),
getOrderSourceLabel: (source: OrderSource): string => {
if (!source) return 'Origen no definido';
return t(`order_sources.${source}`);
if (!source) return t('common:status.undefined', 'Source not defined');
return t(`order_sources.${source}`, source);
},
// Sales Channel
@@ -300,8 +287,8 @@ export function useOrderEnums() {
enumToSelectOptions(SalesChannel, 'sales_channels', t),
getSalesChannelLabel: (channel: SalesChannel): string => {
if (!channel) return 'Canal no definido';
return t(`sales_channels.${channel}`);
if (!channel) return t('common:status.undefined', 'Channel not defined');
return t(`sales_channels.${channel}`, channel);
},
// Field Labels
@@ -325,22 +312,8 @@ export function useProductionEnums() {
enumToSelectOptions(ProductionStatusEnum, 'production_status', t),
getProductionStatusLabel: (status: ProductionStatusEnum): string => {
if (!status) return 'Estado no definido';
const translated = t(`production_status.${status}`);
// If translation failed, return a fallback
if (translated === `production_status.${status}`) {
const fallbacks = {
[ProductionStatusEnum.PENDING]: 'Pendiente',
[ProductionStatusEnum.IN_PROGRESS]: 'En Proceso',
[ProductionStatusEnum.COMPLETED]: 'Completado',
[ProductionStatusEnum.CANCELLED]: 'Cancelado',
[ProductionStatusEnum.ON_HOLD]: 'En Pausa',
[ProductionStatusEnum.QUALITY_CHECK]: 'Control Calidad',
[ProductionStatusEnum.FAILED]: 'Fallido'
};
return fallbacks[status] || status;
}
return translated;
if (!status) return t('common:status.undefined', 'Status not defined');
return t(`production_status.${status}`, status);
},
// Production Priority
@@ -348,19 +321,8 @@ export function useProductionEnums() {
enumToSelectOptions(ProductionPriorityEnum, 'production_priority', t),
getProductionPriorityLabel: (priority: ProductionPriorityEnum): string => {
if (!priority) return 'Prioridad no definida';
const translated = t(`production_priority.${priority}`);
// If translation failed, return a fallback
if (translated === `production_priority.${priority}`) {
const fallbacks = {
[ProductionPriorityEnum.LOW]: 'Baja',
[ProductionPriorityEnum.MEDIUM]: 'Media',
[ProductionPriorityEnum.HIGH]: 'Alta',
[ProductionPriorityEnum.URGENT]: 'Urgente'
};
return fallbacks[priority] || priority;
}
return translated;
if (!priority) return t('common:priority.undefined', 'Priority not defined');
return t(`production_priority.${priority}`, priority);
},
// Production Batch Status
@@ -368,20 +330,8 @@ export function useProductionEnums() {
enumToSelectOptions(ProductionBatchStatus, 'batch_status', t),
getProductionBatchStatusLabel: (status: ProductionBatchStatus): string => {
if (!status) return 'Estado no definido';
const translated = t(`batch_status.${status}`);
// If translation failed, return a fallback
if (translated === `batch_status.${status}`) {
const fallbacks = {
[ProductionBatchStatus.PLANNED]: 'Planificado',
[ProductionBatchStatus.IN_PROGRESS]: 'En Proceso',
[ProductionBatchStatus.COMPLETED]: 'Completado',
[ProductionBatchStatus.CANCELLED]: 'Cancelado',
[ProductionBatchStatus.ON_HOLD]: 'En Pausa'
};
return fallbacks[status] || status;
}
return translated;
if (!status) return t('common:status.undefined', 'Status not defined');
return t(`batch_status.${status}`, status);
},
// Quality Check Status
@@ -389,20 +339,8 @@ export function useProductionEnums() {
enumToSelectOptions(QualityCheckStatus, 'quality_check_status', t),
getQualityCheckStatusLabel: (status: QualityCheckStatus): string => {
if (!status) return 'Estado no definido';
const translated = t(`quality_check_status.${status}`);
// If translation failed, return a fallback
if (translated === `quality_check_status.${status}`) {
const fallbacks = {
[QualityCheckStatus.PENDING]: 'Pendiente',
[QualityCheckStatus.IN_PROGRESS]: 'En Proceso',
[QualityCheckStatus.PASSED]: 'Aprobado',
[QualityCheckStatus.FAILED]: 'Reprobado',
[QualityCheckStatus.REQUIRES_ATTENTION]: 'Requiere Atención'
};
return fallbacks[status] || status;
}
return translated;
if (!status) return t('common:status.undefined', 'Status not defined');
return t(`quality_check_status.${status}`, status);
},
// Field Labels