Skip to content

Commit 1af5702

Browse files
committed
feat: inconsistency detectors
1 parent 76a1e6f commit 1af5702

File tree

12 files changed

+205
-52
lines changed

12 files changed

+205
-52
lines changed

app/app.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,12 @@ onMounted(() => {
111111
) {
112112
uiStore.translations = parseTranslationFile(uiStore.translationsString);
113113
}
114+
115+
if (
116+
Object.keys(uiStore.nwpTranslations ?? {}).length === 0 &&
117+
!!uiStore.nwpString
118+
) {
119+
uiStore.nwpTranslations = parseTranslationFile(uiStore.nwpString);
120+
}
114121
});
115122
</script>

app/components/TranslationForm.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
<UForm
33
:state="state"
44
:schema="schema"
5-
class="flex flex-col gap-4"
5+
class="flex flex-col gap-4 justify-between"
66
@submit="onSubmit"
77
>
88
<UFormField
9+
v-if="original && translationKey"
910
:label="original ? 'Origineel' : 'Key'"
1011
:description="original ? translationKey : undefined"
1112
>
@@ -17,7 +18,13 @@
1718
:model-value="original || translationKey"
1819
/>
1920
</UFormField>
20-
<UFormField label="Vertaling" name="translation">
21+
<UFormField
22+
label="Vertaling"
23+
name="translation"
24+
:description="
25+
original && translationKey ? undefined : original || translationKey
26+
"
27+
>
2128
<UTextarea
2229
v-model="state.translation"
2330
:rows="1"

