dees-document/ts_shared/translation.ts

143 lines
4.7 KiB
TypeScript

import * as interfaces from './interfaces/index.js';
// Define English translations without enforcing TTranslationImplementation yet
export const EN_translations = {
address: 'Address',
bankConnection: 'Bank Connection',
contactInfo: 'Contact Info',
description: 'Description',
invoice: 'Invoice',
itemPos: 'Item Pos.',
quantity: 'Quantity',
registrationInfo: 'Registration Info',
reverseVatNote: 'VAT arises on a reverse charge basis and is payable by the customer.',
totalNetPrice: 'Total Net Price',
unitNetPrice: 'Unit Net Price',
unitType: 'Unit Type',
yourCustomerId: 'Your Customer ID:',
yourVatId: 'Your vat id on file:',
continuesOnPage: 'Continues on page',
finalPageStatement: 'This is the final page of this document.',
page: 'Page',
vatShort: 'VAT',
} as const;
// Infer keys of EN_translations
export type TTranslationKey = keyof typeof EN_translations;
// Define the type for all translations based on EN_translations keys
export type TTranslationImplementation = {
[key in TTranslationKey]: string;
};
// Define German translations
export const DE_translations: TTranslationImplementation = {
address: 'Adresse',
bankConnection: 'Bankverbindung',
contactInfo: 'Kontaktinformationen',
description: 'Beschreibung',
invoice: 'Rechnung',
itemPos: 'Pos.',
quantity: 'Anzahl',
registrationInfo: 'HRA/HRB Info',
reverseVatNote:
'Umkehr der Umsatzsteuerpflicht: Der Rechnungsempfänger ist für die korrekte Abrechnung der Umsatzsteuer zuständig.',
totalNetPrice: 'Summe netto',
unitNetPrice: 'Einheit netto',
unitType: 'Einheit',
yourCustomerId: 'Ihre Kundennummer:',
yourVatId: 'Ihre Umsatzsteuer-ID:',
continuesOnPage: 'Fortsetzung auf Seite',
finalPageStatement: 'Dies ist die letzte Seite dieses Dokuments.',
page: 'Seite',
vatShort: 'USt',
};
// Define Spanish translations
export const ES_translations: TTranslationImplementation = {
address: 'Dirección',
bankConnection: 'Conexión bancaria',
contactInfo: 'Información de contacto',
description: 'Descripción',
invoice: 'Factura',
itemPos: 'Pos.',
quantity: 'Cantidad',
registrationInfo: 'Información de registro',
reverseVatNote: 'El IVA se aplica por inversión del sujeto pasivo y debe ser pagado por el cliente.',
totalNetPrice: 'Precio total neto',
unitNetPrice: 'Precio unitario neto',
unitType: 'Tipo de unidad',
yourCustomerId: 'Su número de cliente:',
yourVatId: 'Su ID de IVA:',
continuesOnPage: 'Continúa en la página',
finalPageStatement: 'Esta es la última página de este documento.',
page: 'Página',
vatShort: 'IVA',
};
// Define French translations
export const FR_translations: TTranslationImplementation = {
address: 'Adresse',
bankConnection: 'Coordonnées bancaires',
contactInfo: 'Informations de contact',
description: 'Description',
invoice: 'Facture',
itemPos: 'Position',
quantity: 'Quantité',
registrationInfo: "Informations d'enregistrement",
reverseVatNote:
"La TVA s'applique selon le mécanisme d'autoliquidation et est à payer par le client.",
totalNetPrice: 'Prix net total',
unitNetPrice: 'Prix unitaire net',
unitType: "Type d'unité",
yourCustomerId: 'Votre numéro de client :',
yourVatId: 'Votre numéro de TVA :',
continuesOnPage: 'Continue sur la page',
finalPageStatement: 'Ceci est la dernière page de ce document.',
page: 'Page',
vatShort: 'TVA',
};
// Define Italian translations
export const IT_translations: TTranslationImplementation = {
address: 'Indirizzo',
bankConnection: 'Coordinate bancarie',
contactInfo: 'Informazioni di contatto',
description: 'Descrizione',
invoice: 'Fattura',
itemPos: 'Pos.',
quantity: 'Quantità',
registrationInfo: 'Informazioni di registrazione',
reverseVatNote: "L'IVA è applicata con inversione contabile ed è a carico del cliente.",
totalNetPrice: 'Prezzo netto totale',
unitNetPrice: 'Prezzo netto unitario',
unitType: 'Tipo di unità',
yourCustomerId: 'Il tuo numero cliente:',
yourVatId: 'Il tuo numero di partita IVA:',
continuesOnPage: 'Continua alla pagina',
finalPageStatement: 'Questa è l\'ultima pagina di questo documento.',
page: 'Pagina',
vatShort: 'IVA',
};
// Language Code Map
export const languageCodeMap: Record<string, TTranslationImplementation> = {
EN: EN_translations,
DE: DE_translations,
ES: ES_translations,
FR: FR_translations,
IT: IT_translations,
};
// Language Code Type
export type TLanguageCode = keyof typeof languageCodeMap;
// Translate Function
export const translate = (
languageCode: TLanguageCode,
key: TTranslationKey,
defaultValue: string
): string => {
const translations = languageCodeMap[languageCode] || EN_translations;
return translations[key] || defaultValue;
};