feat(learn): furigana and pinyin over hints, from Tatoeba's transcriptions

The curator puts Tatoeba's readings on a dictionary's examples by their
Tatoeba ID (`withTatoebaReadings`, `curate readings`, and in `update`):
furigana over JMdict's Japanese from its jpn transcriptions, pinyin with
tone marks over Chinese from its cmn ones, each word over as many Han
characters as it has syllables. An example gets `ruby`, `[start, end,
reading]` each, and `rubyUnreviewed` where no one wrote or checked them
(MeCab's furigana, the automatic pinyin). JMdict's conversion goes to 3,
so instances convert again at once.

A word's example hints carry them as ruby marks, the word still in bold.
The hints sheet shows them from the start with a switch above
(Furigana, Pinyin), kept on the device (`DeviceSettings.hintReadings`),
and below a hint whose readings no one reviewed says so.

Whats-New: Example sentences in a word's hints now show furigana or pinyin over them, with a switch to hide them.
Whats-New-De: Beispielsätze in den Hinweisen eines Worts zeigen jetzt Furigana oder Pinyin darüber, mit einem Schalter zum Ausblenden.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-11-10 20:28:30 +01:00
commit 3257905536
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -2,6 +2,7 @@ import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:halkyon_editor/halkyon_editor.dart';
import 'package:halkyon_learn_flutter/src/core/editor/ruby_marks.dart';
import 'package:halkyon_learn_flutter/src/feature/card/data/card_repository.dart';
import 'package:halkyon_learn_flutter/src/feature/card/model/card.dart';
import 'package:halkyon_learn_flutter/src/feature/card/model/card_content.dart';
@ -324,6 +325,53 @@ void main() {
{'insert': 'た。'},
]);
});
test("an example's readings from Tatoeba go over its sentence, the word "
'still in bold; those no one reviewed are marked so', () {
final word = DictionaryWord.fromEntry(
ref: (source: 'jmdict', id: '1358280'),
headword: '食べる',
reading: 'たべる',
labels: const [],
entry:
'{"senses":[{"glosses":["to eat"],"examples":['
'{"text":"食べ","ja":"果物を食べた。","en":"I ate fruit.",'
'"ruby":[[0,1,"くだ"],[1,2,"もの"],[3,4,"た"]],'
'"rubyUnreviewed":true},'
'{"text":"食べ","ja":"食べた。","ruby":[[0,1,"た"]]}]}]}',
);
final [unreviewed, reviewed] = word.card.hints;
final document = unreviewed.editorJson['document']! as Map;
final [sentence, english] = document['children']! as List;
expect(((sentence as Map)['data']! as Map)['delta'], [
{
'insert': '果',
'attributes': {'ruby': 'くだ'},
},
{
'insert': '物',
'attributes': {'ruby': 'もの'},
},
{'insert': 'を'},
{
'insert': '食',
'attributes': {'bold': true, 'ruby': 'た'},
},
{
'insert': 'べ',
'attributes': {'bold': true},
},
{'insert': 'た。'},
]);
expect(readingsUnreviewed(unreviewed), isTrue);
expect(((english as Map)['data']! as Map)['delta'], [
{'insert': 'I ate fruit.'},
]);
expect(readingsUnreviewed(reviewed), isFalse);
expect(hasReadings(reviewed), isTrue);
expect(hasReadings(RichContent.plain('食べた。')), isFalse);
});
});
group('the repository', () {