From 58f22d5cd791850a9530828a7b15dd5fd579fc74 Mon Sep 17 00:00:00 2001 From: John Factotum <50942278+johnfactotum@users.noreply.github.com> Date: Wed, 11 Oct 2023 01:20:34 +0800 Subject: [PATCH] Make footer translatable Also change "Footnote" to "Reference" --- src/book-viewer.js | 7 +++++-- src/reader/reader.js | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/book-viewer.js b/src/book-viewer.js index 1190d3d6..143d868b 100644 --- a/src/book-viewer.js +++ b/src/book-viewer.js @@ -27,9 +27,12 @@ import { themes, invertTheme } from './themes.js' // for use in the WebView const uiText = { + loc: _('Loc. %s of %s'), + page: _('Page %s of %s'), + pageWithoutTotal: _('Page %s'), close: _('Close'), - footnote: _('Footnote'), - goToFootnote: _('Go to Footnote'), + footnote: _('Reference'), + goToFootnote: _('Go to Reference'), } const userStylesheet = utils.readFile(Gio.File.new_for_path( diff --git a/src/reader/reader.js b/src/reader/reader.js index 837252c1..668093e0 100644 --- a/src/reader/reader.js +++ b/src/reader/reader.js @@ -2,11 +2,7 @@ import '../foliate-js/view.js' import { Overlayer } from '../foliate-js/overlayer.js' import { toPangoMarkup } from './markup.js' -// TODO: make this translatable -const format = { - loc: (a, b) => `Loc ${a} of ${b}`, - page: (a, b) => b ? `Page ${a} of ${b}` : `Page ${a}`, -} +const format = {} const emit = x => globalThis.webkit.messageHandlers.viewer .postMessage(JSON.stringify(x)) @@ -625,10 +621,21 @@ class Reader { globalThis.visualViewport.addEventListener('resize', () => emit({ type: 'pinch-zoom', scale: globalThis.visualViewport.scale })) +const printf = (str, args) => { + for (const arg of args) str = str.replace('%s', arg) + return str +} + globalThis.init = ({ uiText }) => { + format.loc = (a, b) => printf(uiText.loc, [a, b]) + format.page = (a, b) => b + ? printf(uiText.page, [a, b]) + : printf(uiText.pageWithoutTotal, [a]) + footnoteDialog.querySelector('header').innerText = uiText.footnote footnoteDialog.querySelector('[value="close"]').innerText = uiText.close footnoteDialog.querySelector('[value="go"]').innerText = uiText.goToFootnote + document.getElementById('file-input').click() }