refactor (client): move detectLanguage to scripts/language-utils.ts
This commit is contained in:
parent
5e2b8d3be0
commit
400f227237
5 changed files with 21 additions and 16 deletions
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue