From 5409186bf793027777b09707b33e8f87856cead0 Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 29 Jun 2022 00:26:09 +0800 Subject: [PATCH] core: skip fallbacks in english translation --- packages/hydrooj/package.json | 2 +- packages/hydrooj/src/lib/i18n.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 0231a77db..2468820fe 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "3.14.2", + "version": "3.14.3", "bin": "bin/hydrooj.js", "main": "src/loader", "module": "src/loader", diff --git a/packages/hydrooj/src/lib/i18n.ts b/packages/hydrooj/src/lib/i18n.ts index 1446c6429..00ef4d3ca 100644 --- a/packages/hydrooj/src/lib/i18n.ts +++ b/packages/hydrooj/src/lib/i18n.ts @@ -7,6 +7,11 @@ declare global { } String.prototype.translate = function translate(...languages: string[]) { + if (languages[0].startsWith('en')) { + // For most use cases, source text equals to translated text in English. + // So if it doesn't exist, we should use the original text instead of fallback. + return locales[languages[0]]?.[this] || locales['en']?.[this] || this; + } for (const language of languages) { if (!language) continue; const curr = (locales[language] || {})[this] || (locales[language.split('_')[0]] || {})[this];