完善翻译

This commit is contained in:
undefined committed 2020-06-20 12:05:44 +08:00
1 parent 7d3bdc2dd1
commit 2d3cee7753
13 files changed
+1308 -1280

No files matched your search

+4 -2
View File
@@ -103,7 +103,6 @@ class HomeSecurityHandler extends Handler {
async get() {
// TODO(iceboy): pagination? or limit session count for uid?
const sessions = await token.getSessionListByUid(this.user._id);
const parsed = [];
for (const session of sessions) {
session.isCurrent = session._id === this.session._id;
session._id = md5(session._id);
@@ -111,7 +110,8 @@ class HomeSecurityHandler extends Handler {
if (geoip) session.updateGeoip = geoip.lookup(session.updateIp || session.createIp);
}
this.response.template = 'home_security.html';
this.response.body = { sessions: parsed, geoipProvider: (geoip || {}).provider };
this.response.body = { sessions, geoipProvider: (geoip || {}).provider };
if (useragent) this.response.body.icon = useragent.icon;
}
async postChangePassword({ current, password, verifyPassword }) {
@@ -160,6 +160,8 @@ class HomeSettingsHandler extends Handler {
}
async get({ category }) {
// eslint-disable-next-line prefer-destructuring
category = category[0]; // Category would be splitted into array
const path = [
['Hydro', 'homepage'],
[`home_${category}`, null],
+2 -2
View File
@@ -127,9 +127,9 @@ class RecordMainConnectionHandler extends RecordConnectionHandler {
// eslint-disable-next-line prefer-const
let [udoc, pdoc] = await Promise.all([
user.getById(this.domainId, rdoc.uid),
problem.get(this.domainId, rdoc.pid),
problem.get(this.domainId, rdoc.pid, null, false),
]);
if (pdoc.hidden && !this.user.hasPerm(PERM_VIEW_PROBLEM_HIDDEN)) pdoc = null;
if (pdoc && pdoc.hidden && !this.user.hasPerm(PERM_VIEW_PROBLEM_HIDDEN)) pdoc = null;
this.send({ html: await this.renderHTML('record_main_tr.html', { rdoc, udoc, pdoc }) });
}
}
+4 -2
View File
@@ -23,8 +23,10 @@ const Mark = require('markdown-it-mark');
// :::warn This page requires javascript. :::
// :::record-pass Accepted :::
const Container = require('markdown-it-container');
// FIXME doesn't work for webpack
const Anchor = require('markdown-it-anchor');
let Anchor = require('markdown-it-anchor');
// For webpack
if (Anchor.default) Anchor = Anchor.default;
const TOC = require('markdown-it-table-of-contents');
require('prismjs/components/index');
+7 -5
View File
@@ -1,9 +1,11 @@
const browser = require('detect-browser');
function get(str) {
const ua = browser.parseUserAgent(str);
console.log(ua);
return ua;
function parse(str) {
return browser.parseUserAgent(str);
}
global.Hydro.lib.useragent = module.exports = get;
function icon(str) {
return str.split(' ')[0].toLowerCase();
}
global.Hydro.lib.useragent = module.exports = { parse, icon };
+27 -2
View File
@@ -1,7 +1,7 @@
const assert = require('assert');
const path = require('path');
const os = require('os');
const cluster = require('cluster');
const _ = require('lodash');
const { ObjectID } = require('bson');
const Koa = require('koa');
const yaml = require('js-yaml');
@@ -32,7 +32,10 @@ const _validateObjectId = (id, key) => {
throw new ValidationError(key);
};
const _bool = (val) => !!val;
const _splitAndTrim = (val) => val.split(',').map((i) => i.trim());
const _splitAndTrim = (val) => {
const t = val.split(',').map((i) => i.trim().split('+'));
return _.flatten(t);
};
const _date = (val) => {
const d = val.split('-');
assert(d.length === 3);
@@ -412,10 +415,31 @@ class ConnectionHandler {
for (const i in p) this.request.params[p[i][0]] = decodeURIComponent(p[i][1]);
}
url(name, kwargs = {}) { // eslint-disable-line class-methods-use-this
let res = '#';
try {
delete kwargs.__keywords;
if (this.args.domainId !== 'system') {
name += '_with_domainId';
kwargs.domainId = kwargs.domainId || this.args.domainId;
}
const { anchor, query } = kwargs;
delete kwargs.anchor;
delete kwargs.query;
if (query) res = router.url(name, kwargs, { query });
else res = router.url(name, kwargs);
if (anchor) return `${res}#${anchor}`;
} catch (e) {
console.error(e.message);
}
return res;
}
async renderHTML(name, context) {
this.hasPerm = (perm) => this.user.hasPerm(perm);
const res = await template.render(name, Object.assign(context, {
handler: this,
url: (...args) => this.url(...args),
_: (str) => (str ? str.toString().translate(this.user.viewLang || this.session.viewLang) : ''),
user: this.user,
}));
@@ -450,6 +474,7 @@ function Connection(name, prefix, RouteConnHandler, permission) {
const h = new RouteConnHandler(conn);
try {
const args = { domainId: 'system', ...h.request.params };
h.args = args;
if (h.___prepare) await h.___prepare(args);
if (permission) h.checkPerm(permission);
let checking = '';