249 lines
9.8 KiB
JavaScript
249 lines
9.8 KiB
JavaScript
// Internationalization (i18n) system
|
|
let currentLanguage = 'de';
|
|
|
|
// Translations
|
|
const translations = {
|
|
de: {
|
|
master: {
|
|
title: '📄 Master Station',
|
|
subtitle: 'PDF hochladen und Unterschrift empfangen',
|
|
waitingForStation: 'Warte auf Signatur-Station...',
|
|
connectedToStation: '✓ Verbunden mit Signatur-Station',
|
|
selectPdf: 'PDF Dokument auswählen',
|
|
selectPdfDesc: 'Wähle eine PDF-Datei aus, die unterschrieben werden soll',
|
|
selectPdfButton: 'PDF auswählen',
|
|
waitForConnection: '⚠️ Bitte warten Sie, bis die Signatur-Station verbunden ist.',
|
|
waitingForSignature: 'Warte auf Unterschrift von der Signatur-Station...',
|
|
signatureReceived: '✅ Unterschrift erhalten! Unterschrift oben sichtbar. Ziehe sie auf das PDF.',
|
|
textOverlayLabel: '📝 Text für Unterschrifts-Overlay (wird oben links angezeigt):',
|
|
prevPage: '◀ Zurück',
|
|
nextPage: 'Weiter ▶',
|
|
pageInfo: 'Seite 1 von 1',
|
|
pagePlaceholder: 'Seite',
|
|
jumpToPage: 'Springe zu Seite',
|
|
signaturePlaceholder: 'Empfangene Unterschrift wird hier angezeigt',
|
|
positionSignature: '📝 Unterschrift positionieren:',
|
|
positionSignatureDesc: 'Ziehe die Unterschrift an die gewünschte Position im PDF. Nutze den Griff rechts unten zum Skalieren.',
|
|
whichPages: 'Auf welchen Seiten platzieren?',
|
|
currentPageOnly: 'Nur aktuelle Seite',
|
|
allPages: 'Alle Seiten',
|
|
removeSignature: '🗑️ Unterschrift entfernen',
|
|
placeSignature: '✓ Unterschrift & Text platzieren & PDF erstellen',
|
|
downloadPdf: '⬇ Unterschriebene PDF herunterladen',
|
|
discard: '🗑️ Verwerfen',
|
|
downloadReady: 'PDF wurde erstellt und ist bereit zum Download',
|
|
pdfCreated: '✅ PDF wurde erstellt! Bereit zum Download.',
|
|
discardConfirm: 'Möchten Sie wirklich verwerfen? Alle Änderungen gehen verloren.'
|
|
},
|
|
signature: {
|
|
title: '✍️ Unterschriften-Station',
|
|
subtitle: 'Bereit für Unterschriften',
|
|
connecting: 'Verbinde mit Server...',
|
|
waitingForPdf: 'Warte auf PDF...',
|
|
waitingDesc: 'Bereit zum Unterschreiben. Lade ein PDF auf der Master-Station hoch.',
|
|
warning: 'Hinweis:',
|
|
warningText: 'Bereits eine andere Signatur-Station ist mit dem Master verbunden. Diese Station kann nicht verwendet werden, solange die andere Station aktiv ist.',
|
|
documentToSign: '📄 Zu unterschreibendes Dokument',
|
|
pageInfo: 'Seite 1 von 1',
|
|
scrollHint: 'Scrolle nach unten um alle Seiten zu sehen',
|
|
instruction: '📝 Anleitung:',
|
|
instructionText: 'Zeichnen Sie Ihre Unterschrift mit dem Finger oder der Maus im Feld unten. Drücken Sie dann auf "Unterschrift senden".',
|
|
signatureField: 'Unterschriftsfeld:',
|
|
clear: '🗑️ Löschen',
|
|
send: '✓ Unterschrift senden',
|
|
successTitle: '✅ Erfolgreich!',
|
|
successText: 'Ihre Unterschrift wurde erfolgreich übertragen.',
|
|
error: '❌ Fehler beim Senden der Unterschrift. Bitte versuchen Sie es erneut.'
|
|
}
|
|
},
|
|
en: {
|
|
master: {
|
|
title: '📄 Master Station',
|
|
subtitle: 'Upload PDF and receive signature',
|
|
waitingForStation: 'Waiting for signature station...',
|
|
connectedToStation: '✓ Connected to signature station',
|
|
selectPdf: 'Select PDF Document',
|
|
selectPdfDesc: 'Choose a PDF file to be signed',
|
|
selectPdfButton: 'Select PDF',
|
|
waitForConnection: '⚠️ Please wait until the signature station is connected.',
|
|
waitingForSignature: 'Waiting for signature from signature station...',
|
|
signatureReceived: '✅ Signature received! Signature visible above. Drag it onto the PDF.',
|
|
textOverlayLabel: '📝 Text for signature overlay (displayed top left):',
|
|
prevPage: '◀ Back',
|
|
nextPage: 'Next ▶',
|
|
pageInfo: 'Page 1 of 1',
|
|
pagePlaceholder: 'Page',
|
|
jumpToPage: 'Jump to page',
|
|
signaturePlaceholder: 'Received signature will be displayed here',
|
|
positionSignature: '📝 Position signature:',
|
|
positionSignatureDesc: 'Drag the signature to the desired position in the PDF. Use the handle at the bottom right to scale.',
|
|
whichPages: 'On which pages to place?',
|
|
currentPageOnly: 'Current page only',
|
|
allPages: 'All pages',
|
|
removeSignature: '🗑️ Remove signature',
|
|
placeSignature: '✓ Place signature & text & create PDF',
|
|
downloadPdf: '⬇ Download signed PDF',
|
|
discard: '🗑️ Discard',
|
|
downloadReady: 'PDF has been created and is ready for download',
|
|
pdfCreated: '✅ PDF has been created! Ready for download.',
|
|
discardConfirm: 'Do you really want to discard? All changes will be lost.'
|
|
},
|
|
signature: {
|
|
title: '✍️ Signature Station',
|
|
subtitle: 'Ready for signatures',
|
|
connecting: 'Connecting to server...',
|
|
waitingForPdf: 'Waiting for PDF...',
|
|
waitingDesc: 'Ready to sign. Upload a PDF on the Master station.',
|
|
warning: 'Note:',
|
|
warningText: 'Another signature station is already connected to the master. This station cannot be used as long as the other station is active.',
|
|
documentToSign: '📄 Document to sign',
|
|
pageInfo: 'Page 1 of 1',
|
|
scrollHint: 'Scroll down to see all pages',
|
|
instruction: '📝 Instructions:',
|
|
instructionText: 'Draw your signature with your finger or mouse in the field below. Then press "Send signature".',
|
|
signatureField: 'Signature field:',
|
|
clear: '🗑️ Clear',
|
|
send: '✓ Send signature',
|
|
successTitle: '✅ Success!',
|
|
successText: 'Your signature has been successfully transmitted.',
|
|
error: '❌ Error sending signature. Please try again.'
|
|
}
|
|
}
|
|
};
|
|
|
|
// Detect system language (default to German)
|
|
function detectLanguage() {
|
|
// Always default to German
|
|
return 'de';
|
|
}
|
|
|
|
// Initialize language
|
|
function initLanguage() {
|
|
// Check if language is stored in localStorage
|
|
const storedLang = localStorage.getItem('language');
|
|
if (storedLang && (storedLang === 'de' || storedLang === 'en')) {
|
|
currentLanguage = storedLang;
|
|
} else {
|
|
// Detect from browser
|
|
currentLanguage = detectLanguage();
|
|
localStorage.setItem('language', currentLanguage);
|
|
}
|
|
updateLanguageDisplay();
|
|
translatePage();
|
|
}
|
|
|
|
// Update language display button
|
|
function updateLanguageDisplay() {
|
|
const langDisplay = document.getElementById('langDisplay');
|
|
if (langDisplay) {
|
|
langDisplay.textContent = currentLanguage.toUpperCase();
|
|
}
|
|
}
|
|
|
|
// Toggle language
|
|
function toggleLanguage() {
|
|
currentLanguage = currentLanguage === 'de' ? 'en' : 'de';
|
|
localStorage.setItem('language', currentLanguage);
|
|
updateLanguageDisplay();
|
|
translatePage();
|
|
updateDynamicTranslations();
|
|
|
|
// Update HTML lang attribute
|
|
document.documentElement.lang = currentLanguage;
|
|
|
|
// Update text in overlay if it exists
|
|
if (typeof updateTextInOverlay === 'function') {
|
|
updateTextInOverlay();
|
|
}
|
|
|
|
// Update text input with date
|
|
if (typeof updateTextInputWithDate === 'function') {
|
|
updateTextInputWithDate();
|
|
}
|
|
}
|
|
|
|
// Translate a single element
|
|
function translateElement(element) {
|
|
const key = element.getAttribute('data-i18n');
|
|
if (!key) return;
|
|
|
|
const keys = key.split('.');
|
|
let translation = translations[currentLanguage];
|
|
|
|
for (const k of keys) {
|
|
if (translation && translation[k]) {
|
|
translation = translation[k];
|
|
} else {
|
|
return; // Translation not found
|
|
}
|
|
}
|
|
|
|
if (typeof translation === 'string') {
|
|
element.textContent = translation;
|
|
}
|
|
}
|
|
|
|
// Translate placeholder
|
|
function translatePlaceholder(element) {
|
|
const key = element.getAttribute('data-i18n-placeholder');
|
|
if (!key) return;
|
|
|
|
const keys = key.split('.');
|
|
let translation = translations[currentLanguage];
|
|
|
|
for (const k of keys) {
|
|
if (translation && translation[k]) {
|
|
translation = translation[k];
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (typeof translation === 'string') {
|
|
element.placeholder = translation;
|
|
}
|
|
}
|
|
|
|
// Translate entire page
|
|
function translatePage() {
|
|
// Translate all elements with data-i18n
|
|
document.querySelectorAll('[data-i18n]').forEach(translateElement);
|
|
|
|
// Translate placeholders
|
|
document.querySelectorAll('[data-i18n-placeholder]').forEach(translatePlaceholder);
|
|
|
|
// Update dynamic content
|
|
updateDynamicTranslations();
|
|
}
|
|
|
|
// Update dynamic translations (for content that changes)
|
|
function updateDynamicTranslations() {
|
|
// This will be called from master.js and signature.js for dynamic content
|
|
if (typeof window.updateDynamicTranslationsCustom === 'function') {
|
|
window.updateDynamicTranslationsCustom();
|
|
}
|
|
}
|
|
|
|
// Get translation by key
|
|
function t(key) {
|
|
const keys = key.split('.');
|
|
let translation = translations[currentLanguage];
|
|
|
|
for (const k of keys) {
|
|
if (translation && translation[k]) {
|
|
translation = translation[k];
|
|
} else {
|
|
return key; // Return key if translation not found
|
|
}
|
|
}
|
|
|
|
return typeof translation === 'string' ? translation : key;
|
|
}
|
|
|
|
// Initialize on page load
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initLanguage);
|
|
} else {
|
|
initLanguage();
|
|
}
|