diff --git a/common/options.js b/common/options.js index ca75b23..bf2053b 100644 --- a/common/options.js +++ b/common/options.js @@ -4,14 +4,21 @@ }) => { const model = { + defaultLanguage: { + title: `Default Book Language`, + description: `Default '' to set if none could be detected.`, + default: 'en', + restrict: { match: (/^[a-z]{2,10}(:?-[A-Z]{2,10})?$/), message: `Must be n ISO language code, e.g. 'en' or 'en-US'`, }, + input: { type: 'boolean', }, + }, setNavProperty: { - title: `Set 'nav' property`, + title: `Set 'nav' Property`, description: `Standard compliant when set, but disables the navigation in Sumatra PDF.`, default: false, input: { type: 'boolean', }, }, collectStyles: { - title: `Keep style information`, + title: `Keep Style Information`, description: `If enabled, some style information are extracted, but some readers won't be able to change the font settings when styles are set. Only applies to overdrive.com, reader mode always removes all styles.`, default: false, diff --git a/content/collect.js b/content/collect.js index 7461863..827ac73 100644 --- a/content/collect.js +++ b/content/collect.js @@ -8,6 +8,7 @@ const collect = (await require.async('content/collect/'+ collector)); const contents = (await collect({ styles: options.collectStyles.value, ...params, })); if (!contents) { return null; } + if (!contents.language) { contents.language = options.defaultLanguage.value; } const book = new EPub(Object.assign(contents, { markNav: options.setNavProperty.value, })); (await book.loadResources({ allowErrors: true, })); diff --git a/content/collect/about-reader.js b/content/collect/about-reader.js index 5c7f522..7348f70 100644 --- a/content/collect/about-reader.js +++ b/content/collect/about-reader.js @@ -38,7 +38,7 @@ return ({ }, ], title, description: `Offline reader version of ${url}`, - language: null, + language: (new URL(url).hostname.match(/[.](.{2})$/) || [ null, null, ])[1], creator: [ { name: author, role: 'author', }, ], resources, cover: false, diff --git a/content/collect/readability.js b/content/collect/readability.js index 31a9bb6..7a02074 100644 --- a/content/collect/readability.js +++ b/content/collect/readability.js @@ -31,6 +31,10 @@ document.querySelector('.reader-title').textContent = parsed.title || ''; document.querySelector('.reader-credits').textContent = parsed.byline || ''; document.querySelector('.container>.content').innerHTML = parsed.content; // this is not a live document, so this should be unproblematic: https://github.com/mozilla/readability/issues/404 -return aboutReader({ document, }); +const content = (await aboutReader({ document, })); +return { + ...content, + language: global.document.documentElement.lang || global.document.body.lang || content.language, +}; }); })(this);