refactor (client): move detectLanguage to scripts/language-utils.ts

This commit is contained in:
naskya 2024-03-26 20:33:42 +09:00
parent 5e2b8d3be0
commit 400f227237
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
5 changed files with 21 additions and 16 deletions

View file

@ -286,7 +286,7 @@ import XStarButtonNoEmoji from "@/components/MkStarButtonNoEmoji.vue";
import XQuoteButton from "@/components/MkQuoteButton.vue";
import MkVisibility from "@/components/MkVisibility.vue";
import copyToClipboard from "@/scripts/copy-to-clipboard";
import detectLanguage from "@/scripts/detect-language";
import { detectLanguage } from "@/scripts/language-utils";
import { url } from "@/config";
import { pleaseLogin } from "@/scripts/please-login";
import { focusNext, focusPrev } from "@/scripts/focus";

View file

@ -201,7 +201,7 @@ import XStarButtonNoEmoji from "@/components/MkStarButtonNoEmoji.vue";
import XRenoteButton from "@/components/MkRenoteButton.vue";
import XQuoteButton from "@/components/MkQuoteButton.vue";
import copyToClipboard from "@/scripts/copy-to-clipboard";
import detectLanguage from "@/scripts/detect-language";
import { detectLanguage } from "@/scripts/language-utils";
import { url } from "@/config";
import { pleaseLogin } from "@/scripts/please-login";
import { getNoteMenu } from "@/scripts/get-note-menu";

View file

@ -329,9 +329,14 @@ import XCheatSheet from "@/components/MkCheatSheetDialog.vue";
import preprocess from "@/scripts/preprocess";
import { vibrate } from "@/scripts/vibrate";
import { langmap } from "@/scripts/langmap";
import { isSupportedLang, isSameLanguage, languageContains, parentLanguage } from "@/scripts/language-utils";
import {
detectLanguage,
isSupportedLang,
isSameLanguage,
languageContains,
parentLanguage,
} from "@/scripts/language-utils";
import type { MenuItem } from "@/types/menu";
import detectLanguage from "@/scripts/detect-language";
import icon from "@/scripts/icon";
const modal = inject("modal");

View file

@ -1,11 +0,0 @@
import { detect } from "tinyld";
import * as mfm from "mfm-js";
export default function detectLanguage(text: string): string {
const nodes = mfm.parse(text);
const filtered = mfm.extract(nodes, (node) => {
return node.type === "text" || node.type === "quote";
});
const purified = mfm.toString(filtered);
return detect(purified);
}

View file

@ -1,4 +1,15 @@
import { supportedLangs } from "@/scripts/langmap"
import { supportedLangs } from "@/scripts/langmap";
import { detect } from "tinyld";
import * as mfm from "mfm-js";
export function detectLanguage(text: string): string {
const nodes = mfm.parse(text);
const filtered = mfm.extract(nodes, (node) => {
return node.type === "text" || node.type === "quote";
});
const purified = mfm.toString(filtered);
return detect(purified);
}
export function isSupportedLang(langCode: string | null) {
if (!langCode) return false;