Fix: i18n and escapeHtml, url

This commit is contained in:
eight 2017-09-12 02:32:27 +08:00
parent 20481c9180
commit 3730a4e483
4 changed files with 77 additions and 37 deletions

View File

@ -68,6 +68,10 @@
"message": "Apply all updates", "message": "Apply all updates",
"description": "Label for the button to apply all detected updates" "description": "Label for the button to apply all detected updates"
}, },
"author": {
"message": "Author",
"description": "Label for the style author"
},
"backupButtons": { "backupButtons": {
"message": "Backup", "message": "Backup",
"description": "Heading for backup" "description": "Heading for backup"
@ -277,6 +281,14 @@
"message": "Export", "message": "Export",
"description": "Label for the button to export a style ('edit' page) or all styles ('manage' page)" "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": { "filteredStyles": {
"message": "$numShown$ shown of $numTotal$ total", "message": "$numShown$ shown of $numTotal$ total",
"description": "TL note - make this message short", "description": "TL note - make this message short",
@ -365,10 +377,26 @@
"message": "Discard contents of current style and overwrite it with the imported style", "message": "Discard contents of current style and overwrite it with the imported style",
"description": "Label for the button to import and overwrite current 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": { "installUpdate": {
"message": "Install update", "message": "Install update",
"description": "Label for the button to install an update for a single style" "description": "Label for the button to install an update for a single style"
}, },
"license": {
"message": "License",
"description": "Label for the license"
},
"linterConfigPopupTitle": { "linterConfigPopupTitle": {
"message": "Set $linter$ rules configuration", "message": "Set $linter$ rules configuration",
"description": "Stylelint or CSSLint popup header", "description": "Stylelint or CSSLint popup header",
@ -415,6 +443,10 @@
"message": "See a full list of rules", "message": "See a full list of rules",
"description": "Stylelint or CSSLint rules label added immediately before a link" "description": "Stylelint or CSSLint rules label added immediately before a link"
}, },
"liveReloadLabel": {
"message": "Live reload",
"description": "The label of live-reload feature"
},
"manageFilters": { "manageFilters": {
"message": "Filters", "message": "Filters",
"description": "Label for filters container" "description": "Label for filters container"
@ -503,6 +535,10 @@
"message": "More Options", "message": "More Options",
"description": "Subheading for options section on manage page." "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": { "popupManageTooltip": {
"message": "Shift-click or right-click opens manager with styles applicable for current site", "message": "Shift-click or right-click opens manager with styles applicable for current site",
"description": "Tooltip for the 'Manage' button in the popup." "description": "Tooltip for the 'Manage' button in the popup."
@ -831,6 +867,10 @@
"message": "Updates installed:", "message": "Updates installed:",
"description": "Text that displays when an update is installed on options page. Followed by the number of currently installed updates." "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": { "writeStyleFor": {
"message": "Write style for: ", "message": "Write style for: ",
"description": "Label for toolbar pop-up that precedes the links to write a new style" "description": "Label for toolbar pop-up that precedes the links to write a new style"

View File

@ -1,4 +1,4 @@
/* global semverCompare */ /* global semverCompare escapeHtml */
'use strict'; 'use strict';
@ -47,7 +47,7 @@ function getAppliesTo(style) {
} }
const result = [..._gen()]; const result = [..._gen()];
if (!result.length) { if (!result.length) {
result.push('All URLs'); result.push(chrome.i18n.getMessage('appliesToEverything'));
} }
return result; return result;
} }
@ -56,26 +56,31 @@ function initInstallPage({style, dup}, sourceLoader) {
return pendingResource.then(() => { return pendingResource.then(() => {
const versionTest = dup && semverCompare(style.version, dup.version); const versionTest = dup && semverCompare(style.version, dup.version);
document.body.innerHTML = ''; document.body.innerHTML = '';
// FIXME: i18n
document.body.appendChild(tHTML(` document.body.appendChild(tHTML(`
<div class="container"> <div class="container">
<div class="header"> <div class="header">
<h1>${style.name} <small class="meta-version">v${style.version}</small></h1> <h1>
<p>${style.description}</p> ${escapeHtml(style.name)}
<h3>Author</h3> <small class="meta-version">v${escapeHtml(style.version)}</small>
${style.author} </h1>
<h3>License</h3> <p>${escapeHtml(style.description)}</p>
${style.license} <h3 i18n-text="author"></h3>
<h3>Applies to</h3> ${escapeHtml(style.author)}
<h3 i18n-text="license"></h3>
${escapeHtml(style.license)}
<h3 i18n-text="appliesLabel"></h3>
<ul> <ul>
${getAppliesTo(style).map(s => `<li>${s}</li>`)} ${getAppliesTo(style).map(s => `<li>${escapeHtml(s)}</li>`)}
</ul> </ul>
<div class="actions"> <div class="actions">
<button class="install">${!dup ? 'Install' : versionTest > 0 ? 'Update' : 'Reinstall'}</button> <button class="install">${t(
!dup ? 'installButton' : versionTest > 0 ?
'installButtonUpdate' : 'installButtonReinstall'
)}</button>
</div> </div>
<div class="external"> <div class="external">
<a href="${style.url}" target="_blank">Homepage</a> <a href="${decodeURI(style.url)}" target="_blank" i18n-text="externalHomepage" rel="noopener"></a>
<a href="${style.supportURL}" target="_blank">Support</a> <a href="${decodeURI(style.supportURL)}" target="_blank" i18n-text="externalSupport" rel="noopener"></a>
</div> </div>
</div> </div>
<div class="main"> <div class="main">
@ -84,11 +89,8 @@ function initInstallPage({style, dup}, sourceLoader) {
</div> </div>
`)); `));
if (versionTest < 0) { if (versionTest < 0) {
// FIXME: i18n
$('.actions').before(tHTML(` $('.actions').before(tHTML(`
<div class="warning"> <div class="warning" i18n-text="versionInvalidOlder"></div>
The version is older then installed style.
</div>
`)); `));
} }
$('.code').textContent = style.source; $('.code').textContent = style.source;
@ -120,11 +122,9 @@ function initLiveReload(sourceLoader) {
$$('.main .warning').forEach(e => e.remove()); $$('.main .warning').forEach(e => e.remove());
}).catch(err => { }).catch(err => {
const oldWarning = $('.main .warning'); const oldWarning = $('.main .warning');
// FIXME: i18n
const warning = tHTML(` const warning = tHTML(`
<div class="warning"> <div class="warning" i18n-text="parseUsercssError">
Stylus failed to parse usercss: <pre>${escapeHtml(err)}</pre>
<pre>${err}</pre>
</div> </div>
`); `);
if (oldWarning) { if (oldWarning) {
@ -140,11 +140,10 @@ function initLiveReload(sourceLoader) {
watcher.start(); watcher.start();
} }
}); });
// FIXME: i18n
$('.actions').append(tHTML(` $('.actions').append(tHTML(`
<label class="live-reload"> <label class="live-reload">
<input type="checkbox" class="live-reload-checkbox"> <input type="checkbox" class="live-reload-checkbox">
<span>Live reload</span> <span i18n-text="liveReloadLabel"></span>
</label> </label>
`)); `));
$('.live-reload-checkbox').onchange = e => { $('.live-reload-checkbox').onchange = e => {
@ -162,11 +161,9 @@ function initLiveReload(sourceLoader) {
function initErrorPage(err, source) { function initErrorPage(err, source) {
return pendingResource.then(() => { return pendingResource.then(() => {
document.body.innerHTML = ''; document.body.innerHTML = '';
// FIXME: i18n
document.body.appendChild(tHTML(` document.body.appendChild(tHTML(`
<div class="warning"> <div class="warning" i18n-text="parseUsercssError">
Stylus failed to parse usercss: <pre>${escapeHtml(err)}</pre>
<pre>${err}</pre>
</div> </div>
<div class="code"></div> <div class="code"></div>
`)); `));

View File

@ -1,6 +1,7 @@
/* global CodeMirror messageBox */ /* global CodeMirror messageBox */
/* global editors makeSectionVisible showCodeMirrorPopup showHelp */ /* global editors makeSectionVisible showCodeMirrorPopup showHelp */
/* global onDOMscripted injectCSS require CSSLint stylelint */ /* global onDOMscripted injectCSS require CSSLint stylelint */
/* global escapeHtml */
'use strict'; 'use strict';
loadLinterAssets(); loadLinterAssets();
@ -267,15 +268,6 @@ function updateLintReport(cm, delay) {
} }
} }
} }
function escapeHtml(html, {limit} = {}) {
const chars = {'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;', '/': '&#x2F;'};
let ellipsis = '';
if (limit && html.length > limit) {
html = html.substr(0, limit);
ellipsis = '...';
}
return html.replace(/[&<>"'/]/g, char => chars[char]) + ellipsis;
}
} }
function renderLintReport(someBlockChanged) { function renderLintReport(someBlockChanged) {

View File

@ -286,3 +286,14 @@ function dieOnDysfunction() {
} }
}); });
} }
function escapeHtml(html, {limit} = {}) {
const chars = {'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;', '/': '&#x2F;'};
let ellipsis = '';
if (limit && html.length > limit) {
html = html.substr(0, limit);
ellipsis = '...';
}
return html.replace(/[&<>"'/]/g, char => chars[char]) + ellipsis;
}