diff options
Diffstat (limited to 'ext/js/display/display-generator.js')
-rw-r--r-- | ext/js/display/display-generator.js | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js index 22912e9f..0b3236e9 100644 --- a/ext/js/display/display-generator.js +++ b/ext/js/display/display-generator.js @@ -20,7 +20,8 @@ import {ExtensionError} from '../core/extension-error.js'; import {isObject} from '../core/utilities.js'; import {getDisambiguations, getGroupedPronunciations, getTermFrequency, groupKanjiFrequencies, groupTermFrequencies, groupTermTags, isNonNounVerbOrAdjective} from '../dictionary/dictionary-data-util.js'; import {HtmlTemplateCollection} from '../dom/html-template-collection.js'; -import {distributeFurigana, getKanaMorae, getPitchCategory, isCodePointKanji, isStringPartiallyJapanese} from '../language/ja/japanese.js'; +import {distributeFurigana, getKanaMorae, getPitchCategory, isCodePointKanji} from '../language/ja/japanese.js'; +import {getLanguageFromText} from '../language/text-utilities.js'; import {createPronunciationDownstepPosition, createPronunciationGraph, createPronunciationText} from './sandbox/pronunciation-generator.js'; import {StructuredContentGenerator} from './sandbox/structured-content-generator.js'; @@ -991,12 +992,7 @@ export class DisplayGenerator { * @param {string} [language] */ _setTextContent(node, value, language) { - if (typeof language === 'string') { - node.lang = language; - } else if (isStringPartiallyJapanese(value)) { - node.lang = 'ja'; - } - + this._setElementLanguage(node, language, value); node.textContent = value; } @@ -1008,11 +1004,7 @@ export class DisplayGenerator { _setMultilineTextContent(node, value, language) { // This can't just call _setTextContent because the lack of <br> elements will // cause the text to not copy correctly. - if (typeof language === 'string') { - node.lang = language; - } else if (isStringPartiallyJapanese(value)) { - node.lang = 'ja'; - } + this._setElementLanguage(node, language, value); let start = 0; while (true) { @@ -1029,6 +1021,22 @@ export class DisplayGenerator { } /** + * @param {HTMLElement} element + * @param {string|undefined} language + * @param {string} content + */ + _setElementLanguage(element, language, content) { + if (typeof language === 'string') { + element.lang = language; + } else { + const language2 = getLanguageFromText(content); + if (language2 !== null) { + element.lang = language2; + } + } + } + + /** * @param {string} reading * @param {import('dictionary').TermPronunciation[]} termPronunciations * @param {string[]} wordClasses |