Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into dev
  • Loading branch information
edsilv committed Apr 10, 2024
2 parents 7fa003b + 393fe63 commit 92ea59e
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 Expand Up @@ -1284,7 +1281,7 @@ export default class OpenSeadragonExtension extends BaseExtension<Config> {

getImageId(canvas: Canvas): string | null {
if (canvas.externalResource) {
const id: string | undefined = canvas.externalResource.data["@id"];
const id: string | undefined = canvas.externalResource.data["@id"] || canvas.externalResource.data.id;

if (id) {
return id.substr(id.lastIndexOf("/") + 1);
Expand Down Expand Up @@ -1342,7 +1339,7 @@ export default class OpenSeadragonExtension extends BaseExtension<Config> {
id += "/";
}

if (Utils.isImageProfile(service.getProfile())) {
if (Utils.isImageProfile(service.getProfile()) || Utils.isImageServiceType(service.getIIIFResourceType())) {
infoUri = id + "info.json";
}
}
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
34 changes: 12 additions & 22 deletions src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ export class BaseExtension<T extends BaseConfig> implements IExtension {
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 92ea59e

Please sign in to comment.