aboutsummaryrefslogtreecommitdiffstats
path: root/src/lang-guess.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-10-09 10:47:18 -0700
committerAdam Soltys <[email protected]>2026-10-09 10:47:18 -0700
commit7e064d5c8b33f788bda2755a32e71e2fb01a00ba (patch)
tree66a3b32f07a98b5646ffc9b662362bc912eb7553 /src/lang-guess.js
parent41d7b9d4e5d0e10cdac708d9c9cd4838e47240ec (diff)
downloadcoinosv3-7e064d5c8b33f788bda2755a32e71e2fb01a00ba.tar.gz
coinosv3-7e064d5c8b33f788bda2755a32e71e2fb01a00ba.zip
Translation: a hashtag in a script the reader can't read gets its translation in brackets after it — "#総合部絵チャ (…)" — the tag itself kept as the link it is. A post that is only such hashtags now counts as foreign (it was judged by its prose alone, of which it has none, so nothing ever offered to translate it), and ⋯ → Translate on a post with no words says so instead of "already in your language". The registrar's language detection reads the glossed tags too; lang-guess's scriptOf takes a minimum (a two-character tag has a script too).
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vps2H27rhbG9ZqseGfMrc3
Diffstat (limited to 'src/lang-guess.js')
-rw-r--r--src/lang-guess.js6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lang-guess.js b/src/lang-guess.js
index f688cac..1d60c59 100644
--- a/src/lang-guess.js
+++ b/src/lang-guess.js
@@ -15,7 +15,7 @@ const SCRIPTS = [
['han', /[一-鿿㐀-䶿]/g],
['hangul', /[가-힯ᄀ-ᇿ]/g],
];
-const LANG_SCRIPT = {
+export const LANG_SCRIPT = {
en: 'latin', es: 'latin', fr: 'latin', de: 'latin', pt: 'latin', id: 'latin', sw: 'latin', tr: 'latin', vi: 'latin',
ru: 'cyrillic', ar: 'arabic', ur: 'arabic', hi: 'devanagari', mr: 'devanagari', bn: 'bengali', ta: 'tamil', te: 'telugu',
ja: 'kana', ko: 'hangul', zh: 'han',
@@ -37,14 +37,14 @@ const STOPSETS = Object.fromEntries(Object.entries(STOP).map(([k, v]) => [k, new
export const proseOf = (text) => String(text || '')
.replace(/https?:\/\/\S+/g, ' ').replace(/nostr:[a-z0-9]+/gi, ' ').replace(/#[\p{L}\p{N}_]+/gu, ' ');
-export function scriptOf(text) {
+export function scriptOf(text, min = 3) {
let best = null, bestN = 0, total = 0;
for (const [name, re] of SCRIPTS) {
const n = (text.match(re) || []).length;
total += n;
if (n > bestN) { best = name; bestN = n; }
}
- return total < 3 ? null : best;
+ return total < min ? null : best;
}
// A language code from the app's list, or null when it cannot tell.