Merge branch 'traditional-chinese-post-translation' into 'develop'
feat: post translation in Traditional Chinese Closes #9827 See merge request firefish/firefish!10580
This commit is contained in:
commit
9ea14ceed6
3 changed files with 18 additions and 2 deletions
|
@ -100,6 +100,7 @@
|
|||
"nodemailer": "6.9.4",
|
||||
"nsfwjs": "2.4.2",
|
||||
"oauth": "^0.10.0",
|
||||
"opencc-js": "^1.0.5",
|
||||
"os-utils": "0.0.14",
|
||||
"otpauth": "^9.1.4",
|
||||
"parse5": "7.1.2",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { URLSearchParams } from "node:url";
|
||||
import fetch from "node-fetch";
|
||||
import config from "@/config/index.js";
|
||||
import { Converter } from "opencc-js";
|
||||
import { getAgentByUrl } from "@/misc/fetch.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { Notes } from "@/models/index.js";
|
||||
|
@ -38,6 +39,13 @@ export const paramDef = {
|
|||
required: ["noteId", "targetLang"],
|
||||
} as const;
|
||||
|
||||
function convertChinese(convert: boolean, src: string) {
|
||||
if (!convert) return src;
|
||||
|
||||
const converter = Converter({ from: "cn", to: "twp" });
|
||||
return converter(src);
|
||||
}
|
||||
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const note = await getNote(ps.noteId, user).catch((err) => {
|
||||
if (err.id === "9725d0ce-ba28-4dde-95a7-2cbb2c15de24")
|
||||
|
@ -93,7 +101,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
|
||||
return {
|
||||
sourceLang: json.detectedLanguage?.language,
|
||||
text: json.translatedText,
|
||||
text: convertChinese(ps.targetLang === "zh-TW", json.translatedText),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -128,6 +136,6 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
|
||||
return {
|
||||
sourceLang: json.translations[0].detected_source_language,
|
||||
text: json.translations[0].text,
|
||||
text: convertChinese(ps.targetLang === "zh-TW", json.translations[0].text),
|
||||
};
|
||||
});
|
||||
|
|
|
@ -303,6 +303,9 @@ importers:
|
|||
oauth:
|
||||
specifier: ^0.10.0
|
||||
version: 0.10.0
|
||||
opencc-js:
|
||||
specifier: ^1.0.5
|
||||
version: 1.0.5
|
||||
os-utils:
|
||||
specifier: 0.0.14
|
||||
version: 0.0.14
|
||||
|
@ -14555,6 +14558,10 @@ packages:
|
|||
is-wsl: 2.2.0
|
||||
dev: true
|
||||
|
||||
/opencc-js@1.0.5:
|
||||
resolution: {integrity: sha512-LD+1SoNnZdlRwtYTjnQdFrSVCAaYpuDqL5CkmOaHOkKoKh7mFxUicLTRVNLU5C+Jmi1vXQ3QL4jWdgSaa4sKjg==}
|
||||
dev: false
|
||||
|
||||
/opencollective-postinstall@2.0.3:
|
||||
resolution: {integrity: sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q==}
|
||||
hasBin: true
|
||||
|
|
Loading…
Reference in a new issue