Skip to content

Commit

Permalink
Simplify localization of the "default-content" in FreeText editors
Browse files Browse the repository at this point in the history
By using "data-l10n-attrs" it's possible to instruct Fluent to localize *custom* attributes, which means that we don't need to manually translate/update the "default-content" in FreeText editors.
  • Loading branch information
Snuffleupagus committed Oct 19, 2024
1 parent c88d3a3 commit 27a0721
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 2 additions & 2 deletions l10n/en-US/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ pdfjs-editor-free-highlight-thickness-input = Thickness
pdfjs-editor-free-highlight-thickness-title =
.title = Change thickness when highlighting items other than text
pdfjs-free-text =
pdfjs-free-text2 =
.aria-label = Text Editor
pdfjs-free-text-default-content = Start typing…
.default-content = Start typing…
pdfjs-ink =
.aria-label = Draw Editor
pdfjs-ink-canvas =
Expand Down
10 changes: 3 additions & 7 deletions src/display/editor/freetext.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ class FreeTextEditor extends AnnotationEditor {

/** @inheritdoc */
static initialize(l10n, uiManager) {
AnnotationEditor.initialize(l10n, uiManager, {
strings: ["pdfjs-free-text-default-content"],
});
AnnotationEditor.initialize(l10n, uiManager);
const style = getComputedStyle(document.documentElement);

if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
Expand Down Expand Up @@ -563,12 +561,10 @@ class FreeTextEditor extends AnnotationEditor {
this.editorDiv.className = "internal";

this.editorDiv.setAttribute("id", this.#editorDivId);
this.editorDiv.setAttribute("data-l10n-id", "pdfjs-free-text");
this.editorDiv.setAttribute("data-l10n-id", "pdfjs-free-text2");
this.editorDiv.setAttribute("data-l10n-attrs", "default-content");
this.enableEditing();

AnnotationEditor._l10nPromise
.get("pdfjs-free-text-default-content")
.then(msg => this.editorDiv?.setAttribute("default-content", msg));
this.editorDiv.contentEditable = true;

const { style } = this.editorDiv;
Expand Down

0 comments on commit 27a0721

Please sign in to comment.