Refactor UI messages for localization support

All user-facing messages now use a `localized` object instead of hardcoded strings, enabling easier translation. Introduced `formatLocalized` for template formatting. Updated all dialogs and notifications to use localized keys, improving internationalization across the app.
This commit is contained in:
2026-02-16 17:34:17 +01:00
parent 8f94317e80
commit dc6a2027d6
2 changed files with 27 additions and 25 deletions

View File

@@ -1,3 +1,5 @@
const formatLocalized = (template, ...args) => typeof template === 'string' ? template.replace(/\{(\d+)\}/g, (_, idx) => args[idx] ?? '') : '';
class App {
constructor(envelopeKey, envelopeReceiver, documentBytes, licenseKey, locale, container) {
this.container = container ?? `#${this.constructor.name.toLowerCase()}`;
@@ -112,8 +114,8 @@ class App {
Comp.SignatureProgress.SignedCount = 0;
if (result.isConfirmed) {
Swal.fire({
title: 'Erfolg',
text: 'Dokument wurde zurückgesetzt',
title: localized.success,
text: localized.documentReset,
icon: 'info',
})
}
@@ -168,9 +170,9 @@ class App {
case 'COPY_URL':
const url = window.location.href.replace(/\/readonly/gi, '');
navigator.clipboard.writeText(url).then(function () {
bsNotify('Kopiert', { alert_type: 'success', delay: 4, icon_name: 'check_circle' });
bsNotify(localized.copyLinkSuccess, { alert_type: 'success', delay: 4, icon_name: 'check_circle' });
}).catch(function (err) {
bsNotify('Unerwarteter Fehler', { alert_type: 'danger', delay: 4, icon_name: 'error' });
bsNotify(localized.copyLinkFailure ?? localized.unexpectedErrorTitle, { alert_type: 'danger', delay: 4, icon_name: 'error' });
});
break;
@@ -194,11 +196,11 @@ class App {
if (!allViewed) {
const unviewed = JSON.parse(sessionStorage.getItem('pspdf_unviewed_pages') || '[]')
const message = unviewed.length
? `Bitte sehen Sie sich die folgenden Seiten an: ${unviewed.join(', ')}`
: 'Bitte sehen Sie sich alle Seiten an.'
? formatLocalized(localized.viewRemainingPages, unviewed.join(', '))
: localized.viewAllPages
await Swal.fire({
title: 'Warnung',
title: localized.warning,
text: message,
icon: 'warning'
})
@@ -216,8 +218,8 @@ class App {
if (hasEmptyReq) {
Swal.fire({
title: 'Warnung',
text: 'Bitte füllen Sie alle Standortinformationen vollständig aus!',
title: localized.warning,
text: localized.locationFieldsRequired,
icon: 'warning',
})
return false;
@@ -229,8 +231,8 @@ class App {
for (var f of iCityFields)
if (!IS_MOBILE_DEVICE && !city_regex.test(f.value)) {
Swal.fire({
title: 'Warnung',
text: `Bitte überprüfen Sie die eingegebene Ortsangabe "${f.value}" auf korrekte Formatierung. Beispiele für richtige Formate sind: München, Île-de-France, Sauðárkrókur, San Francisco, St. Catharines usw.`,
title: localized.warning,
text: formatLocalized(localized.cityFormatInvalid, f.value),
icon: 'warning',
})
return false;
@@ -240,8 +242,8 @@ class App {
const validationResult = await this.validateAnnotations(this.signatureCount)
if (validationResult === false) {
Swal.fire({
title: 'Warnung',
text: 'Es wurden nicht alle Signaturfelder ausgefüllt!',
title: localized.warning,
text: localized.missingSignatures,
icon: 'warning',
})
return false
@@ -268,8 +270,8 @@ class App {
await this.pdfKit.save()
} catch (e) {
Swal.fire({
title: 'Fehler',
text: 'Umschlag konnte nicht signiert werden!',
title: localized.warning,
text: localized.envelopeSignError,
icon: 'error',
})
return false
@@ -282,16 +284,16 @@ class App {
if (!res.ok) {
if (res.status === 409) {
Swal.fire({
title: 'Warnung',
text: 'Umschlag ist nicht mehr verfügbar.',
title: localized.warning,
text: localized.envelopeUnavailable,
icon: 'warning',
})
return false
}
else if (res.status === 423) {
Swal.fire({
title: 'Info',
text: 'Dokument wurde von einem Empfänger abgelehnt. Sie werden weitergeleitet...',
title: localized.info ?? localized.warning,
text: localized.envelopeRejectedRedirect,
icon: 'info',
timer: 2000,
showConfirmButton: false
@@ -306,8 +308,8 @@ class App {
return true
} catch (e) {
Swal.fire({
title: 'Fehler',
text: 'Umschlag konnte nicht signiert werden!',
title: localized.warning,
text: localized.envelopeSignError,
icon: 'error',
})
return false
@@ -329,8 +331,8 @@ class App {
async handleReset(event) {
const result = Swal.fire({
title: 'Sind sie sicher?',
text: 'Wollen Sie das Dokument und alle erstellten Signaturen zurücksetzen?',
title: localized.resetConfirmTitle,
text: localized.resetConfirmText,
icon: 'question',
showCancelButton: true
})