diff --git a/src/content-handlers/iiif/extensions/uv-aleph-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-aleph-extension/Extension.ts index 88ba7acdb..47390eb9d 100644 --- a/src/content-handlers/iiif/extensions/uv-aleph-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-aleph-extension/Extension.ts @@ -31,9 +31,6 @@ export default class Extension extends BaseExtension settingsDialogue: SettingsDialogue; shareDialogue: ShareDialogue; defaultConfig: Config = defaultConfig; - locales = { - "en-GB": defaultConfig, - }; create(): void { super.create(); diff --git a/src/content-handlers/iiif/extensions/uv-av-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-av-extension/Extension.ts index b1b4b5908..3f72620d5 100644 --- a/src/content-handlers/iiif/extensions/uv-av-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-av-extension/Extension.ts @@ -33,9 +33,6 @@ export default class Extension extends BaseExtension settingsDialogue: SettingsDialogue; shareDialogue: ShareDialogue; defaultConfig: Config = defaultConfig; - locales = { - "en-GB": defaultConfig, - }; lastAvCanvasIndex?: number; create(): void { diff --git a/src/content-handlers/iiif/extensions/uv-default-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-default-extension/Extension.ts index db66fb891..9c2f9f08f 100644 --- a/src/content-handlers/iiif/extensions/uv-default-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-default-extension/Extension.ts @@ -29,9 +29,6 @@ export default class Extension extends BaseExtension rightPanel: MoreInfoRightPanel; settingsDialogue: SettingsDialogue; defaultConfig: Config = defaultConfig; - locales = { - "en-GB": defaultConfig, - }; create(): void { super.create(); diff --git a/src/content-handlers/iiif/extensions/uv-ebook-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-ebook-extension/Extension.ts index 08d86d794..94ef931ca 100644 --- a/src/content-handlers/iiif/extensions/uv-ebook-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-ebook-extension/Extension.ts @@ -37,9 +37,6 @@ export default class Extension extends BaseExtension shareDialogue: ShareDialogue; cfiFragement: string; defaultConfig: Config = defaultConfig; - locales = { - "en-GB": defaultConfig, - }; create(): void { super.create(); diff --git a/src/content-handlers/iiif/extensions/uv-mediaelement-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-mediaelement-extension/Extension.ts index d2b738b8a..2f196c304 100644 --- a/src/content-handlers/iiif/extensions/uv-mediaelement-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-mediaelement-extension/Extension.ts @@ -46,9 +46,6 @@ export default class Extension extends BaseExtension rightPanel: MoreInfoRightPanel; settingsDialogue: SettingsDialogue; defaultConfig: Config = defaultConfig; - locales = { - "en-GB": defaultConfig, - }; create(): void { super.create(); diff --git a/src/content-handlers/iiif/extensions/uv-model-viewer-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-model-viewer-extension/Extension.ts index 73b218f06..70ab09d49 100644 --- a/src/content-handlers/iiif/extensions/uv-model-viewer-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-model-viewer-extension/Extension.ts @@ -41,9 +41,6 @@ export default class ModelViewerExtension extends BaseExtension { settingsDialogue: SettingsDialogue; shareDialogue: ShareDialogue; defaultConfig: Config = defaultConfig; - locales = { - "en-GB": defaultConfig, - }; create(): void { super.create(); diff --git a/src/content-handlers/iiif/extensions/uv-openseadragon-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-openseadragon-extension/Extension.ts index a24c6bc1e..70fc7cae1 100644 --- a/src/content-handlers/iiif/extensions/uv-openseadragon-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-openseadragon-extension/Extension.ts @@ -82,9 +82,6 @@ export default class OpenSeadragonExtension extends BaseExtension { settingsDialogue: SettingsDialogue; shareDialogue: ShareDialogue; defaultConfig: Config = defaultConfig; - locales = { - "en-GB": defaultConfig, - }; create(): void { super.create(); diff --git a/src/content-handlers/iiif/extensions/uv-pdf-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-pdf-extension/Extension.ts index b2152407f..88a7af2e7 100644 --- a/src/content-handlers/iiif/extensions/uv-pdf-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-pdf-extension/Extension.ts @@ -33,9 +33,6 @@ export default class Extension extends BaseExtension rightPanel: MoreInfoRightPanel; settingsDialogue: SettingsDialogue; defaultConfig: Config = defaultConfig; - locales = { - "en-GB": defaultConfig, - }; create(): void { super.create(); diff --git a/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts b/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts index 38f77b818..f98a7ce7f 100644 --- a/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts +++ b/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts @@ -79,7 +79,15 @@ export class BaseExtension implements IExtension { tabbing: boolean = false; browserDetect: BrowserDetect; locales = {}; - defaultConfig: T; + defaultConfig: T = {} as any; + localeLoaders: Record Promise> = { + "en-GB": () => import("../../../../locales/en-GB.json"), + "cy-GB": () => import("../../../../locales/cy-GB.json"), + "fr-FR": () => import("../../../../locales/fr-FR.json"), + "pl-PL": () => import("../../../../locales/pl-PL.json"), + "sv-SE": () => import("../../../../locales/sv-SE.json"), + }; + public create(): void { const that = this; @@ -469,33 +477,15 @@ export class BaseExtension implements IExtension { } public async loadConfig(locale: string, extension: string): Promise { - let uv_locale = locale; - if (extension) { - uv_locale = "_"; - this.locales["_"] = () => - import(`../../extensions/${extension}/config/config.json`); - } - - let config = this.locales[uv_locale]; - - if (!config) { - throw new Error("Unable to load config"); - } - if (typeof config === "object") { - config = JSON.parse(JSON.stringify(config)); - } else if (typeof config === "function") { - config = await config(); - config = JSON.parse(JSON.stringify(config)); - } - - return this.translateLocale(config, locale); + return this.translateLocale(this.defaultConfig, locale); } private async translateLocale( config: Object, locale: String ): Promise { - let localeStrings = await import(`../../../../locales/${locale}.json`); + let loader = this.localeLoaders[locale as any] || this.localeLoaders["en-GB"]; + let localeStrings = (await loader()) || {}; let conf = JSON.stringify(config); for (let str in localeStrings) {