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

Introduce a L10n-method to translate an element once, and use that in PDFLayerViewer #18643

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions web/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ class L10n {
}
}

/** @inheritdoc */
async translateOnce(element) {
try {
await this.#l10n.translateElements([element]);
} catch (ex) {
console.error(`translateOnce: "${ex}".`);
}
}

/** @inheritdoc */
async destroy() {
for (const element of this.#elements) {
Expand Down
7 changes: 5 additions & 2 deletions web/pdf_layer_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,16 @@ class PDFLayerViewer extends BaseTreeViewer {
/**
* @private
*/
async _setNestedName(element, { name = null }) {
_setNestedName(element, { name = null }) {
if (typeof name === "string") {
element.textContent = this._normalizeTextContent(name);
return;
}
element.textContent = await this._l10n.get("pdfjs-additional-layers");
element.setAttribute("data-l10n-id", "pdfjs-additional-layers");
element.style.fontStyle = "italic";
// Trigger translation manually, since translation is paused when
// the final layer-tree is appended to the DOM.
this._l10n.translateOnce(element);
}

/**
Expand Down