From 5497598c63c6678c2c3a906995e4ab92fa801b34 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Thu, 20 May 2021 10:40:38 +0300 Subject: [PATCH] Localize pdf-reader and note-editor --- chrome/content/zotero/reader.xul | 24 +++--- .../content/zotero/standalone/standalone.xul | 80 +++++++++++++++---- chrome/content/zotero/xpcom/editorInstance.js | 5 +- chrome/content/zotero/xpcom/intl.js | 18 +++++ chrome/content/zotero/xpcom/reader.js | 25 +++--- chrome/locale/en-US/zotero/zotero.dtd | 13 +++ chrome/locale/en-US/zotero/zotero.properties | 74 ++++++++++++++++- note-editor | 2 +- pdf-reader | 2 +- 9 files changed, 197 insertions(+), 46 deletions(-) diff --git a/chrome/content/zotero/reader.xul b/chrome/content/zotero/reader.xul index f38b524e83..0dba461772 100644 --- a/chrome/content/zotero/reader.xul +++ b/chrome/content/zotero/reader.xul @@ -75,22 +75,22 @@ --> - - + + - - + + - - + + - - - + + + - - - + + + diff --git a/chrome/content/zotero/standalone/standalone.xul b/chrome/content/zotero/standalone/standalone.xul index 1f32d39474..981ddaba07 100644 --- a/chrome/content/zotero/standalone/standalone.xul +++ b/chrome/content/zotero/standalone/standalone.xul @@ -221,24 +221,76 @@ label="&viewMenu.label;" onpopupshowing="ZoteroStandalone.onViewMenuOpen()"> - - - - + + + + + + + + - - + + - - + + - - - + + + - - - + + + diff --git a/chrome/content/zotero/xpcom/editorInstance.js b/chrome/content/zotero/xpcom/editorInstance.js index d02e977584..74c53d6b6f 100644 --- a/chrome/content/zotero/xpcom/editorInstance.js +++ b/chrome/content/zotero/xpcom/editorInstance.js @@ -104,7 +104,8 @@ class EditorInstance { dir: Zotero.dir, font: this._getFont(), hasBackup: note && !Zotero.Notes.hasSchemaVersion(note) - || !!await Zotero.NoteBackups.getNote(this._item.id) + || !!await Zotero.NoteBackups.getNote(this._item.id), + localizedStrings: Zotero.Intl.getPrefixedStrings('noteEditor') }); } @@ -1251,7 +1252,7 @@ class EditorInstance { jsonAnnotation.attachmentItemID = attachmentItem.id; jsonAnnotations.push(jsonAnnotation); } - let html = `

${Zotero.getString('note.annotationsWithDate', new Date().toLocaleString())}

\n`; + let html = `

${Zotero.getString('noteEditor.annotationsWithDate', new Date().toLocaleString())}

\n`; let { html: serializedHTML, citationItems } = await editorInstance._serializeAnnotations(jsonAnnotations, true); html += serializedHTML; citationItems = encodeURIComponent(JSON.stringify(citationItems)); diff --git a/chrome/content/zotero/xpcom/intl.js b/chrome/content/zotero/xpcom/intl.js index f4cf974d63..0220559e3e 100644 --- a/chrome/content/zotero/xpcom/intl.js +++ b/chrome/content/zotero/xpcom/intl.js @@ -133,6 +133,24 @@ Zotero.Intl = new function () { return l10n; }; + /** + * Get all strings with a specified prefix + * + * @param {String} prefix + * @return {Object} + */ + this.getPrefixedStrings = function (prefix) { + let strings = []; + let enumerator = bundle.getSimpleEnumeration(); + while (enumerator.hasMoreElements()) { + let entity = enumerator.getNext().QueryInterface(Ci.nsIPropertyElement); + if (entity.key.startsWith(prefix)) { + strings[entity.key] = entity.value; + } + } + return strings; + }; + /* * Compares two strings based on the current collator. * @param {String} string1 diff --git a/chrome/content/zotero/xpcom/reader.js b/chrome/content/zotero/xpcom/reader.js index 88de3010b6..51912efc17 100644 --- a/chrome/content/zotero/xpcom/reader.js +++ b/chrome/content/zotero/xpcom/reader.js @@ -72,7 +72,8 @@ class ReaderInstance { showItemPaneToggle: this._showItemPaneToggle, sidebarWidth: this._sidebarWidth, sidebarOpen: this._sidebarOpen, - bottomPlaceholderHeight: this._bottomPlaceholderHeight + bottomPlaceholderHeight: this._bottomPlaceholderHeight, + localizedStrings: Zotero.Intl.getPrefixedStrings('pdfReader') }, [buf]); return true; } @@ -252,7 +253,7 @@ class ReaderInstance { let menuitem; if (data.text) { menuitem = this._window.document.createElement('menuitem'); - menuitem.setAttribute('label', 'Copy'); + menuitem.setAttribute('label', Zotero.getString('general.copy')); menuitem.addEventListener('command', () => { Zotero.Utilities.Internal.copyTextToClipboard(data.text); }); @@ -262,21 +263,21 @@ class ReaderInstance { } // Zoom in menuitem = this._window.document.createElement('menuitem'); - menuitem.setAttribute('label', 'Zoom In'); + menuitem.setAttribute('label', Zotero.getString('pdfReader.zoomIn')); menuitem.addEventListener('command', () => { this._postMessage({ action: 'popupCmd', cmd: 'zoomIn' }); }); popup.appendChild(menuitem); // Zoom out menuitem = this._window.document.createElement('menuitem'); - menuitem.setAttribute('label', 'Zoom Out'); + menuitem.setAttribute('label', Zotero.getString('pdfReader.zoomOut')); menuitem.addEventListener('command', () => { this._postMessage({ action: 'popupCmd', cmd: 'zoomOut' }); }); popup.appendChild(menuitem); // Zoom 'Auto' menuitem = this._window.document.createElement('menuitem'); - menuitem.setAttribute('label', 'Automatically Resize'); + menuitem.setAttribute('label', Zotero.getString('pdfReader.zoomAuto')); menuitem.setAttribute('checked', data.isZoomAuto); menuitem.addEventListener('command', () => { this._postMessage({ action: 'popupCmd', cmd: 'zoomAuto' }); @@ -284,7 +285,7 @@ class ReaderInstance { popup.appendChild(menuitem); // Zoom 'Page Width' menuitem = this._window.document.createElement('menuitem'); - menuitem.setAttribute('label', 'Zoom to Page Width'); + menuitem.setAttribute('label', Zotero.getString('pdfReader.zoomPageWidth')); menuitem.setAttribute('checked', data.isZoomPageWidth); menuitem.addEventListener('command', () => { this._postMessage({ action: 'popupCmd', cmd: 'zoomPageWidth' }); @@ -294,7 +295,7 @@ class ReaderInstance { popup.appendChild(this._window.document.createElement('menuseparator')); // Next page menuitem = this._window.document.createElement('menuitem'); - menuitem.setAttribute('label', 'Next Page'); + menuitem.setAttribute('label', Zotero.getString('pdfReader.nextPage')); menuitem.setAttribute('disabled', !data.enableNextPage); menuitem.addEventListener('command', () => { this._postMessage({ action: 'popupCmd', cmd: 'nextPage' }); @@ -302,7 +303,7 @@ class ReaderInstance { popup.appendChild(menuitem); // Previous page menuitem = this._window.document.createElement('menuitem'); - menuitem.setAttribute('label', 'Previous Page'); + menuitem.setAttribute('label', Zotero.getString('pdfReader.previousPage')); menuitem.setAttribute('disabled', !data.enablePrevPage); menuitem.addEventListener('command', () => { this._postMessage({ action: 'popupCmd', cmd: 'prevPage' }); @@ -320,7 +321,7 @@ class ReaderInstance { let menuitem; // Add to note menuitem = this._window.document.createElement('menuitem'); - menuitem.setAttribute('label', 'Add to Note'); + menuitem.setAttribute('label', Zotero.getString('pdfReader.addToNote')); let hasActiveEditor = this._window.ZoteroContextPane.getActiveEditor(); menuitem.setAttribute('disabled', !hasActiveEditor); menuitem.addEventListener('command', () => { @@ -356,7 +357,7 @@ class ReaderInstance { popup.appendChild(this._window.document.createElement('menuseparator')); // Delete menuitem = this._window.document.createElement('menuitem'); - menuitem.setAttribute('label', 'Delete'); + menuitem.setAttribute('label', Zotero.getString('general.delete')); menuitem.setAttribute('disabled', readOnly); menuitem.addEventListener('command', () => { let data = { @@ -523,7 +524,7 @@ class ReaderInstance { let crash = message && ['setAnnotation'].includes(message.action); this._postMessage({ action: crash ? 'crash' : 'error', - message: `An error occurred during '${message ? message.action : ''}'`, + message: `${Zotero.getString('general.error')}: '${message ? message.action : ''}'`, moreInfo: { message: e.message, stack: e.stack, @@ -553,7 +554,7 @@ class ReaderInstance { /** * Return item JSON in the pdf-reader ready format - * + * * @param {Zotero.Item} item * @returns {Object|null} */ diff --git a/chrome/locale/en-US/zotero/zotero.dtd b/chrome/locale/en-US/zotero/zotero.dtd index 74bed783ec..aaf7668c7e 100644 --- a/chrome/locale/en-US/zotero/zotero.dtd +++ b/chrome/locale/en-US/zotero/zotero.dtd @@ -335,3 +335,16 @@ + + + + + + + + + + + + + diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 20d4658eca..0a3ad5f40f 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -66,6 +66,7 @@ general.tryAgain = Try Again general.tryLater = Try Later general.showDirectory = Show Directory general.continue = Continue +general.copy = Copy general.copyToClipboard = Copy to Clipboard general.cancel = Cancel general.clear = Clear @@ -405,8 +406,6 @@ pane.context.itemNotes = Item Notes pane.context.allNotes = All Notes pane.context.noNotes = No notes -noteEditor.editNote = Edit Note - itemTypes.note = Note itemTypes.annotation = Annotation itemTypes.attachment = Attachment @@ -623,8 +622,6 @@ findPDF.pdfWithMethod = PDF (%S) findPDF.noPDFsFound = No PDFs found findPDF.noPDFFound = No PDF found -note.annotationsWithDate = Annotations (%S) - attachment.fullText = Full Text attachment.acceptedVersion = Accepted Version attachment.submittedVersion = Submitted Version @@ -1263,3 +1260,72 @@ retraction.citeWarning.text1 = The item you are citing has been retracted. Do yo retraction.citeWarning.text2 = You can view the item in your library for further details on the retraction. retraction.citationWarning = A citation in your document has been retracted: retraction.citationWarning.dontWarn = Don’t warn me about this item again + +noteEditor.annotationsWithDate = Annotations (%S) +noteEditor.cut = Cut +noteEditor.copy = Copy +noteEditor.paste = Paste +noteEditor.rightToLeft = Right to Left +noteEditor.leftToRight = Left to Right +noteEditor.viewNoteBackup = View Note Backup +noteEditor.updateNotice = This note was edited with a newer version of Zotero.\nPlease update Zotero to make changes. +noteEditor.enterLink = Enter Link +noteEditor.heading1 = Heading 1 +noteEditor.heading2 = Heading 2 +noteEditor.heading3 = Heading 3 +noteEditor.paragraph = Paragraph +noteEditor.monospaced = Monospaced +noteEditor.bulletList = Bulleted List +noteEditor.orderedList = Numbered List +noteEditor.blockquote = Block Quote +noteEditor.formatText = Format Text +noteEditor.bold = Bold +noteEditor.italic = Italic +noteEditor.underline = Underline +noteEditor.returnToNotesList = Return to Notes List +noteEditor.insertLink = Insert Link +noteEditor.clearFormatting = Clear Formatting +noteEditor.align = Align +noteEditor.alignLeft = Align Left +noteEditor.alignCenter = Align Center +noteEditor.alignRight = Align Right +noteEditor.insertCitation = Insert Citation +noteEditor.more = More +noteEditor.search = Search… +noteEditor.replace = Replace… +noteEditor.matchCase = Match Case +noteEditor.wholeWords = Whole Words +noteEditor.previous = Prev +noteEditor.next = Next +noteEditor.replaceNext = Replace +noteEditor.replaceAll = Replace All +noteEditor.goToPage = Go to Page +noteEditor.showItem = Show Item +noteEditor.editCitation = Edit Citation +noteEditor.showOnPage = Show on Page +noteEditor.unlink = Unlink +noteEditor.set = Set +noteEditor.edit = Edit +noteEditor.addCitation = Add Citation +noteEditor.findAndReplace = Find and Replace +noteEditor.showInLibrary = Show in Library +noteEditor.editInWindow = Edit in a Separate Window + +pdfReader.annotations = Annotations +pdfReader.showAnnotations = Show Annotations +pdfReader.searchAnnotations = Search Annotations +pdfReader.noAnnotations = Create an annotation to see it in the sidebar +pdfReader.addText = Add extracted text +pdfReader.addComment = Add comment +pdfReader.addTags = Add tags… +pdfReader.highlightText = Highlight Text +pdfReader.addNote = Add Note +pdfReader.selectArea = Select Area +pdfReader.pickColor = Pick a Color +pdfReader.addToNote = Add to Note +pdfReader.zoomIn = Zoom In +pdfReader.zoomOut = Zoom Out +pdfReader.zoomAuto = Automatically Resize +pdfReader.zoomPageWidth = Zoom to Page Width +pdfReader.nextPage = Next Page +pdfReader.previousPage = Previous Page diff --git a/note-editor b/note-editor index 5834ce05e0..2401d208e0 160000 --- a/note-editor +++ b/note-editor @@ -1 +1 @@ -Subproject commit 5834ce05e01b123917521bfd22df7d2c242350e2 +Subproject commit 2401d208e00f330c994bfe975b2c15e781a09e82 diff --git a/pdf-reader b/pdf-reader index ac0b6bcc36..521570fba3 160000 --- a/pdf-reader +++ b/pdf-reader @@ -1 +1 @@ -Subproject commit ac0b6bcc362df7691497cdb5c0766ee1fd3f5bf8 +Subproject commit 521570fba3302b35ce9984469c579c21c1eace86