@antelopejs/dms-lang 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -7
- package/dist/pages/workspace.js.map +1 -1
- package/dist/routes/publicLocales.js +1 -1
- package/dist/routes/publicLocales.js.map +1 -1
- package/dist/utils/announce.js +2 -1
- package/dist/utils/announce.js.map +1 -1
- package/dist/utils/body.js +5 -1
- package/dist/utils/body.js.map +1 -1
- package/dist/utils/cache.d.ts +1 -1
- package/dist/utils/cache.js +11 -9
- package/dist/utils/cache.js.map +1 -1
- package/dist/utils/errors.d.ts +5 -1
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/export.d.ts +2 -2
- package/dist/utils/export.js +8 -6
- package/dist/utils/export.js.map +1 -1
- package/dist/utils/guards.d.ts +3 -0
- package/dist/utils/guards.js +15 -0
- package/dist/utils/guards.js.map +1 -0
- package/dist/utils/json.d.ts +16 -10
- package/dist/utils/json.js +48 -20
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/keys.d.ts +7 -6
- package/dist/utils/keys.js +4 -3
- package/dist/utils/keys.js.map +1 -1
- package/dist/utils/message-check.d.ts +2 -1
- package/dist/utils/message-check.js +7 -8
- package/dist/utils/message-check.js.map +1 -1
- package/dist/utils/public-url.d.ts +1 -0
- package/dist/utils/public-url.js +8 -8
- package/dist/utils/public-url.js.map +1 -1
- package/dist/utils/registry.d.ts +2 -2
- package/dist/utils/registry.js +2 -1
- package/dist/utils/registry.js.map +1 -1
- package/dist/utils/resolve.js +2 -1
- package/dist/utils/resolve.js.map +1 -1
- package/dist/utils/review.d.ts +2 -2
- package/dist/utils/review.js +2 -1
- package/dist/utils/review.js.map +1 -1
- package/dist/utils/snippets.js +2 -2
- package/dist/utils/snippets.js.map +1 -1
- package/dist/utils/tree.d.ts +7 -5
- package/dist/utils/tree.js +13 -7
- package/dist/utils/tree.js.map +1 -1
- package/dist/utils/workspaces.d.ts +3 -3
- package/dist/utils/workspaces.js +13 -6
- package/dist/utils/workspaces.js.map +1 -1
- package/dist/utils/write-target.d.ts +2 -1
- package/dist/utils/write-target.js +2 -2
- package/dist/utils/write-target.js.map +1 -1
- package/dist/validation/validate.js +1 -3
- package/dist/validation/validate.js.map +1 -1
- package/dist/validation/workspace.schema.d.ts +4 -3
- package/dist/validation/workspace.schema.js +5 -1
- package/dist/validation/workspace.schema.js.map +1 -1
- package/frontend-vue/app/build/components/KeyEditorDrawer.vue +28 -264
- package/frontend-vue/app/build/components/matrix/MatrixColumns.vue +1 -4
- package/frontend-vue/app/build/composables/useCellSaves.ts +12 -16
- package/frontend-vue/app/build/composables/useMatrixExport.ts +97 -0
- package/frontend-vue/app/build/composables/useQueueSave.ts +8 -3
- package/frontend-vue/app/build/composables/useQueueToasts.ts +7 -4
- package/frontend-vue/app/build/drawer/KeyLanguageField.vue +308 -0
- package/frontend-vue/app/build/drawer/fieldStatus.ts +11 -0
- package/frontend-vue/app/build/matrix/MatrixDoneBanner.vue +36 -0
- package/frontend-vue/app/build/matrix/MatrixFooter.vue +61 -0
- package/frontend-vue/app/build/matrix/MatrixLanguageHeader.vue +52 -0
- package/frontend-vue/app/build/matrix/MatrixNoRows.vue +68 -0
- package/frontend-vue/app/components/LanguageNamespaces.vue +1 -1
- package/frontend-vue/app/components/NamespaceCoverage.vue +1 -1
- package/frontend-vue/app/components/TranslationMatrix.vue +40 -225
- package/frontend-vue/app/components/WorkspaceList.vue +1 -1
- package/frontend-vue/app/composables/translation/useMutationToast.ts +9 -12
- package/frontend-vue/app/composables/translation/useWorkspaceActions.ts +8 -4
- package/frontend-vue/app/composables/translation/useWorkspaceFlat.ts +1 -1
- package/frontend-vue/app/utils/coverage.ts +139 -0
- package/frontend-vue/app/utils/translations.ts +1 -133
- package/frontend-vue/build/backend-boundary.ts +122 -0
- package/frontend-vue/dms.frontend.build.ts +3 -0
- package/frontend-vue/package.json +4 -4
- package/package.json +21 -10
- package/skills/dms-lang/SKILL.md +1 -1
- package/skills/dms-lang/cases.json +47 -0
|
@@ -5,25 +5,17 @@ import {
|
|
|
5
5
|
useElementSize,
|
|
6
6
|
useIntersectionObserver,
|
|
7
7
|
} from '@vueuse/core'
|
|
8
|
-
import UButton from '@nuxt/ui/components/Button.vue'
|
|
9
|
-
import UDropdownMenu from '@nuxt/ui/components/DropdownMenu.vue'
|
|
10
8
|
import { useDmsRouter } from '#dms/frontend-module'
|
|
11
9
|
import type { FlatTranslationRow, LanguageCoverage } from '../types/lang'
|
|
12
10
|
import { useWorkspaceFlatSync } from '../composables/translation/useWorkspaceFlat'
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
languageCoverage,
|
|
16
|
-
stringValue,
|
|
17
|
-
} from '../utils/translations'
|
|
18
|
-
import { exportFileName, translationsCsv } from '../utils/matrixExport'
|
|
19
|
-
import LocaleTile from '../build/components/LocaleTile.vue'
|
|
11
|
+
import { stringValue } from '../utils/translations'
|
|
12
|
+
import { languageCoverage } from '../utils/coverage'
|
|
20
13
|
import PlaceholderText from '../build/components/PlaceholderText.vue'
|
|
21
14
|
import MatrixCell from '../build/components/matrix/MatrixCell.vue'
|
|
22
15
|
import MatrixColumns from '../build/components/matrix/MatrixColumns.vue'
|
|
23
16
|
import MatrixGroupHeader from '../build/components/matrix/MatrixGroupHeader.vue'
|
|
24
17
|
import MatrixKeyCell from '../build/components/matrix/MatrixKeyCell.vue'
|
|
25
18
|
import MatrixToolbar from '../build/components/matrix/MatrixToolbar.vue'
|
|
26
|
-
import ShortcutKbds from '../build/components/ShortcutKbds.vue'
|
|
27
19
|
import {
|
|
28
20
|
useCellSaves,
|
|
29
21
|
type CellAddress,
|
|
@@ -41,6 +33,11 @@ import { useKeyPanel } from '../build/composables/useKeyPanel'
|
|
|
41
33
|
import { useMatrixRows } from '../build/composables/useMatrixRows'
|
|
42
34
|
import { useMatrixView } from '../build/composables/useMatrixView'
|
|
43
35
|
import { useMatrixFilters } from '../build/composables/useMatrixFilters'
|
|
36
|
+
import { useMatrixExport } from '../build/composables/useMatrixExport'
|
|
37
|
+
import MatrixDoneBanner from '../build/matrix/MatrixDoneBanner.vue'
|
|
38
|
+
import MatrixFooter from '../build/matrix/MatrixFooter.vue'
|
|
39
|
+
import MatrixLanguageHeader from '../build/matrix/MatrixLanguageHeader.vue'
|
|
40
|
+
import MatrixNoRows from '../build/matrix/MatrixNoRows.vue'
|
|
44
41
|
import { MATRIX_KEYS, shortcutName } from '../utils/shortcuts'
|
|
45
42
|
|
|
46
43
|
const COMPACT_WIDTH = 768
|
|
@@ -321,71 +318,16 @@ function hideDone() {
|
|
|
321
318
|
pinned.value = new Set()
|
|
322
319
|
}
|
|
323
320
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
locales,
|
|
335
|
-
)
|
|
336
|
-
downloadText(
|
|
337
|
-
exportFileName(selectedWorkspace.value, isView ? locales : undefined),
|
|
338
|
-
content,
|
|
339
|
-
'text/csv;charset=utf-8',
|
|
340
|
-
)
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
function keysLabel(count: number): string {
|
|
344
|
-
return t('dms_lang.matrix.group_keys', { count: formatCount(count) }, count)
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function languagesLabel(count: number): string {
|
|
348
|
-
return t('dms_lang.matrix.languages_counted', { count }, count)
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
usePageHeaderActions(
|
|
352
|
-
() => [
|
|
353
|
-
h(
|
|
354
|
-
UDropdownMenu,
|
|
355
|
-
{
|
|
356
|
-
items: [
|
|
357
|
-
{
|
|
358
|
-
label: t('dms_lang.matrix.export_view', {
|
|
359
|
-
keys: keysLabel(rows.value.length),
|
|
360
|
-
languages: languagesLabel(columnCodes.value.length),
|
|
361
|
-
}),
|
|
362
|
-
icon: 'i-ph-funnel',
|
|
363
|
-
onSelect: () => exportCsv(true),
|
|
364
|
-
},
|
|
365
|
-
{
|
|
366
|
-
label: t('dms_lang.matrix.export_all', {
|
|
367
|
-
keys: keysLabel(flat.value.rows.length),
|
|
368
|
-
languages: languagesLabel(flat.value.locales.length),
|
|
369
|
-
}),
|
|
370
|
-
icon: 'i-ph-table',
|
|
371
|
-
onSelect: () => exportCsv(false),
|
|
372
|
-
},
|
|
373
|
-
],
|
|
374
|
-
content: { align: 'end' },
|
|
375
|
-
},
|
|
376
|
-
() =>
|
|
377
|
-
h(UButton, {
|
|
378
|
-
label: t('dms_lang.matrix.export'),
|
|
379
|
-
icon: 'i-ph-download-simple',
|
|
380
|
-
trailingIcon: 'i-ph-caret-down',
|
|
381
|
-
color: 'neutral',
|
|
382
|
-
variant: 'outline',
|
|
383
|
-
disabled: !isLoaded.value,
|
|
384
|
-
}),
|
|
385
|
-
),
|
|
386
|
-
],
|
|
387
|
-
{ order: -1 },
|
|
388
|
-
)
|
|
321
|
+
useMatrixExport({
|
|
322
|
+
t,
|
|
323
|
+
formatCount,
|
|
324
|
+
flat,
|
|
325
|
+
rows,
|
|
326
|
+
columnCodes,
|
|
327
|
+
order,
|
|
328
|
+
selectedWorkspace,
|
|
329
|
+
isLoaded,
|
|
330
|
+
})
|
|
389
331
|
|
|
390
332
|
watch(
|
|
391
333
|
() => [filters.value, selectedWorkspace.value],
|
|
@@ -469,30 +411,12 @@ onBeforeUnmount(() => {
|
|
|
469
411
|
/>
|
|
470
412
|
</div>
|
|
471
413
|
|
|
472
|
-
<
|
|
414
|
+
<MatrixDoneBanner
|
|
473
415
|
v-if="doneCount"
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
<span class="text-default">
|
|
479
|
-
{{
|
|
480
|
-
$t(
|
|
481
|
-
'dms_lang.matrix.done_banner',
|
|
482
|
-
{ count: formatCount(doneCount) },
|
|
483
|
-
doneCount,
|
|
484
|
-
)
|
|
485
|
-
}}
|
|
486
|
-
</span>
|
|
487
|
-
<UButton
|
|
488
|
-
size="xs"
|
|
489
|
-
color="neutral"
|
|
490
|
-
variant="outline"
|
|
491
|
-
class="ml-auto"
|
|
492
|
-
:label="$t('dms_lang.matrix.hide_done')"
|
|
493
|
-
@click="hideDone"
|
|
494
|
-
/>
|
|
495
|
-
</div>
|
|
416
|
+
:done-count="doneCount"
|
|
417
|
+
:format-count="formatCount"
|
|
418
|
+
:hide-done="hideDone"
|
|
419
|
+
/>
|
|
496
420
|
|
|
497
421
|
<DmsEmptyState
|
|
498
422
|
v-if="hasError && !isLoaded"
|
|
@@ -526,54 +450,14 @@ onBeforeUnmount(() => {
|
|
|
526
450
|
</div>
|
|
527
451
|
</div>
|
|
528
452
|
|
|
529
|
-
<
|
|
453
|
+
<MatrixNoRows
|
|
530
454
|
v-else-if="!rows.length"
|
|
531
|
-
:
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
:
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
: $t('dms_lang.matrix.no_keys')
|
|
538
|
-
"
|
|
539
|
-
:description="
|
|
540
|
-
flat.rows.length
|
|
541
|
-
? $t(
|
|
542
|
-
'dms_lang.matrix.no_match_description',
|
|
543
|
-
{ count: formatCount(flat.rows.length) },
|
|
544
|
-
flat.rows.length,
|
|
545
|
-
)
|
|
546
|
-
: $t('dms_lang.matrix.no_keys_description')
|
|
547
|
-
"
|
|
548
|
-
:actions="[
|
|
549
|
-
...(flat.rows.length
|
|
550
|
-
? [
|
|
551
|
-
{
|
|
552
|
-
label: $t(
|
|
553
|
-
'dms_lang.matrix.show_all',
|
|
554
|
-
{ count: formatCount(flat.rows.length) },
|
|
555
|
-
flat.rows.length,
|
|
556
|
-
),
|
|
557
|
-
color: 'neutral',
|
|
558
|
-
variant: 'outline',
|
|
559
|
-
onClick: resetFilters,
|
|
560
|
-
},
|
|
561
|
-
]
|
|
562
|
-
: []),
|
|
563
|
-
...(canManageKeys
|
|
564
|
-
? [
|
|
565
|
-
{
|
|
566
|
-
label: filters.search
|
|
567
|
-
? $t('dms_lang.matrix.add_named', { key: filters.search })
|
|
568
|
-
: $t('dms_lang.key_add.title'),
|
|
569
|
-
icon: 'i-ph-plus',
|
|
570
|
-
color: 'neutral',
|
|
571
|
-
variant: 'ghost',
|
|
572
|
-
onClick: () => addKey(),
|
|
573
|
-
},
|
|
574
|
-
]
|
|
575
|
-
: []),
|
|
576
|
-
]"
|
|
455
|
+
:flat="flat"
|
|
456
|
+
:filters="filters"
|
|
457
|
+
:can-manage-keys="canManageKeys"
|
|
458
|
+
:format-count="formatCount"
|
|
459
|
+
:reset-filters="resetFilters"
|
|
460
|
+
:add-key="addKey"
|
|
577
461
|
/>
|
|
578
462
|
|
|
579
463
|
<div v-else-if="isCompact && compactColumn">
|
|
@@ -658,42 +542,10 @@ onBeforeUnmount(() => {
|
|
|
658
542
|
:key="column.code"
|
|
659
543
|
class="border-default border-b border-l px-3 pt-2.5 pb-0 text-left font-normal"
|
|
660
544
|
>
|
|
661
|
-
<
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
:is-base="column.isBase"
|
|
666
|
-
:siblings="columnSiblings"
|
|
667
|
-
/>
|
|
668
|
-
<span class="text-highlighted truncate font-medium">
|
|
669
|
-
{{ column.name }}
|
|
670
|
-
</span>
|
|
671
|
-
<DmsStatusPill
|
|
672
|
-
v-if="column.isBase"
|
|
673
|
-
dot="none"
|
|
674
|
-
tone="neutral"
|
|
675
|
-
size="sm"
|
|
676
|
-
:label="$t('dms_lang.common.base')"
|
|
677
|
-
/>
|
|
678
|
-
<span
|
|
679
|
-
v-else
|
|
680
|
-
class="text-dimmed ml-auto font-mono text-[10.5px] whitespace-nowrap"
|
|
681
|
-
>
|
|
682
|
-
{{
|
|
683
|
-
$t(
|
|
684
|
-
'dms_lang.matrix.column_missing',
|
|
685
|
-
{ count: formatCount(column.missing) },
|
|
686
|
-
column.missing,
|
|
687
|
-
)
|
|
688
|
-
}}
|
|
689
|
-
</span>
|
|
690
|
-
</div>
|
|
691
|
-
<DmsMeter
|
|
692
|
-
class="mt-2"
|
|
693
|
-
:value="column.coverage"
|
|
694
|
-
:max="100"
|
|
695
|
-
size="xs"
|
|
696
|
-
:tone="column.isBase ? 'primary' : coverageTone(column.coverage)"
|
|
545
|
+
<MatrixLanguageHeader
|
|
546
|
+
:column="column"
|
|
547
|
+
:column-siblings="columnSiblings"
|
|
548
|
+
:format-count="formatCount"
|
|
697
549
|
/>
|
|
698
550
|
</th>
|
|
699
551
|
</tr>
|
|
@@ -760,50 +612,13 @@ onBeforeUnmount(() => {
|
|
|
760
612
|
<div v-if="view.hasMore.value" ref="sentinel" class="h-8" />
|
|
761
613
|
</div>
|
|
762
614
|
|
|
763
|
-
<
|
|
615
|
+
<MatrixFooter
|
|
764
616
|
v-if="isLoaded"
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
{ count: formatCount(counts.missing) },
|
|
772
|
-
counts.missing,
|
|
773
|
-
)
|
|
774
|
-
}}
|
|
775
|
-
·
|
|
776
|
-
{{
|
|
777
|
-
$t(
|
|
778
|
-
'dms_lang.matrix.footer_cells',
|
|
779
|
-
{ count: formatCount(counts.cells), languages: countedLabel },
|
|
780
|
-
counts.cells,
|
|
781
|
-
)
|
|
782
|
-
}}
|
|
783
|
-
</span>
|
|
784
|
-
<span
|
|
785
|
-
v-if="canEditValues && !isCompact"
|
|
786
|
-
class="ml-auto inline-flex flex-wrap items-center gap-3"
|
|
787
|
-
>
|
|
788
|
-
<span class="inline-flex items-center gap-1">
|
|
789
|
-
<ShortcutKbds :keys="MATRIX_KEYS.saveDown" />
|
|
790
|
-
{{ $t('dms_lang.matrix.shortcut_save_down') }}
|
|
791
|
-
</span>
|
|
792
|
-
<span class="inline-flex items-center gap-1">
|
|
793
|
-
<ShortcutKbds :keys="MATRIX_KEYS.nextCell" />
|
|
794
|
-
{{ $t('dms_lang.matrix.shortcut_next_cell') }}
|
|
795
|
-
</span>
|
|
796
|
-
<span class="inline-flex items-center gap-1">
|
|
797
|
-
<ShortcutKbds :keys="MATRIX_KEYS.nextMissing" />
|
|
798
|
-
/
|
|
799
|
-
<ShortcutKbds :keys="MATRIX_KEYS.previousMissing" />
|
|
800
|
-
{{ $t('dms_lang.matrix.shortcut_next_missing') }}
|
|
801
|
-
</span>
|
|
802
|
-
<span class="inline-flex items-center gap-1">
|
|
803
|
-
<ShortcutKbds :keys="MATRIX_KEYS.openPanel" />
|
|
804
|
-
{{ $t('dms_lang.matrix.open_panel') }}
|
|
805
|
-
</span>
|
|
806
|
-
</span>
|
|
807
|
-
</div>
|
|
617
|
+
:counts="counts"
|
|
618
|
+
:counted-label="countedLabel"
|
|
619
|
+
:can-edit-values="canEditValues"
|
|
620
|
+
:is-compact="isCompact"
|
|
621
|
+
:format-count="formatCount"
|
|
622
|
+
/>
|
|
808
623
|
</DmsCard>
|
|
809
624
|
</template>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import UButton from '@nuxt/ui/components/Button.vue'
|
|
3
3
|
import type { WorkspaceKind, WorkspaceStats } from '../types/lang'
|
|
4
|
-
import { COVERAGE_TEXT_CLASSES, coverageTone } from '../utils/
|
|
4
|
+
import { COVERAGE_TEXT_CLASSES, coverageTone } from '../utils/coverage'
|
|
5
5
|
import {
|
|
6
6
|
PUBLIC_URL_METHOD,
|
|
7
7
|
matchesWorkspace,
|
|
@@ -7,7 +7,8 @@ interface ErrorBody {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
interface MutationToastOptions {
|
|
10
|
-
|
|
10
|
+
fallbackKey?: string
|
|
11
|
+
params?: Record<string, string | number | boolean>
|
|
11
12
|
retry?: () => void
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -24,25 +25,21 @@ export function serverErrorCode(error: unknown): string {
|
|
|
24
25
|
* `$dms_lang.errors.*` key the server answers, with a Retry action.
|
|
25
26
|
*/
|
|
26
27
|
export const useMutationToast = () => {
|
|
27
|
-
const {
|
|
28
|
-
const
|
|
29
|
-
const translate = (key: string, params: Record<string, unknown>) =>
|
|
30
|
-
t(key, params)
|
|
28
|
+
const { presentError, resolveError } = useApiErrorPresenter()
|
|
29
|
+
const fallbackKey = 'error.500.description'
|
|
31
30
|
|
|
32
31
|
/** The server's message, translated; the generic server error otherwise. */
|
|
33
32
|
function errorMessage(error: unknown): string {
|
|
34
|
-
return
|
|
33
|
+
return resolveError(error, { fallbackKey })?.message ?? ''
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
function reportFailure(error: unknown, options: MutationToastOptions = {}) {
|
|
38
37
|
const actions = options.retry
|
|
39
|
-
? [{
|
|
38
|
+
? [{ labelKey: 'dms_lang.actions.retry', onSelect: options.retry }]
|
|
40
39
|
: undefined
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
color: 'error',
|
|
45
|
-
icon: 'i-ph-warning-circle',
|
|
40
|
+
presentError(error, {
|
|
41
|
+
fallbackKey: options.fallbackKey ?? fallbackKey,
|
|
42
|
+
params: options.params,
|
|
46
43
|
actions,
|
|
47
44
|
})
|
|
48
45
|
}
|
|
@@ -148,8 +148,9 @@ async function updateDetails(
|
|
|
148
148
|
): Promise<boolean> {
|
|
149
149
|
const { workspaces } = context
|
|
150
150
|
return context.failures.tryMutate(
|
|
151
|
-
async () =>
|
|
152
|
-
|
|
151
|
+
async () =>
|
|
152
|
+
workspaces.patchSummary(await workspaces.updateWorkspace(id, change)),
|
|
153
|
+
{ fallbackKey: 'dms_lang.workspace_details.save_failed' },
|
|
153
154
|
)
|
|
154
155
|
}
|
|
155
156
|
|
|
@@ -158,10 +159,13 @@ async function downloadBackup(
|
|
|
158
159
|
workspace: string,
|
|
159
160
|
): Promise<void> {
|
|
160
161
|
try {
|
|
161
|
-
downloadJson(
|
|
162
|
+
downloadJson(
|
|
163
|
+
`${workspace}.json`,
|
|
164
|
+
await context.workspaces.fetchBackup(workspace),
|
|
165
|
+
)
|
|
162
166
|
} catch (error) {
|
|
163
167
|
context.failures.reportFailure(error, {
|
|
164
|
-
|
|
168
|
+
fallbackKey: 'dms_lang.errors.export_failed',
|
|
165
169
|
})
|
|
166
170
|
}
|
|
167
171
|
}
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
FlatTranslations,
|
|
7
7
|
KeyRowResponse,
|
|
8
8
|
} from '../../types/lang'
|
|
9
|
-
import { EMPTY_FLAT, withRow } from '../../utils/
|
|
9
|
+
import { EMPTY_FLAT, withRow } from '../../utils/coverage'
|
|
10
10
|
|
|
11
11
|
/** Realtime topic the backend publishes on after each write. */
|
|
12
12
|
export const LANG_REALTIME_TOPIC = 'dms-lang.translations'
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FlatTranslationRow,
|
|
3
|
+
FlatTranslations,
|
|
4
|
+
LanguageCoverage,
|
|
5
|
+
NamespaceCoverage,
|
|
6
|
+
} from '../types/lang'
|
|
7
|
+
import {
|
|
8
|
+
isRowValueMissing,
|
|
9
|
+
NAMESPACE_SEPARATOR,
|
|
10
|
+
namespaceOf,
|
|
11
|
+
} from './translations'
|
|
12
|
+
|
|
13
|
+
const FULL_COVERAGE = 100
|
|
14
|
+
|
|
15
|
+
export const HIGH_COVERAGE = 90
|
|
16
|
+
export const MID_COVERAGE = 60
|
|
17
|
+
|
|
18
|
+
export const EMPTY_FLAT: FlatTranslations = {
|
|
19
|
+
defaultLocale: '',
|
|
20
|
+
locales: [],
|
|
21
|
+
rows: [],
|
|
22
|
+
localeProgress: {},
|
|
23
|
+
localeMissing: {},
|
|
24
|
+
totalKeys: 0,
|
|
25
|
+
baseMissing: 0,
|
|
26
|
+
incompleteKeys: 0,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The share of `total` that is translated, in whole percent rounded down, so
|
|
31
|
+
* that one missing text keeps it under 100 (200 of 201 reads 99). Nothing to
|
|
32
|
+
* translate reads 100. The rule the server rounds every coverage with.
|
|
33
|
+
*/
|
|
34
|
+
export function coveragePercent(translated: number, total: number): number {
|
|
35
|
+
if (total <= 0) return FULL_COVERAGE
|
|
36
|
+
return Math.floor((Math.max(translated, 0) * FULL_COVERAGE) / total)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function coverageTone(
|
|
40
|
+
coverage: number,
|
|
41
|
+
): 'success' | 'warning' | 'error' {
|
|
42
|
+
if (coverage >= HIGH_COVERAGE) return 'success'
|
|
43
|
+
if (coverage >= MID_COVERAGE) return 'warning'
|
|
44
|
+
return 'error'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function translatedCount(
|
|
48
|
+
rows: FlatTranslationRow[],
|
|
49
|
+
locale: string,
|
|
50
|
+
): number {
|
|
51
|
+
return rows.filter((row) => !isRowValueMissing(row, locale)).length
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The coverage of each language, from the figures the server keeps. */
|
|
55
|
+
export function languageCoverage(
|
|
56
|
+
flat: FlatTranslations,
|
|
57
|
+
nameOf: (code: string) => string,
|
|
58
|
+
): LanguageCoverage[] {
|
|
59
|
+
return flat.locales.map((code) => {
|
|
60
|
+
const missing = flat.localeMissing[code] ?? 0
|
|
61
|
+
const translated = flat.totalKeys - missing
|
|
62
|
+
return {
|
|
63
|
+
code,
|
|
64
|
+
name: nameOf(code),
|
|
65
|
+
isBase: code === flat.defaultLocale,
|
|
66
|
+
coverage: coveragePercent(translated, flat.totalKeys),
|
|
67
|
+
translated,
|
|
68
|
+
missing,
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function groupByNamespace(
|
|
74
|
+
rows: FlatTranslationRow[],
|
|
75
|
+
): Map<string, FlatTranslationRow[]> {
|
|
76
|
+
const groups = new Map<string, FlatTranslationRow[]>()
|
|
77
|
+
for (const row of rows) {
|
|
78
|
+
const namespace = namespaceOf(row.key)
|
|
79
|
+
const group = groups.get(namespace)
|
|
80
|
+
if (group) group.push(row)
|
|
81
|
+
else groups.set(namespace, [row])
|
|
82
|
+
}
|
|
83
|
+
return groups
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function namespaceCoverage(
|
|
87
|
+
rows: FlatTranslationRow[],
|
|
88
|
+
locales: string[],
|
|
89
|
+
): NamespaceCoverage[] {
|
|
90
|
+
return [...groupByNamespace(rows)].map(([namespace, group]) => {
|
|
91
|
+
const coverage: Record<string, number> = {}
|
|
92
|
+
const missing: Record<string, number> = {}
|
|
93
|
+
for (const locale of locales) {
|
|
94
|
+
const translated = translatedCount(group, locale)
|
|
95
|
+
coverage[locale] = coveragePercent(translated, group.length)
|
|
96
|
+
missing[locale] = group.length - translated
|
|
97
|
+
}
|
|
98
|
+
return { namespace, keys: group.length, coverage, missing }
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Where a key put back before `before` (a sibling key or namespace) goes: the end when none is there. */
|
|
103
|
+
function insertionIndex(rows: FlatTranslationRow[], before?: string): number {
|
|
104
|
+
if (before === undefined) return rows.length
|
|
105
|
+
const index = rows.findIndex(
|
|
106
|
+
(entry) =>
|
|
107
|
+
entry.key === before ||
|
|
108
|
+
entry.key.startsWith(`${before}${NAMESPACE_SEPARATOR}`),
|
|
109
|
+
)
|
|
110
|
+
return index < 0 ? rows.length : index
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The translations with one row put in place: replaced, added (before the
|
|
115
|
+
* `before` sibling, else at the end), or taken out when there is none (the
|
|
116
|
+
* key is gone). The other rows are kept as they are.
|
|
117
|
+
*/
|
|
118
|
+
export function withRow(
|
|
119
|
+
flat: FlatTranslations,
|
|
120
|
+
key: string,
|
|
121
|
+
row: FlatTranslationRow | undefined,
|
|
122
|
+
before?: string,
|
|
123
|
+
): FlatTranslations {
|
|
124
|
+
const index = flat.rows.findIndex((entry) => entry.key === key)
|
|
125
|
+
const rows = [...flat.rows]
|
|
126
|
+
if (row && index >= 0) rows[index] = row
|
|
127
|
+
else if (row) rows.splice(insertionIndex(rows, before), 0, row)
|
|
128
|
+
else if (index >= 0) rows.splice(index, 1)
|
|
129
|
+
return { ...flat, rows }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export const COVERAGE_TEXT_CLASSES: Record<
|
|
133
|
+
'success' | 'warning' | 'error',
|
|
134
|
+
string
|
|
135
|
+
> = {
|
|
136
|
+
success: 'text-success',
|
|
137
|
+
warning: 'text-warning',
|
|
138
|
+
error: 'text-error',
|
|
139
|
+
}
|