diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/App.js | 36 | ||||
-rwxr-xr-x | js/Headlines.js | 12 | ||||
-rwxr-xr-x | js/common.js | 16 |
3 files changed, 54 insertions, 10 deletions
@@ -17,6 +17,15 @@ const App = { hotkey_actions: {}, is_prefs: false, LABEL_BASE_INDEX: -1024, + _translations: {}, + l10n: { + ngettext: function(msg1, msg2, n) { + return self.__((parseInt(n) > 1) ? msg2 : msg1); + }, + __: function(msg) { + return App._translations[msg] ? App._translations[msg] : msg; + } + }, FormFields: { attributes_to_string: function(attributes) { return Object.keys(attributes).map((k) => @@ -410,7 +419,7 @@ const App = { if (error && error.code && error.code != App.Error.E_SUCCESS) { console.warn("handleRpcJson: fatal error", error); - this.Error.fatal(error.code); + this.Error.fatal(error.code, error.params); return false; } @@ -526,12 +535,20 @@ const App = { PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, this._initParams); } + const translations = reply['translations']; + + if (translations) { + console.log('reading translations...'); + App._translations = translations; + } + this.initSecondStage(); }, Error: { E_SUCCESS: "E_SUCCESS", E_UNAUTHORIZED: "E_UNAUTHORIZED", E_SCHEMA_MISMATCH: "E_SCHEMA_MISMATCH", + E_URL_SCHEME_MISMATCH: "E_URL_SCHEME_MISMATCH", fatal: function (error, params = {}) { if (error == App.Error.E_UNAUTHORIZED) { window.location.href = "index.php"; @@ -539,9 +556,14 @@ const App = { } else if (error == App.Error.E_SCHEMA_MISMATCH) { window.location.href = "public.php?op=dbupdate"; return; + } else if (error == App.Error.E_URL_SCHEME_MISMATCH) { + params.description = __("URL scheme reported by your browser (%a) doesn't match server-configured SELF_URL_PATH (%b), check X-Forwarded-Proto.") + .replace("%a", params.client_scheme) + .replace("%b", params.server_scheme); + params.info = `SELF_URL_PATH: ${params.self_url_path}\nCLIENT_LOCATION: ${document.location.href}` } - return this.report(__("Fatal error: %s").replace("%s", error), + return this.report(error, {...{title: __("Fatal error")}, ...params}); }, report: function(error, params = {}) { @@ -572,10 +594,13 @@ const App = { <div class='exception-contents'> <h3>${message}</h3> - <header>${__('Stack trace')}</header> + ${params.description ? `<p>${params.description}</p>` : ''} + + ${error.stack ? + `<header>${__('Stack trace')}</header> <section> <textarea readonly='readonly'>${error.stack}</textarea> - </section> + </section>` : ''} ${params && params.info ? ` @@ -635,7 +660,8 @@ const App = { op: "rpc", method: "sanityCheck", clientTzOffset: new Date().getTimezoneOffset() * 60, - hasSandbox: "sandbox" in document.createElement("iframe") + hasSandbox: "sandbox" in document.createElement("iframe"), + clientLocation: window.location.href }; xhr.json("backend.php", params, (reply) => { diff --git a/js/Headlines.js b/js/Headlines.js index 6dbe24918..fd9bc6661 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -440,10 +440,12 @@ const Headlines = { if (headlines.vfeed_group_enabled && hl.feed_title && this.vgroup_last_feed != hl.feed_id) { const vgrhdr = `<div data-feed-id='${hl.feed_id}' class='feed-title'> - <div style='float : right'>${Feeds.renderIcon(hl.feed_id, hl.has_icon)}</div> - <a class="title" href="#" onclick="Feeds.open({feed:${hl.feed_id}})">${hl.feed_title} - <a class="catchup" title="${__('mark feed as read')}" onclick="Feeds.catchupFeedInGroup(${hl.feed_id})" href="#"><i class="icon-done material-icons">done_all</i></a> - </div>` + <div class="pull-right">${Feeds.renderIcon(hl.feed_id, hl.has_icon)}</div> + <a class="title" href="#" onclick="Feeds.open({feed:${hl.feed_id}})">${hl.feed_title}</a> + <a class="catchup" title="${__('mark feed as read')}" onclick="Feeds.catchupFeedInGroup(${hl.feed_id})" href="#"> + <i class="icon-done material-icons">done_all</i> + </a> + </div>` const tmp = document.createElement("div"); tmp.innerHTML = vgrhdr; @@ -476,6 +478,7 @@ const Headlines = { </div> <span onclick="return Headlines.click(event, ${hl.id});" data-article-id="${hl.id}" class="titleWrap hlMenuAttach"> + ${App.getInitParam("debug_headline_ids") ? `<span class="text-muted small">A: ${hl.id} F: ${hl.feed_id}</span>` : ""} <a class="title" title="${App.escapeHtml(hl.title)}" target="_blank" rel="noopener noreferrer" href="${App.escapeHtml(hl.link)}"> ${hl.title}</a> <span class="author">${hl.author}</span> @@ -542,6 +545,7 @@ const Headlines = { <i class="pub-pic pub-${hl.id} material-icons" onclick="Headlines.togglePub(${hl.id})">rss_feed</i> </div> <div onclick="return Headlines.click(event, ${hl.id})" class="title"> + ${App.getInitParam("debug_headline_ids") ? `<span class="text-muted small">A: ${hl.id} F: ${hl.feed_id}</span>` : ""} <span data-article-id="${hl.id}" class="hl-content hlMenuAttach"> <a class="title" href="${App.escapeHtml(hl.link)}">${hl.title} <span class="preview">${hl.content_preview}</span></a> <span class="author">${hl.author}</span> diff --git a/js/common.js b/js/common.js index 670ee1b30..1544e6d0b 100755 --- a/js/common.js +++ b/js/common.js @@ -1,8 +1,22 @@ 'use strict'; -/* global dijit, __, App, dojo, __csrf_token */ +/* global dijit, App, dojo, __csrf_token */ /* eslint-disable no-new */ +/* exported __ */ +function __(msg) { + if (typeof App != "undefined") { + return App.l10n.__(msg); + } else { + return msg; + } +} + +/* exported ngettext */ +function ngettext(msg1, msg2, n) { + return __((parseInt(n) > 1) ? msg2 : msg1); +} + /* exported $ */ function $(id) { console.warn("FIXME: please use App.byId() or document.getElementById() instead of $():", id); |