core: translation enhance

This commit is contained in:
undefined committed 2022-06-29 00:15:22 +08:00
1 parent 2b0bd3df04
commit 0bb6be0eaf
4 files changed
+5 -4

No files matched your search

@@ -5,6 +5,7 @@ import token from 'hydrooj/src/model/token';
export default async (ctx, next) => {
const forceDomain = /^\/d\/([^/]+)\//.exec(ctx.request.path);
ctx.originalPath = ctx.request.path;
ctx.path = ctx.request.path = ctx.request.path.replace(/^\/d\/[^/]+\//, '/');
const [xff, xhost] = system.getMany(['server.xff', 'server.xhost']);
const ip = ctx.request.headers[xff?.toLowerCase() || ''] as string || ctx.request.ip;
@@ -1,6 +1,5 @@
import { ObjectID } from 'mongodb';
import avatar from 'hydrooj/src/lib/avatar';
import * as system from 'hydrooj/src/model/system';
import type { KoaContext } from '../server';
function serializer(k: string, v: any) {
@@ -66,7 +65,7 @@ export default (router, logger) => async (ctx: KoaContext, next) => {
ctx.translate = (str: string) => {
if (!str) return '';
const lang = ctx.HydroContext.user?.viewLang || ctx.session?.viewLang;
return str.toString().translate(lang, ...ctx.acceptsLanguages(), system.get('server.language'));
return str.toString().translate(lang, ...ctx.acceptsLanguages());
};
await next();
};