diff options
| author | Adam Soltys <[email protected]> | 2026-10-09 10:47:18 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-10-09 10:47:18 -0700 |
| commit | 7e064d5c8b33f788bda2755a32e71e2fb01a00ba (patch) | |
| tree | 66a3b32f07a98b5646ffc9b662362bc912eb7553 /src/features | |
| parent | 41d7b9d4e5d0e10cdac708d9c9cd4838e47240ec (diff) | |
| download | coinosv3-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/features')
| -rw-r--r-- | src/features/messages.js | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/features/messages.js b/src/features/messages.js index 8596f23..133b0b3 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -44,7 +44,7 @@ import { sha256 } from '@noble/hashes/sha256'; import { base64urlnopad } from '@scure/base'; import { t, getLang } from '../i18n.js'; import { inLanguage, isMachinePost, guessLang } from '../lang-guess.js'; -import { translatePieces } from '../translate-split.js'; +import { translatePieces, translatable as transParts } from '../translate-split.js'; import { animateZap, warmZapSound } from '../zap-animation.js'; import { SIGNER_SILENT } from '../dm.js'; import { cacheStorage, onCacheReady, cacheIsReady } from '../cache-store.js'; @@ -4083,7 +4083,13 @@ export function messagesFeature(ctx) { const translatable = (ev) => !!ev && !ev.pending && (ev.kind === 1 || ev.kind === COMMENT); // foreign as far as the cheap guess can tell (a script, or a clear other // language); unknown is never translated unasked - const looksForeign = (ev) => translatable(ev) && canTranslateTo(getLang()) && !inLanguage(noteText(ev), getLang()); + // A post that is only hashtags is judged by them: its tags in a script + // the reader can't read are what wants translating (as glosses). + const looksForeign = (ev) => { + if (!translatable(ev) || !canTranslateTo(getLang())) return false; + const text = noteText(ev), { prose, tags } = transParts(text, getLang()); + return prose.length ? !inLanguage(text, getLang()) : tags.length > 0; + }; const langName = (code) => { try { return new Intl.DisplayNames([getLang()], { type: 'language' }).of(code) || code; } catch { return code; } }; // the translation to SHOW for this post now, or null function shownTranslation(ev) { @@ -4109,7 +4115,7 @@ export function messagesFeature(ctx) { } const tr = await browserTranslators.get(pair); if (!tr) return null; - return translatePieces(text, (qs) => Promise.all(qs.map((q) => tr.translate(q)))); + return translatePieces(text, (qs) => Promise.all(qs.map((q) => tr.translate(q))), to); } async function translateNote(ev, { asked = false } = {}) { const k = transKey(ev); @@ -4131,13 +4137,13 @@ export function messagesFeature(ctx) { }); const j = await r.json().catch(() => ({})); if (!r.ok) throw new Error(j.error || 'translate ' + r.status); - out = { text: String(j.text || ''), source: j.source || null }; + out = { text: String(j.text || ''), source: j.source || null, nothing: !!j.nothing }; } // already in the reader's language after all: nothing to show, and // nothing to offer again if (!out.text || out.source === to || out.text.trim() === text.trim()) { translating.set(k, 'same'); - if (asked) toast(t('translateSame')); + if (asked) toast(t(out.nothing ? 'translateNothing' : 'translateSame')); } else { translations.set(k, out); translating.delete(k); |
