aboutsummaryrefslogtreecommitdiffstats
path: root/names
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 /names
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 'names')
-rw-r--r--names/translate.js10
1 files changed, 5 insertions, 5 deletions
diff --git a/names/translate.js b/names/translate.js
index 7d6181d..5382711 100644
--- a/names/translate.js
+++ b/names/translate.js
@@ -3,7 +3,7 @@
// passes through here; the cache keys on the text itself, so a popular post
// is translated once whoever asks.
import { createHash } from 'node:crypto';
-import { splitProse, hasWords, translatePieces } from '../src/translate-split.js';
+import { translatable, translatePieces } from '../src/translate-split.js';
const LT = process.env.LT_URL || 'http://libretranslate:5000';
const MAX_CHARS = 5000;
@@ -48,8 +48,8 @@ export async function translate(text, target, source = 'auto') {
const key = createHash('sha256').update(target + '|' + source + '|' + text).digest('hex');
const hit = cache.get(key);
if (hit) { cache.delete(key); cache.set(key, hit); return hit; }
- const prose = splitProse(text).filter((p) => p.prose && hasWords(p.prose));
- if (!prose.length) return { text, source: source === 'auto' ? null : source };
+ const { prose, tags } = translatable(text, target);
+ if (!prose.length && !tags.length) return { text, source: source === 'auto' ? null : source, nothing: true };
await slot();
try {
const call = async (path, body) => {
@@ -63,7 +63,7 @@ export async function translate(text, target, source = 'auto') {
};
let from = source, confidence = null;
if (from === 'auto') {
- const d = await call('/detect', { q: prose.map((p) => p.prose).join('\n') });
+ const d = await call('/detect', { q: [...prose.map((p) => p.prose), ...tags.map((p) => p.keep.slice(1).replace(/_/g, ' '))].join('\n') });
from = norm(d[0]?.language) || null;
confidence = d[0]?.confidence ?? null;
if (!from) throw Object.assign(new Error('unknown language'), { status: 422 });
@@ -73,7 +73,7 @@ export async function translate(text, target, source = 'auto') {
const translated = await translatePieces(text, async (qs) => {
const r = await call('/translate', { q: qs, source: toLt(from), target: toLt(target), format: 'text' });
return Array.isArray(r.translatedText) ? r.translatedText : [r.translatedText];
- });
+ }, target);
const out = { text: translated, source: from, confidence };
cache.set(key, out);
if (cache.size > CACHE_MAX) cache.delete(cache.keys().next().value);