app/pages/translate/index.vue

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@
1616
<UPageGrid>
1717
<UPageCard v-for="(card, index) in cards" :key="index" v-bind="card" />
1818
</UPageGrid>
19+
<div
20+
v-if="uiStore.uiInconsistencies.length > 0"
21+
class="flex flex-col gap-8"
22+
>
23+
<p>{{ uiStore.uiInconsistencies.length }} UI inconsistentie(s):</p>
24+
<UAlert
25+
v-for="term in uiStore.uiInconsistencies"
26+
:key="term.key"
27+
color="warning"
28+
variant="subtle"
29+
:title="`Inconsistentie voor: ${term.key}`"
30+
:description="`NWS: ${term.nws} • NWP: ${term.nwp}`"
31+
:actions="[
32+
{
33+
label: 'Open NWS term',
34+
variant: 'link',
35+
to: `/translate/nws/${term.key}`,
36+
},
37+
{
38+
label: 'Open NWP term',
39+
variant: 'link',
40+
to: `/translate/nwp/${term.key}`,
41+
},
42+
]"
43+
/>
44+
</div>
1945
</UPageBody>
2046
</UPage>
2147
</template>
@@ -27,7 +53,7 @@ const translationStore = useTranslationStore();
2753
const cards = computed((): PageCardProps[] => {
2854
return [
2955
{
30-
description: `${uiStore.keys.length} records.`,
56+
description: `${uiStore.keys.length} records. ${uiStore.inconsistentNWS.length > 0 ? `${uiStore.inconsistentNWS.flatMap((i) => i.others).length} inconsistentie(s).` : ""}`,
3157
icon: "i-lucide:monitor",
3258
title: "NWS UI",
3359
to: "/translate/nws",
@@ -57,7 +83,7 @@ const cards = computed((): PageCardProps[] => {
5783
to: "/translate/songs",
5884
},
5985
{
60-
description: `${translationStore.originals.tips?.length ?? 0} records.`,
86+
description: `${translationStore.originals.tips?.length ?? 0} records. ${translationStore.inconsistentTips.length > 0 ? `${translationStore.inconsistentTips.length} inconsistentie(s).` : ""}`,
6187
icon: "i-lucide:lightbulb",
6288
title: "Tips",
6389
to: "/translate/tips",

app/pages/translate/literature/index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<UPageGrid>
2121
<LiteratureForm
2222
v-for="item in translationStore.originals.literature"
23+
:id="`literature-${item.id}`"
2324
:key="item.id"
2425
:item="item"
2526
/>

app/pages/translate/nwp/[key].vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
<template>
2-
<NWPTranslationForm :translation-key="key" />
2+
<div>
3+
<div v-if="keys.length < 3" class="flex flex-col gap-8">
4+
<NWPTranslationForm v-for="k in keys" :key="k" :translation-key="k" />
5+
</div>
6+
<UPageGrid v-else>
7+
<NWPTranslationForm v-for="k in keys" :key="k" :translation-key="k" />
8+
</UPageGrid>
9+
</div>
310
</template>
411
<script setup lang="ts">
512
const key = useRouteParams<string>("key");
13+
const keys = computed(() => key.value.split(","));
614
</script>

app/pages/translate/nws/[key].vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
<template>
2-
<NWSTranslationForm :translation-key="key" />
2+
<div>
3+
<div v-if="keys.length < 3" class="flex flex-col gap-8">
4+
<NWSTranslationForm v-for="k in keys" :key="k" :translation-key="k" />
5+
</div>
6+
<UPageGrid v-else>
7+
<NWSTranslationForm v-for="k in keys" :key="k" :translation-key="k" />
8+
</UPageGrid>
9+
</div>
310
</template>
411
<script setup lang="ts">
512
const key = useRouteParams<string>("key");
13+
const keys = computed(() => key.value.split(","));
614
</script>

app/pages/translate/nws/index.vue

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
11
<template>
2-
<p>Kies een key uit de lijst om te vertalen.</p>
2+
<div class="flex flex-col gap-4">
3+
<p>Kies een key uit de lijst om te vertalen.</p>
4+
<UAlert
5+
v-for="i in uiStore.inconsistentNWS"
6+
:key="i.key"
7+
color="warning"
8+
variant="subtle"
9+
:title="`Inconsistentie in de term: ${i.original} = ${i.translation}`"
10+
:description="
11+
i.others.length === 1
12+
? i.others[0]!.value
13+
: `${i.others.length} inconsistente vertalingen`
14+
"
15+
:actions="[
16+
{
17+
label: 'Open termen naast elkaar',
18+
to: `/translate/nws/${i.key},${i.others.map((o) => o.key).join(',')}`,
19+
},
20+
...(i.others.length === 1
21+
? ([
22+
{
23+
label: 'Markeer als consistent',
24+
onClick: () => {
25+
uiStore.markNWSConsistent(i.key, i.others[0]!.key);
26+
},
27+
color: 'neutral',
28+
},
29+
] as const)
30+
: []),
31+
]"
32+
/>
33+
</div>
334
</template>
35+
<script setup lang="ts">
36+
const uiStore = useUIStore();
37+
</script>

app/pages/translate/outlines/index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<UPageGrid>
2121
<OutlineForm
2222
v-for="outline in translationStore.originals.outlines"
23+
:id="`outline-${outline.number}`"
2324
:key="outline.number"
2425
:outline="outline"
2526
/>

app/pages/translate/songs/index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<UPageGrid>
2727
<SongForm
2828
v-for="song in translationStore.originals.songs"
29+
:id="`song-${song.number}`"
2930
:key="song.number"
3031
:song="song"
3132
/>

app/pages/translate/tips/index.vue

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
/>
88

99
<UPageBody>
10-
<template v-if="inconsistentHeadings.length">
10+
<template v-if="translationStore.inconsistentTips.length">
1111
<UAlert
12-
v-for="h in inconsistentHeadings"
12+
v-for="h in translationStore.inconsistentTips"
1313
:key="h.heading"
1414
variant="soft"
1515
color="warning"
@@ -19,7 +19,7 @@
1919
h.translations.map((t) => ({
2020
label: t,
2121
onClick: () => {
22-
fixInconsistentHeading(t, h.tips);
22+
fixInconsistentTips(t, h.tips);
2323
},
2424
}))
2525
"
@@ -35,6 +35,7 @@
3535
<template v-else>
3636
<TipForm
3737
v-for="(tip, i) in translationStore.originals.tips"
38+
:id="`tip-${i}`"
3839
:key="i"
3940
:index="i"
4041
:tip="tip"
@@ -46,50 +47,14 @@
4647
<script setup lang="ts">
4748
const translationStore = useTranslationStore();
4849
49-
const inconsistentHeadings = computed(() => {
50-
if (!translationStore.originals.tips?.length) return [];
51-
const headings: Record<string, { index: number; translation: string }[]> = {};
52-
53-
translationStore.originals.tips.forEach((tip, index) => {
54-
if (headings[tip.heading]) {
55-
headings[tip.heading]!.push({
56-
index,
57-
translation: translationStore.translations.tips?.[index]?.heading ?? "",
58-
});
59-
} else {
60-
headings[tip.heading] = [
61-
{
62-
index,
63-
translation:
64-
translationStore.translations.tips?.[index]?.heading ?? "",
65-
},
66-
];
67-
}
68-
});
69-
return Object.entries(headings)
70-
.filter(
71-
([, tips]) =>
72-
tips.length > 1 &&
73-
tips.some((t) => t.translation !== tips[0]?.translation),
74-
)
75-
.map(([heading, tips]) => ({
76-
heading,
77-
tips: tips,
78-
translations: [...new Set(tips.map((t) => t.translation))],
79-
}));
80-
});
81-
8250
const loading = ref(false);
8351
84-
const fixInconsistentHeading = async (
52+
const fixInconsistentTips = async (
8553
heading: string,
8654
tips: { index: number }[],
8755
) => {
8856
loading.value = true;
89-
tips.forEach((t) => {
90-
translationStore.translations.tips![t.index]!.heading = heading;
91-
});
92-
await new Promise((resolve) => setTimeout(resolve, 100));
57+
await translationStore.fixInconsistentTips(heading, tips);
9358
loading.value = false;
9459
};
9560

0 commit comments

Comments
 (0)