Skip to content

Commit

Permalink
Fixed dynamic imports of locale - removed unused properties
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenwf committed Jan 25, 2024
1 parent d74e34d commit 4e71ec4
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ export default class Extension extends BaseExtension<Config>
settingsDialogue: SettingsDialogue;
shareDialogue: ShareDialogue;
defaultConfig: Config = defaultConfig;
locales = {
"en-GB": defaultConfig,
};

create(): void {
super.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ export default class Extension extends BaseExtension<Config>
settingsDialogue: SettingsDialogue;
shareDialogue: ShareDialogue;
defaultConfig: Config = defaultConfig;
locales = {
"en-GB": defaultConfig,
};
lastAvCanvasIndex?: number;

create(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ export default class Extension extends BaseExtension<Config>
rightPanel: MoreInfoRightPanel;
settingsDialogue: SettingsDialogue;
defaultConfig: Config = defaultConfig;
locales = {
"en-GB": defaultConfig,
};

create(): void {
super.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export default class Extension extends BaseExtension<Config>
shareDialogue: ShareDialogue;
cfiFragement: string;
defaultConfig: Config = defaultConfig;
locales = {
"en-GB": defaultConfig,
};

create(): void {
super.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ export default class Extension extends BaseExtension<Config>
rightPanel: MoreInfoRightPanel;
settingsDialogue: SettingsDialogue;
defaultConfig: Config = defaultConfig;
locales = {
"en-GB": defaultConfig,
};

create(): void {
super.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export default class ModelViewerExtension extends BaseExtension<Config> {
settingsDialogue: SettingsDialogue;
shareDialogue: ShareDialogue;
defaultConfig: Config = defaultConfig;
locales = {
"en-GB": defaultConfig,
};

create(): void {
super.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ export default class OpenSeadragonExtension extends BaseExtension<Config> {
settingsDialogue: SettingsDialogue;
shareDialogue: ShareDialogue;
defaultConfig: Config = defaultConfig;
locales = {
"en-GB": defaultConfig,
};

create(): void {
super.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ export default class Extension extends BaseExtension<Config>
rightPanel: MoreInfoRightPanel;
settingsDialogue: SettingsDialogue;
defaultConfig: Config = defaultConfig;
locales = {
"en-GB": defaultConfig,
};

create(): void {
super.create();
Expand Down
38 changes: 14 additions & 24 deletions src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class BaseExtension<T extends BaseConfig> implements IExtension {
$element: JQuery;
$loginDialogue: JQuery;
$restrictedDialogue: JQuery;
authDialogue: AuthDialogue;
authDialogue: AuthDialogue;
annotations: AnnotationGroup[] = [];
clickThroughDialogue: ClickThroughDialogue;
extensionHost: IIIFExtensionHost;
Expand All @@ -75,11 +75,19 @@ export class BaseExtension<T extends BaseConfig> implements IExtension {
restrictedDialogue: RestrictedDialogue;
shell: Shell;
shifted: boolean = false;
store: StoreApi<ExtensionState>;
store: StoreApi<ExtensionState>;
tabbing: boolean = false;
browserDetect: BrowserDetect;
locales = {};
defaultConfig: T;
defaultConfig: T = {} as any;
localeLoaders: Record<string, () => Promise<any>> = {
"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;
Expand Down Expand Up @@ -469,33 +477,15 @@ export class BaseExtension<T extends BaseConfig> implements IExtension {
}

public async loadConfig(locale: string, extension: string): Promise<any> {
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<Object> {
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) {
Expand Down

0 comments on commit 4e71ec4

Please sign in to comment.