Skip to content

Commit b341220

Browse files
committed
feat: better examples
1 parent 9dd9674 commit b341220

3 files changed

Lines changed: 54 additions & 16 deletions

File tree

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- [ ] Check SEO
44
- [x] Highlighting tokens when selecting (hovering) and when selected (with current color, which will be the link color)
55
- [x] Make sure instructions are clear and concise, up to date, and complete.
6-
- [ ] Add better examples - with complex links and advanced tokenization.
6+
- [x] Add better examples - with complex links and advanced tokenization.
77
- [x] Improve export card comment
88
- [x] Twitter doesn't show visual preview
99
- [x] Dependency CVE check (`npm audit` / CI)

bitext/src/lib/components/editor/Editor.svelte

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,22 @@
1414
>
1515
Editor
1616
</h2>
17-
<button
18-
type="button"
19-
class="shrink-0 rounded-none border-0 bg-transparent px-2 py-1 text-sm font-medium text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 dark:text-gray-400 dark:hover:bg-gray-800/80 dark:hover:text-gray-100 dark:focus-visible:outline-primary-500"
20-
onclick={() => projectStore.loadExample()}
21-
>
22-
Load example
23-
</button>
17+
<div class="flex flex-wrap items-center gap-1">
18+
<button
19+
type="button"
20+
class="shrink-0 rounded-none border-0 bg-transparent px-2 py-1 text-sm font-medium text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 dark:text-gray-400 dark:hover:bg-gray-800/80 dark:hover:text-gray-100 dark:focus-visible:outline-primary-500"
21+
onclick={() => projectStore.loadExample('simple')}
22+
>
23+
Simple example
24+
</button>
25+
<button
26+
type="button"
27+
class="shrink-0 rounded-none border-0 bg-transparent px-2 py-1 text-sm font-medium text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 dark:text-gray-400 dark:hover:bg-gray-800/80 dark:hover:text-gray-100 dark:focus-visible:outline-primary-500"
28+
onclick={() => projectStore.loadExample('complex')}
29+
>
30+
Complex example
31+
</button>
32+
</div>
2433
</div>
2534
<p class="mb-4 w-full text-base text-gray-600 dark:text-gray-400">
2635
Edit the sentences here. To link words, click a word in the preview below, then click the

bitext/src/lib/state/project.svelte.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,48 @@ class ProjectStore {
128128
};
129129
}
130130

131-
/** Demo alignment for first-time users */
132-
loadExample() {
131+
/**
132+
* Demo alignments for first-time users.
133+
*
134+
* - `simple`: English↔French with one many-to-many pair (English `world` ↔ French `le monde`)
135+
* so newcomers immediately see that a single source word can connect to multiple target words.
136+
* - `complex`: Turkish↔English showcasing agglutination and the token-splitter feature. One Turkish
137+
* "word" (`Ev.im.de.yim` — "I am at my house") is split on `.` into 4 morphemes, and the copula
138+
* `yim` links to both English `I` and `am` (1-to-many). Forces `.` into the split chars if the
139+
* user has removed it, otherwise the example degenerates into a single unsplit token.
140+
*/
141+
loadExample(kind: 'simple' | 'complex' = 'simple') {
142+
const palette = settingsStore.settings.palette;
143+
144+
if (kind === 'simple') {
145+
this.loadSnapshot({
146+
sourceText: 'Hello world',
147+
targetText: 'Bonjour le monde',
148+
sourceGlosses: [],
149+
targetGlosses: [],
150+
links: []
151+
});
152+
this.addAlignment(['s-0'], ['t-0'], palette);
153+
this.addAlignment(['s-1'], ['t-1', 't-2'], palette);
154+
return;
155+
}
156+
157+
if (!settingsStore.settings.tokenSplitChars.includes('.')) {
158+
settingsStore.patch({
159+
tokenSplitChars: settingsStore.settings.tokenSplitChars + '.'
160+
});
161+
}
133162
this.loadSnapshot({
134-
sourceText: 'The cat sleeps',
135-
targetText: 'Le chat dort',
163+
sourceText: 'Ev.im.de.yim',
164+
targetText: 'I am at my house',
136165
sourceGlosses: [],
137166
targetGlosses: [],
138167
links: []
139168
});
140-
const p = settingsStore.settings.palette;
141-
this.addAlignment(['s-0'], ['t-0'], p);
142-
this.addAlignment(['s-1'], ['t-1'], p);
143-
this.addAlignment(['s-2'], ['t-2'], p);
169+
this.addAlignment(['s-0'], ['t-4'], palette);
170+
this.addAlignment(['s-1'], ['t-3'], palette);
171+
this.addAlignment(['s-2'], ['t-2'], palette);
172+
this.addAlignment(['s-3'], ['t-0', 't-1'], palette);
144173
}
145174

146175
loadSnapshot(s: ProjectSnapshotV1) {

0 commit comments

Comments
 (0)