From 3730a4e48314ca9d9eb603f36d995e57ef88f4e6 Mon Sep 17 00:00:00 2001 From: eight Date: Tue, 12 Sep 2017 02:32:27 +0800 Subject: [PATCH] Fix: i18n and escapeHtml, url --- _locales/en/messages.json | 40 ++++++++++++++++++++++++++++ content/install-user-css.js | 53 +++++++++++++++++-------------------- edit/lint.js | 10 +------ js/dom.js | 11 ++++++++ 4 files changed, 77 insertions(+), 37 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 8c297dbc..03207d6b 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -68,6 +68,10 @@ "message": "Apply all updates", "description": "Label for the button to apply all detected updates" }, + "author": { + "message": "Author", + "description": "Label for the style author" + }, "backupButtons": { "message": "Backup", "description": "Heading for backup" @@ -277,6 +281,14 @@ "message": "Export", "description": "Label for the button to export a style ('edit' page) or all styles ('manage' page)" }, + "externalHomepage": { + "message": "Homepage", + "description": "Label for the external link to style's homepage" + }, + "externalSupport": { + "message": "Support", + "description": "Label for the external link to style's support site" + }, "filteredStyles": { "message": "$numShown$ shown of $numTotal$ total", "description": "TL note - make this message short", @@ -365,10 +377,26 @@ "message": "Discard contents of current style and overwrite it with the imported style", "description": "Label for the button to import and overwrite current style" }, + "installButton": { + "message": "Install", + "description": "Label for install button" + }, + "installButtonUpdate": { + "message": "Update", + "description": "Label for update button" + }, + "installButtonReinstall": { + "message": "Reinstall", + "description": "Label for reinstall button" + }, "installUpdate": { "message": "Install update", "description": "Label for the button to install an update for a single style" }, + "license": { + "message": "License", + "description": "Label for the license" + }, "linterConfigPopupTitle": { "message": "Set $linter$ rules configuration", "description": "Stylelint or CSSLint popup header", @@ -415,6 +443,10 @@ "message": "See a full list of rules", "description": "Stylelint or CSSLint rules label added immediately before a link" }, + "liveReloadLabel": { + "message": "Live reload", + "description": "The label of live-reload feature" + }, "manageFilters": { "message": "Filters", "description": "Label for filters container" @@ -503,6 +535,10 @@ "message": "More Options", "description": "Subheading for options section on manage page." }, + "parseUsercssError": { + "message": "Stylus failed to parse usercss:", + "description": "The error message to show when stylus failed to parse usercss" + }, "popupManageTooltip": { "message": "Shift-click or right-click opens manager with styles applicable for current site", "description": "Tooltip for the 'Manage' button in the popup." @@ -831,6 +867,10 @@ "message": "Updates installed:", "description": "Text that displays when an update is installed on options page. Followed by the number of currently installed updates." }, + "versionInvalidOlder": { + "message": "The version is older then installed style.", + "description": "Displayed when the version of style is older then installed one" + }, "writeStyleFor": { "message": "Write style for: ", "description": "Label for toolbar pop-up that precedes the links to write a new style" diff --git a/content/install-user-css.js b/content/install-user-css.js index 8dce7539..43b13eef 100644 --- a/content/install-user-css.js +++ b/content/install-user-css.js @@ -1,4 +1,4 @@ -/* global semverCompare */ +/* global semverCompare escapeHtml */ 'use strict'; @@ -47,7 +47,7 @@ function getAppliesTo(style) { } const result = [..._gen()]; if (!result.length) { - result.push('All URLs'); + result.push(chrome.i18n.getMessage('appliesToEverything')); } return result; } @@ -56,26 +56,31 @@ function initInstallPage({style, dup}, sourceLoader) { return pendingResource.then(() => { const versionTest = dup && semverCompare(style.version, dup.version); document.body.innerHTML = ''; - // FIXME: i18n document.body.appendChild(tHTML(`
-

${style.name} v${style.version}

-

${style.description}

-

Author

- ${style.author} -

License

- ${style.license} -

Applies to

+

+ ${escapeHtml(style.name)} + v${escapeHtml(style.version)} +

+

${escapeHtml(style.description)}

+

+ ${escapeHtml(style.author)} +

+ ${escapeHtml(style.license)} +

    - ${getAppliesTo(style).map(s => `
  • ${s}
  • `)} + ${getAppliesTo(style).map(s => `
  • ${escapeHtml(s)}
  • `)}
- +
- Homepage - Support + +
@@ -84,11 +89,8 @@ function initInstallPage({style, dup}, sourceLoader) {
`)); if (versionTest < 0) { - // FIXME: i18n $('.actions').before(tHTML(` -
- The version is older then installed style. -
+
`)); } $('.code').textContent = style.source; @@ -120,11 +122,9 @@ function initLiveReload(sourceLoader) { $$('.main .warning').forEach(e => e.remove()); }).catch(err => { const oldWarning = $('.main .warning'); - // FIXME: i18n const warning = tHTML(` -
- Stylus failed to parse usercss: -
${err}
+
+
${escapeHtml(err)}
`); if (oldWarning) { @@ -140,11 +140,10 @@ function initLiveReload(sourceLoader) { watcher.start(); } }); - // FIXME: i18n $('.actions').append(tHTML(` `)); $('.live-reload-checkbox').onchange = e => { @@ -162,11 +161,9 @@ function initLiveReload(sourceLoader) { function initErrorPage(err, source) { return pendingResource.then(() => { document.body.innerHTML = ''; - // FIXME: i18n document.body.appendChild(tHTML(` -
- Stylus failed to parse usercss: -
${err}
+
+
${escapeHtml(err)}
`)); diff --git a/edit/lint.js b/edit/lint.js index df103833..3ec7282c 100644 --- a/edit/lint.js +++ b/edit/lint.js @@ -1,6 +1,7 @@ /* global CodeMirror messageBox */ /* global editors makeSectionVisible showCodeMirrorPopup showHelp */ /* global onDOMscripted injectCSS require CSSLint stylelint */ +/* global escapeHtml */ 'use strict'; loadLinterAssets(); @@ -267,15 +268,6 @@ function updateLintReport(cm, delay) { } } } - function escapeHtml(html, {limit} = {}) { - const chars = {'&': '&', '<': '<', '>': '>', '"': '"', "'": ''', '/': '/'}; - let ellipsis = ''; - if (limit && html.length > limit) { - html = html.substr(0, limit); - ellipsis = '...'; - } - return html.replace(/[&<>"'/]/g, char => chars[char]) + ellipsis; - } } function renderLintReport(someBlockChanged) { diff --git a/js/dom.js b/js/dom.js index 091f58be..5c1d5897 100644 --- a/js/dom.js +++ b/js/dom.js @@ -286,3 +286,14 @@ function dieOnDysfunction() { } }); } + + +function escapeHtml(html, {limit} = {}) { + const chars = {'&': '&', '<': '<', '>': '>', '"': '"', "'": ''', '/': '/'}; + let ellipsis = ''; + if (limit && html.length > limit) { + html = html.substr(0, limit); + ellipsis = '...'; + } + return html.replace(/[&<>"'/]/g, char => chars[char]) + ellipsis; +}