Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate localisation config #875

Open
stephenwf opened this issue Aug 17, 2022 · 5 comments
Open

Consolidate localisation config #875

stephenwf opened this issue Aug 17, 2022 · 5 comments

Comments

@stephenwf
Copy link
Contributor

At the moment we have the locales (dynamically imported) from the BaseExtension:
https://github.com/UniversalViewer/universalviewer/blob/67ada49f6d866a51ab173d7166f6ddf04fffb471/src/content-handlers/iiif/extensions/uv-default-extension/Extension.ts

But then, some of the classes that extend from this base redefine the locales, without modification. This makes it difficult to add a new locale (e.g. #874)

Examples:

locales = {
"en-GB": defaultConfig,
"cy-GB": () => import("./config/cy-GB.json"),
"fr-FR": () => import("./config/fr-FR.json"),
"pl-PL": () => import("./config/pl-PL.json"),
"sv-SE": () => import("./config/sv-SE.json"),
};

locales = {
"en-GB": defaultConfig,
"cy-GB": () => import("./config/cy-GB.json"),
"fr-FR": () => import("./config/fr-FR.json"),
"pl-PL": () => import("./config/pl-PL.json"),
"sv-SE": () => import("./config/sv-SE.json"),
};

locales = {
"en-GB": defaultConfig,
"cy-GB": () => import("./config/cy-GB.json"),
"fr-FR": () => import("./config/fr-FR.json"),
"pl-PL": () => import("./config/pl-PL.json"),
"sv-SE": () => import("./config/sv-SE.json"),
};

A fix for now would be to remove these from the extensions that already extend from the base - unless there is a different base configuration.

@404mike
Copy link
Contributor

404mike commented Oct 17, 2022

Hi @stephenwf what do you think the best structure for the lang files would be?

Would a directory structure similar to this be a solution:

- locales
  - pdf-extensions
    - en-GB.json
    - cy-GB.json
    ....
  - openseadragon-extensions
    - en-GB.json
    - cy-GB.json
    ....

as opposed to a single locale file per language?

Also, I see that some of the languages are not in sync - en-GB sometimes contains text that isn't available in other languages. as part of this work would a script to validate the language files be an idea? I looked at something similar a while ago - #689 - something that could be run such as npm run validate-locale

@stephenwf
Copy link
Contributor Author

I think that folder structure looks good. Keeps them all in one place. I think having a - default folder or similar would be good too - to avoid the duplication that currently exists.

A validation script would certainly be very useful, good idea!

@404mike
Copy link
Contributor

404mike commented Oct 24, 2022

Hi @stephenwf,

Had a quick look at this.

Added the extension config files to src/locales -
https://github.com/404mike/universalviewer/tree/main/src/locales

I've tried passing the extension that's being requested - https://github.com/404mike/universalviewer/blob/main/src/content-handlers/iiif/IIIFContentHandler.ts#L387 - through to - https://github.com/404mike/universalviewer/blob/main/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts#L477

Also added a script to check if the languages are out of sync with the English config files for each extension - https://github.com/404mike/universalviewer/blob/main/src/locales/validate.ts - which can be run with npm run validate-locales.

Happy to discuss this in the next UV dev call.

@404mike
Copy link
Contributor

404mike commented Jan 15, 2023

Revisiting this ticket with a different approach.

I've created a locales JSON file (English only for POC)
https://github.com/404mike/universalviewer/blob/uv-875/src/locales/en-GB.json

Created a single config file for a module (uv-openseadragon only for POC)
https://github.com/404mike/universalviewer/blob/uv-875/src/content-handlers/iiif/extensions/uv-openseadragon-extension/config/config.json
The idea each module would only contain a single config.json.

Passed the extension name through to the loadConfig method
https://github.com/404mike/universalviewer/blob/uv-875/src/content-handlers/iiif/IIIFContentHandler.ts#L387

In loadConfig I add a new locale type if an extension is being passed through:
https://github.com/404mike/universalviewer/blob/uv-875/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts#L478-L484
I've done it this way because I'm unsure if anything else is dependant on this function.

The config is then sent to a new function translate_locale
https://github.com/404mike/universalviewer/blob/uv-875/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts#L499-L511
Where it replaces the placeholder text in the uv config with the string from locale.

@LlGC-szw
Copy link

All issues will be triaged for further investigation or closure by the 28 September 2023. If your issue is still relevant and would like for it be investigated further please comment by 14 September 2023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants