readium / readium-js-viewer

👁 ReadiumJS viewer: default web app for Readium.js library
BSD 3-Clause "New" or "Revised" License
549 stars 186 forks source link

User interface language #724

Open DavidPetit opened 5 years ago

DavidPetit commented 5 years ago

Hi, I am using the cloud reader lite.

I see there are i18n locale files with stings translations, but I do not understand how to use them. I would like to use the french translation. How to achieve this?

I also believe there is some kind of language detection as I read this line in Strings.js: var language = navigator.userLanguage || navigator.language;

But even if this return fr_FR in my browser, the interface of Readium is still in english.

Thanks for your help!

danielweck commented 5 years ago

Thank you for reporting this!

The current code incorrectly matches same-language locales (e.g. fr vs. fr_FR vs. fr_CA, or en_US (which is the default) vs. en_GB).

Furthermore, the underscore syntax _ is specific to the now-defunct Chrome app / extension (see https://developer.chrome.com/apps/i18n ), this should now really be a dash / hyphen -, as per BCP47 https://tools.ietf.org/rfc/bcp/bcp47 (as reported by navigator.language in all modern web browsers)

Code references:

https://github.com/readium/readium-js-viewer/blob/4ab8dab28e7ae0a74f2b1716ea09d90f7cf399a4/src/i18n/Strings.js#L28-L38

https://github.com/readium/readium-js-viewer/blob/4ab8dab28e7ae0a74f2b1716ea09d90f7cf399a4/src/i18n/Strings.js#L47

Until a proper fix, a possible workaround would have been to set navigator.userLanguage via the "web inspector" (debugging tools, console), but unfortunately to no avail because navigator properties are reset at each page refresh (at least, in my Firefox and Chrome tests). For example: navigator.userLanguage="fr" or Object.defineProperty(navigator, 'userLanguage', { get: function() { return "fr" } });