fix: convert katakana proper nouns (e.g. ヨルシカ) to romaji in sort tags

When kuromoji marks a katakana token as reading '*' (unknown word — common
for band names like ヨルシカ), the code fell back to the surface_form which
is still katakana. _hiraToRomaji can't handle katakana so it passed through
unchanged, causing sort tags to show ヨルシカ instead of Yorushika.

Fix: if the surface_form contains katakana and reading is *, convert it
mechanically via _kataToHira + _hiraToRomaji — katakana-to-romaji is always
unambiguous and needs no dictionary.

Also add a Japanese-char guard in the frontend when applying romaji index
values, so stale cache entries can never overwrite correct values with Japanese.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-05-27 02:52:35 +02:00
1 parent e6d85e63a8
commit 212491aa89
2 files changed
+16 -6

No files matched your search

+9 -2
View File
@@ -65,12 +65,16 @@ function _hiraToRomaji(str) {
const JP_RE = /[぀-ヿ㐀-䶿一-鿿＀-￯]/;
const KATA_RE = /[ァ-ヶ]/;
function toRomaji(text) {
if (!text || !_tokenizer || !JP_RE.test(text)) return text || '';
const tokens = _tokenizer.tokenize(text);
const hira = tokens.map(t => {
const r = t.reading;
return (r && r !== '*') ? _kataToHira(r) : t.surface_form;
if (r && r !== '*') return _kataToHira(r);
if (KATA_RE.test(t.surface_form)) return _kataToHira(t.surface_form); // katakana proper noun
return t.surface_form;
}).join('');
return _hiraToRomaji(hira).toLowerCase();
}
@@ -81,7 +85,10 @@ function romajiForStorage(text) {
const tokens = _tokenizer.tokenize(text);
const parts = tokens.map(t => {
const r = t.reading;
if (!r || r === '*') return t.surface_form; // ASCII — keep original
if (!r || r === '*') {
if (KATA_RE.test(t.surface_form)) return _hiraToRomaji(_kataToHira(t.surface_form)); // katakana proper noun
return t.surface_form; // ASCII — keep original
}
return _hiraToRomaji(_kataToHira(r)); // Japanese — convert (lowercase)
});
// Add space between adjacent alphabetic segments (word separation for names/titles)