mirror of
https://github.com/paricafe/misskey.git
synced 2025-03-25 11:29:26 -05:00
detect-language fallback to local
This commit is contained in:
parent
5778632fc2
commit
8120e320ab
1 changed files with 3 additions and 1 deletions
|
@ -5,14 +5,16 @@
|
|||
|
||||
import { detect } from 'tinyld/heavy';
|
||||
import * as mfm from 'mfm-js';
|
||||
import { miLocalStorage } from '@/local-storage.js';
|
||||
|
||||
export default function detectLanguage(text: string): string {
|
||||
const localLang = (miLocalStorage.getItem('lang') ?? navigator.language).slice(0, 2);
|
||||
const nodes = mfm.parse(text);
|
||||
const filtered = mfm.extract(nodes, (node) => {
|
||||
return node.type === 'text' || node.type === 'quote';
|
||||
});
|
||||
const purified = mfm.toString(filtered);
|
||||
|
||||
if (detect(purified) === '') return 'en';
|
||||
if (detect(purified) === '') return localLang;
|
||||
return detect(purified);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue