From 756ff21c65bcf60ed4d979b475ae08a9ad78c3be Mon Sep 17 00:00:00 2001 From: abaevbog Date: Tue, 15 Oct 2024 02:54:26 -0700 Subject: [PATCH] use simpler reader.ftl, construct announcements on the fly (#145) Per https://github.com/zotero/zotero/pull/4752#discussion_r1800481917, reader.ftl is simplified in https://github.com/zotero/zotero/pull/4756. This adds necessary logic to the reader to fetch necessary localized components and piece them together into an announcement. Also, added zotero.ftl as the localization link, since without it general strings, such as option-or-alt, are not defined. --- index.reader.html | 1 + src/common/reader.js | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/index.reader.html b/index.reader.html index 0d57da5b..c86fb1c0 100644 --- a/index.reader.html +++ b/index.reader.html @@ -9,6 +9,7 @@ + <% } %> diff --git a/src/common/reader.js b/src/common/reader.js index e4ece204..b5c4001a 100644 --- a/src/common/reader.js +++ b/src/common/reader.js @@ -275,7 +275,8 @@ class Reader { setTimeout(async () => { // Temporary until web library supports fluent if (!document.l10n) return; - let msg = await document.l10n.formatValue('pdfReader-a11yAnnotationCreated', { type : annotation.type } ); + let annotationType = await document.l10n.formatValue(`pdfReader-${annotation.type}Annotation`); + let msg = await document.l10n.formatValue('pdfReader-a11yAnnotationCreated', { type : annotationType } ); this.setA11yMessage(msg); }, 100); if (select) { @@ -793,7 +794,8 @@ class Reader { setTimeout(async () => { // Temporary until web library supports fluent if (!document.l10n) return; - let msg = await document.l10n.formatValue('pdfReader-a11yAnnotationCreated', { type : annotation.type } ); + let annotationType = await document.l10n.formatValue(`pdfReader-${annotation.type}Annotation`); + let msg = await document.l10n.formatValue('pdfReader-a11yAnnotationCreated', { type : annotationType } ); this.setA11yMessage(msg); }, 100); if (select) { @@ -1224,8 +1226,22 @@ class Reader { setTimeout(async () => { // Temporary until web library supports fluent if (!document.l10n) return; - let popupVisible = document.querySelector('.annotation-popup') ? "yes" : "no"; - let a11yAnnouncement = await document.l10n.formatValue('pdfReader-a11yAnnotationSelected', { type: annotation.type, popupVisible }); + let annotationType = await document.l10n.formatValue(`pdfReader-${annotation.type}Annotation`); + let a11yAnnouncement = await document.l10n.formatValue('pdfReader-a11yAnnotationSelected', { type: annotationType }); + // Announce if there is a popup. + if (document.querySelector('.annotation-popup')) { + a11yAnnouncement += ' ' + await document.l10n.formatValue('pdfReader-a11yAnnotationPopupAppeared'); + } + // Announce available keyboard interface options for this annotation type + if (['highlight', 'underline'].includes(annotation.type)) { + a11yAnnouncement += ' ' + await document.l10n.formatValue('pdfReader-a11yEditTextAnnotation'); + } + else if (['note', 'text', 'image'].includes(annotation.type)) { + a11yAnnouncement += ' ' + await document.l10n.formatValue('pdfReader-a11yMoveAnnotation'); + if (['text', 'image'].includes(annotation.type)) { + a11yAnnouncement += ' ' + await document.l10n.formatValue('pdfReader-a11yResizeAnnotation'); + } + } // only announce if the content view is focused. E.g. if comment in // sidebar has focus, say nothing as it will not be relevant if (document.activeElement.nodeName === 'IFRAME') {