@antelopejs/dms-lang 0.0.1

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.
Files changed (76) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +62 -0
  3. package/dist/index.d.ts +7 -0
  4. package/dist/index.js +46 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/pages/index.d.ts +4 -0
  7. package/dist/pages/index.js +21 -0
  8. package/dist/pages/index.js.map +1 -0
  9. package/dist/pages/module.d.ts +1 -0
  10. package/dist/pages/module.js +12 -0
  11. package/dist/pages/module.js.map +1 -0
  12. package/dist/pages/overview.d.ts +9 -0
  13. package/dist/pages/overview.js +29 -0
  14. package/dist/pages/overview.js.map +1 -0
  15. package/dist/pages/translations.d.ts +9 -0
  16. package/dist/pages/translations.js +29 -0
  17. package/dist/pages/translations.js.map +1 -0
  18. package/dist/routes/index.d.ts +2 -0
  19. package/dist/routes/index.js +19 -0
  20. package/dist/routes/index.js.map +1 -0
  21. package/dist/routes/publicLocales.d.ts +6 -0
  22. package/dist/routes/publicLocales.js +46 -0
  23. package/dist/routes/publicLocales.js.map +1 -0
  24. package/dist/routes/translations.d.ts +72 -0
  25. package/dist/routes/translations.js +213 -0
  26. package/dist/routes/translations.js.map +1 -0
  27. package/dist/utils/config.d.ts +6 -0
  28. package/dist/utils/config.js +15 -0
  29. package/dist/utils/config.js.map +1 -0
  30. package/dist/utils/json.d.ts +5 -0
  31. package/dist/utils/json.js +86 -0
  32. package/dist/utils/json.js.map +1 -0
  33. package/dist/utils/locale-discovery.d.ts +3 -0
  34. package/dist/utils/locale-discovery.js +39 -0
  35. package/dist/utils/locale-discovery.js.map +1 -0
  36. package/dist/utils/mutations.d.ts +3 -0
  37. package/dist/utils/mutations.js +35 -0
  38. package/dist/utils/mutations.js.map +1 -0
  39. package/dist/utils/own.d.ts +3 -0
  40. package/dist/utils/own.js +64 -0
  41. package/dist/utils/own.js.map +1 -0
  42. package/dist/utils/registry.d.ts +11 -0
  43. package/dist/utils/registry.js +43 -0
  44. package/dist/utils/registry.js.map +1 -0
  45. package/dist/utils/resolve.d.ts +24 -0
  46. package/dist/utils/resolve.js +203 -0
  47. package/dist/utils/resolve.js.map +1 -0
  48. package/dist/utils/tree.d.ts +24 -0
  49. package/dist/utils/tree.js +161 -0
  50. package/dist/utils/tree.js.map +1 -0
  51. package/dist/utils/workspaces.d.ts +38 -0
  52. package/dist/utils/workspaces.js +236 -0
  53. package/dist/utils/workspaces.js.map +1 -0
  54. package/frontend-vue/.editorconfig +12 -0
  55. package/frontend-vue/.prettierrc +10 -0
  56. package/frontend-vue/app/build/components/pages/lang/TranslationMatrix.vue +284 -0
  57. package/frontend-vue/app/components/LanguageAddModal.vue +78 -0
  58. package/frontend-vue/app/components/WorkspaceEndpoint.vue +29 -0
  59. package/frontend-vue/app/components/WorkspaceSelector.vue +180 -0
  60. package/frontend-vue/app/components/WorkspaceStatus.vue +24 -0
  61. package/frontend-vue/app/composables/translation/useI18nWorkspaces.ts +177 -0
  62. package/frontend-vue/app/composables/translation/useLanguageCatalog.ts +90 -0
  63. package/frontend-vue/app/composables/translation/useLocaleMeta.ts +18 -0
  64. package/frontend-vue/app/composables/translation/useMutationToast.ts +30 -0
  65. package/frontend-vue/app/composables/translation/useTranslationProgress.ts +73 -0
  66. package/frontend-vue/app/composables/translation/useWorkspaceContext.ts +27 -0
  67. package/frontend-vue/app/composables/translation/useWorkspaceFlat.ts +81 -0
  68. package/frontend-vue/app/custom-pages/lang/overview.vue +397 -0
  69. package/frontend-vue/app/custom-pages/lang/translations.vue +498 -0
  70. package/frontend-vue/app/plugins/workspace-sidebar-widget.ts +12 -0
  71. package/frontend-vue/dms.frontend.ts +42 -0
  72. package/frontend-vue/eslint.config.mjs +50 -0
  73. package/frontend-vue/i18n/locales/lang-en-GB.json +80 -0
  74. package/frontend-vue/i18n/locales/lang-fr-FR.json +80 -0
  75. package/frontend-vue/package.json +37 -0
  76. package/package.json +76 -0
@@ -0,0 +1,180 @@
1
+ <script setup lang="ts">
2
+ import type { DropdownMenuItem } from "@nuxt/ui";
3
+ import type { WorkspaceSummary } from "../composables/translation/useI18nWorkspaces";
4
+ import type { LanguageCatalogEntry } from "../composables/translation/useLanguageCatalog";
5
+
6
+ interface WorkspaceForm extends LanguageCatalogEntry {
7
+ id: string;
8
+ }
9
+
10
+ interface Props {
11
+ collapsed?: boolean;
12
+ }
13
+
14
+ const EMPTY_FORM: WorkspaceForm = { id: "", code: "", name: "", flag: "" };
15
+
16
+ defineProps<Props>();
17
+
18
+ const { t } = useI18n();
19
+ const { tryMutate } = useMutationToast();
20
+ const { current } = useWorkspaceContext();
21
+ const { items: languageItems, resolveLanguage } = useLanguageCatalog();
22
+ const {
23
+ workspaces,
24
+ editable,
25
+ selectedWorkspace,
26
+ isLoading,
27
+ fetchWorkspaces,
28
+ canUseWorkspaceId,
29
+ createWorkspace,
30
+ } = useI18nWorkspaces();
31
+
32
+ const currentIcon = computed(() =>
33
+ current.value?.editable ? "i-lucide-pencil" : "i-lucide-lock",
34
+ );
35
+
36
+ const subtitle = computed(() =>
37
+ t("dms_lang.sidebar.languages_count", current.value?.locales.length ?? 0),
38
+ );
39
+
40
+ const menuItems = computed<DropdownMenuItem[][]>(() => {
41
+ const groups: DropdownMenuItem[][] = [
42
+ workspaces.value.map((workspace: WorkspaceSummary) => ({
43
+ label: workspace.id,
44
+ icon: workspace.editable ? "i-lucide-pencil" : "i-lucide-lock",
45
+ type: "checkbox" as const,
46
+ checked: workspace.id === selectedWorkspace.value,
47
+ onSelect: () => {
48
+ selectedWorkspace.value = workspace.id;
49
+ },
50
+ })),
51
+ ];
52
+ if (editable.value) {
53
+ groups.push([
54
+ {
55
+ label: t("dms_lang.translation.ws_new"),
56
+ icon: "i-lucide-plus",
57
+ onSelect: openCreateWorkspace,
58
+ },
59
+ ]);
60
+ }
61
+ return groups;
62
+ });
63
+
64
+ const createOpen = ref(false);
65
+ const createForm = ref<WorkspaceForm>({ ...EMPTY_FORM });
66
+ const isSubmitting = ref(false);
67
+
68
+ const normalizedId = computed(() => normalizeWorkspaceId(createForm.value.id));
69
+ const canCreate = computed(
70
+ () => canUseWorkspaceId(normalizedId.value) && Boolean(createForm.value.code),
71
+ );
72
+
73
+ function openCreateWorkspace() {
74
+ createForm.value = { ...EMPTY_FORM };
75
+ createOpen.value = true;
76
+ }
77
+
78
+ async function submitCreateWorkspace() {
79
+ if (isSubmitting.value || !canCreate.value) return;
80
+ const id = normalizedId.value;
81
+ const { code, name, flag } = createForm.value;
82
+ isSubmitting.value = true;
83
+ const ok = await tryMutate(() =>
84
+ createWorkspace(id, { code, name: name || undefined, flag: flag || undefined }),
85
+ );
86
+ isSubmitting.value = false;
87
+ if (!ok) return;
88
+ createOpen.value = false;
89
+ const list = await fetchWorkspaces();
90
+ if (list.some((workspace) => workspace.id === id)) {
91
+ selectedWorkspace.value = id;
92
+ }
93
+ }
94
+
95
+ onMounted(() => {
96
+ if (workspaces.value.length === 0) fetchWorkspaces();
97
+ });
98
+ </script>
99
+
100
+ <template>
101
+ <UDropdownMenu
102
+ v-if="workspaces.length > 0"
103
+ :items="menuItems"
104
+ :content="{ align: 'start' }"
105
+ :ui="{ content: 'w-56' }"
106
+ >
107
+ <button
108
+ type="button"
109
+ class="border-default hover:bg-elevated/50 flex w-full items-center gap-2.5 rounded-lg border p-2 text-left transition-colors"
110
+ :class="{ 'justify-center border-transparent p-1.5': collapsed }"
111
+ :aria-label="collapsed ? t('dms_lang.sidebar.workspace') : undefined"
112
+ >
113
+ <span
114
+ class="bg-primary/10 ring-primary/20 grid size-8 shrink-0 place-items-center rounded-md ring"
115
+ >
116
+ <UIcon :name="currentIcon" class="text-primary size-4" />
117
+ </span>
118
+ <template v-if="!collapsed">
119
+ <span class="min-w-0 flex-1">
120
+ <span class="text-highlighted block truncate text-sm font-semibold">
121
+ {{ selectedWorkspace || t("dms_lang.sidebar.workspace") }}
122
+ </span>
123
+ <span class="text-muted block truncate text-xs">{{ subtitle }}</span>
124
+ </span>
125
+ <UIcon
126
+ name="i-lucide-chevrons-up-down"
127
+ class="text-muted size-4 shrink-0"
128
+ />
129
+ </template>
130
+ </button>
131
+ </UDropdownMenu>
132
+ <USkeleton
133
+ v-else-if="isLoading"
134
+ class="rounded-lg"
135
+ :class="collapsed ? 'mx-auto size-11' : 'h-12 w-full'"
136
+ />
137
+
138
+ <UModal v-model:open="createOpen" :title="$t('dms_lang.translation.ws_new')">
139
+ <template #body>
140
+ <div class="space-y-4">
141
+ <UFormField
142
+ :label="$t('dms_lang.translation.ws_workspace_name')"
143
+ :help="$t('dms_lang.translation.ws_workspace_name_help')"
144
+ >
145
+ <UInput v-model="createForm.id" class="w-full" />
146
+ </UFormField>
147
+ <UFormField :label="$t('dms_lang.translation.ws_default_locale')">
148
+ <USelectMenu
149
+ :model-value="createForm.code"
150
+ :items="languageItems"
151
+ value-key="value"
152
+ label-key="label"
153
+ searchable
154
+ class="w-full"
155
+ :placeholder="$t('dms_lang.translation.ws_language_select')"
156
+ @update:model-value="
157
+ createForm = { ...resolveLanguage($event), id: createForm.id }
158
+ "
159
+ />
160
+ </UFormField>
161
+ </div>
162
+ </template>
163
+ <template #footer>
164
+ <div class="flex w-full justify-end gap-2">
165
+ <UButton
166
+ color="neutral"
167
+ variant="ghost"
168
+ :label="$t('dms_lang.translation.ws_cancel')"
169
+ @click="createOpen = false"
170
+ />
171
+ <UButton
172
+ :label="$t('dms_lang.translation.ws_create')"
173
+ :loading="isSubmitting"
174
+ :disabled="!canCreate"
175
+ @click="submitCreateWorkspace"
176
+ />
177
+ </div>
178
+ </template>
179
+ </UModal>
180
+ </template>
@@ -0,0 +1,24 @@
1
+ <script setup lang="ts">
2
+ const { isDefault, isModules, isEditable } = useWorkspaceContext();
3
+ </script>
4
+
5
+ <template>
6
+ <UBadge
7
+ :color="isEditable ? 'primary' : 'warning'"
8
+ variant="subtle"
9
+ :icon="isEditable ? 'i-lucide-pencil' : 'i-lucide-lock'"
10
+ >
11
+ {{
12
+ isEditable
13
+ ? $t("dms_lang.translation.ws_editable")
14
+ : $t("dms_lang.translation.ws_read_only")
15
+ }}
16
+ </UBadge>
17
+
18
+ <p v-if="isDefault" class="text-muted text-sm">
19
+ {{ $t("dms_lang.translation.ws_default_hint") }}
20
+ </p>
21
+ <p v-else-if="isModules" class="text-muted text-sm">
22
+ {{ $t("dms_lang.translation.ws_modules_hint") }}
23
+ </p>
24
+ </template>
@@ -0,0 +1,177 @@
1
+ import { useDmsState } from '#dms-inertia/frontend-module'
2
+
3
+ export interface WorkspaceLocale {
4
+ code: string
5
+ name?: string
6
+ flag?: string
7
+ }
8
+
9
+ export type WorkspaceKind = 'default' | 'modules' | 'added'
10
+
11
+ export interface WorkspaceSummary {
12
+ id: string
13
+ kind: WorkspaceKind
14
+ editable: boolean
15
+ defaultLocale: string
16
+ locales: WorkspaceLocale[]
17
+ }
18
+
19
+ interface WorkspacesResponse {
20
+ editable: boolean
21
+ workspaces: WorkspaceSummary[]
22
+ }
23
+
24
+ const API_BASE = '/api/lang/translations'
25
+ const WORKSPACES_ENDPOINT = `${API_BASE}/workspaces`
26
+ const WORKSPACE_ENDPOINT = `${API_BASE}/workspace`
27
+ const WORKSPACE_RENAME_ENDPOINT = `${API_BASE}/workspace/rename`
28
+ const LOCALE_ENDPOINT = `${API_BASE}/locale`
29
+ const LOCALE_DEFAULT_ENDPOINT = `${API_BASE}/locale/default`
30
+ const KEY_ENDPOINT = `${API_BASE}/key`
31
+ const KEY_RENAME_ENDPOINT = `${API_BASE}/key/rename`
32
+
33
+ export const DEFAULT_WORKSPACE = 'default'
34
+
35
+ const WORKSPACE_ID_RE = /^[a-z0-9][\w-]{0,63}$/
36
+
37
+ export function normalizeWorkspaceId(raw: string): string {
38
+ return raw.trim().toLowerCase()
39
+ }
40
+
41
+ export const useI18nWorkspaces = () => {
42
+ const { $authFetch } = useAuthFetch()
43
+
44
+ const workspaces = useDmsState<WorkspaceSummary[]>(
45
+ 'dms-lang-workspaces',
46
+ () => [],
47
+ )
48
+ const editable = useDmsState<boolean>(
49
+ 'dms-lang-workspaces-editable',
50
+ () => false,
51
+ )
52
+ const isLoading = useDmsState<boolean>(
53
+ 'dms-lang-workspaces-loading',
54
+ () => false,
55
+ )
56
+ const selectedWorkspace = useDmsState<string>(
57
+ 'dms-lang-selected-workspace',
58
+ () => DEFAULT_WORKSPACE,
59
+ )
60
+ const requestSeq = useDmsState<number>('dms-lang-workspaces-seq', () => 0)
61
+
62
+ function canUseWorkspaceId(id: string): boolean {
63
+ return (
64
+ WORKSPACE_ID_RE.test(id) &&
65
+ !workspaces.value.some((workspace) => workspace.id === id)
66
+ )
67
+ }
68
+
69
+ function ensureSelection(): void {
70
+ if (workspaces.value.some((w) => w.id === selectedWorkspace.value)) return
71
+ selectedWorkspace.value = workspaces.value[0]?.id ?? ''
72
+ }
73
+
74
+ async function fetchWorkspaces(): Promise<WorkspaceSummary[]> {
75
+ requestSeq.value += 1
76
+ const sequence = requestSeq.value
77
+ isLoading.value = true
78
+ try {
79
+ const response = await $authFetch<WorkspacesResponse>(WORKSPACES_ENDPOINT)
80
+ if (sequence !== requestSeq.value) return workspaces.value
81
+ editable.value = response?.editable ?? false
82
+ workspaces.value = response?.workspaces ?? []
83
+ ensureSelection()
84
+ return workspaces.value
85
+ } catch {
86
+ return workspaces.value
87
+ } finally {
88
+ if (sequence === requestSeq.value) isLoading.value = false
89
+ }
90
+ }
91
+
92
+ function createWorkspace(id: string, locale: WorkspaceLocale) {
93
+ return $authFetch(WORKSPACE_ENDPOINT, {
94
+ method: 'POST',
95
+ body: { id, locale },
96
+ })
97
+ }
98
+
99
+ function renameWorkspace(id: string, newId: string) {
100
+ return $authFetch(WORKSPACE_RENAME_ENDPOINT, {
101
+ method: 'POST',
102
+ body: { id, newId },
103
+ })
104
+ }
105
+
106
+ function deleteWorkspace(id: string) {
107
+ return $authFetch(WORKSPACE_ENDPOINT, {
108
+ method: 'DELETE',
109
+ body: { id },
110
+ })
111
+ }
112
+
113
+ function addLocale(workspace: string, locale: WorkspaceLocale) {
114
+ return $authFetch(LOCALE_ENDPOINT, {
115
+ method: 'POST',
116
+ body: { workspace, ...locale },
117
+ })
118
+ }
119
+
120
+ function removeLocale(workspace: string, code: string) {
121
+ return $authFetch(LOCALE_ENDPOINT, {
122
+ method: 'DELETE',
123
+ body: { workspace, code },
124
+ })
125
+ }
126
+
127
+ function setDefaultLocale(workspace: string, code: string) {
128
+ return $authFetch(LOCALE_DEFAULT_ENDPOINT, {
129
+ method: 'POST',
130
+ body: { workspace, code },
131
+ })
132
+ }
133
+
134
+ function upsertKey(
135
+ workspace: string,
136
+ path: string,
137
+ values: Record<string, unknown> = {},
138
+ defaultLocale?: string,
139
+ ) {
140
+ return $authFetch(KEY_ENDPOINT, {
141
+ method: 'PUT',
142
+ body: { workspace, path, values, defaultLocale },
143
+ })
144
+ }
145
+
146
+ function renameKey(workspace: string, path: string, newPath: string) {
147
+ return $authFetch(KEY_RENAME_ENDPOINT, {
148
+ method: 'POST',
149
+ body: { workspace, path, newPath },
150
+ })
151
+ }
152
+
153
+ function deleteKey(workspace: string, path: string) {
154
+ return $authFetch(KEY_ENDPOINT, {
155
+ method: 'DELETE',
156
+ body: { workspace, path },
157
+ })
158
+ }
159
+
160
+ return {
161
+ workspaces,
162
+ editable,
163
+ selectedWorkspace,
164
+ isLoading: readonly(isLoading),
165
+ fetchWorkspaces,
166
+ canUseWorkspaceId,
167
+ createWorkspace,
168
+ renameWorkspace,
169
+ deleteWorkspace,
170
+ addLocale,
171
+ removeLocale,
172
+ setDefaultLocale,
173
+ upsertKey,
174
+ renameKey,
175
+ deleteKey,
176
+ }
177
+ }
@@ -0,0 +1,90 @@
1
+ export interface LanguageCatalogEntry {
2
+ code: string;
3
+ name: string;
4
+ flag: string;
5
+ }
6
+
7
+ const LANGUAGES: LanguageCatalogEntry[] = [
8
+ { code: "en", name: "English", flag: "gb-ukm" },
9
+ { code: "fr", name: "Français", flag: "fr" },
10
+ { code: "es", name: "Español", flag: "es" },
11
+ { code: "de", name: "Deutsch", flag: "de" },
12
+ { code: "it", name: "Italiano", flag: "it" },
13
+ { code: "pt", name: "Português", flag: "pt" },
14
+ { code: "nl", name: "Nederlands", flag: "nl" },
15
+ { code: "ru", name: "Русский", flag: "ru" },
16
+ { code: "zh", name: "中文", flag: "cn" },
17
+ { code: "ja", name: "日本語", flag: "jp" },
18
+ { code: "ko", name: "한국어", flag: "kr" },
19
+ { code: "ar", name: "العربية", flag: "sa" },
20
+ { code: "hi", name: "हिन्दी", flag: "in" },
21
+ { code: "bn", name: "বাংলা", flag: "bd" },
22
+ { code: "tr", name: "Türkçe", flag: "tr" },
23
+ { code: "pl", name: "Polski", flag: "pl" },
24
+ { code: "uk", name: "Українська", flag: "ua" },
25
+ { code: "ro", name: "Română", flag: "ro" },
26
+ { code: "el", name: "Ελληνικά", flag: "gr" },
27
+ { code: "cs", name: "Čeština", flag: "cz" },
28
+ { code: "sv", name: "Svenska", flag: "se" },
29
+ { code: "da", name: "Dansk", flag: "dk" },
30
+ { code: "fi", name: "Suomi", flag: "fi" },
31
+ { code: "no", name: "Norsk", flag: "no" },
32
+ { code: "hu", name: "Magyar", flag: "hu" },
33
+ { code: "sk", name: "Slovenčina", flag: "sk" },
34
+ { code: "bg", name: "Български", flag: "bg" },
35
+ { code: "hr", name: "Hrvatski", flag: "hr" },
36
+ { code: "sr", name: "Српски", flag: "rs" },
37
+ { code: "sl", name: "Slovenščina", flag: "si" },
38
+ { code: "et", name: "Eesti", flag: "ee" },
39
+ { code: "lv", name: "Latviešu", flag: "lv" },
40
+ { code: "lt", name: "Lietuvių", flag: "lt" },
41
+ { code: "he", name: "עברית", flag: "il" },
42
+ { code: "th", name: "ไทย", flag: "th" },
43
+ { code: "vi", name: "Tiếng Việt", flag: "vn" },
44
+ { code: "id", name: "Bahasa Indonesia", flag: "id" },
45
+ { code: "ms", name: "Bahasa Melayu", flag: "my" },
46
+ { code: "fa", name: "فارسی", flag: "ir" },
47
+ { code: "ur", name: "اردو", flag: "pk" },
48
+ { code: "ta", name: "தமிழ்", flag: "in" },
49
+ { code: "te", name: "తెలుగు", flag: "in" },
50
+ { code: "sw", name: "Kiswahili", flag: "ke" },
51
+ { code: "af", name: "Afrikaans", flag: "za" },
52
+ { code: "is", name: "Íslenska", flag: "is" },
53
+ { code: "ga", name: "Gaeilge", flag: "ie" },
54
+ { code: "sq", name: "Shqip", flag: "al" },
55
+ { code: "mk", name: "Македонски", flag: "mk" },
56
+ { code: "bs", name: "Bosanski", flag: "ba" },
57
+ { code: "ka", name: "ქართული", flag: "ge" },
58
+ { code: "hy", name: "Հայերեն", flag: "am" },
59
+ { code: "az", name: "Azərbaycan", flag: "az" },
60
+ { code: "kk", name: "Қазақ", flag: "kz" },
61
+ { code: "uz", name: "Oʻzbek", flag: "uz" },
62
+ { code: "mn", name: "Монгол", flag: "mn" },
63
+ { code: "ne", name: "नेपाली", flag: "np" },
64
+ { code: "si", name: "සිංහල", flag: "lk" },
65
+ { code: "km", name: "ខ្មែរ", flag: "kh" },
66
+ { code: "my", name: "မြန်မာ", flag: "mm" },
67
+ { code: "am", name: "አማርኛ", flag: "et" },
68
+ { code: "tl", name: "Tagalog", flag: "ph" },
69
+ ];
70
+
71
+ export interface LanguageSelectItem {
72
+ label: string;
73
+ value: string;
74
+ icon: string;
75
+ }
76
+
77
+ const BY_CODE = new Map(LANGUAGES.map((lang) => [lang.code, lang]));
78
+
79
+ const ITEMS: LanguageSelectItem[] = LANGUAGES.map((lang) => ({
80
+ label: `${lang.name} (${lang.code})`,
81
+ value: lang.code,
82
+ icon: `flagpack:${lang.flag}`,
83
+ }));
84
+
85
+ export const useLanguageCatalog = () => {
86
+ const resolveLanguage = (code: string): LanguageCatalogEntry =>
87
+ BY_CODE.get(code) ?? { code, name: code, flag: "" };
88
+
89
+ return { items: ITEMS, resolveLanguage };
90
+ };
@@ -0,0 +1,18 @@
1
+ export interface LocaleMeta {
2
+ name: string
3
+ flag: string
4
+ }
5
+
6
+ export const useLocaleMeta = () => {
7
+ const { uniqueLocales } = useUniqueLocales()
8
+ const { resolveLanguage } = useLanguageCatalog()
9
+
10
+ function localeMetaOf(code: string): LocaleMeta {
11
+ const meta = uniqueLocales.value.find((locale) => locale.code === code)
12
+ const language = resolveLanguage(code)
13
+ const name = language.name === code ? meta?.name ?? code : language.name
14
+ return { name, flag: language.flag }
15
+ }
16
+
17
+ return { localeMetaOf }
18
+ }
@@ -0,0 +1,30 @@
1
+ interface MutationError {
2
+ data?: { statusMessage?: string };
3
+ statusMessage?: string;
4
+ }
5
+
6
+ export const useMutationToast = () => {
7
+ const { t } = useI18n();
8
+ const toast = useToast();
9
+
10
+ function errorMessage(error: unknown): string {
11
+ const e = error as MutationError;
12
+ return (
13
+ e?.data?.statusMessage ??
14
+ e?.statusMessage ??
15
+ t("dms_lang.translation.ws_save_error")
16
+ );
17
+ }
18
+
19
+ async function tryMutate(fn: () => Promise<unknown>): Promise<boolean> {
20
+ try {
21
+ await fn();
22
+ return true;
23
+ } catch (error) {
24
+ toast.add({ title: errorMessage(error), color: "error" });
25
+ return false;
26
+ }
27
+ }
28
+
29
+ return { tryMutate };
30
+ };
@@ -0,0 +1,73 @@
1
+ type TranslationValue = string | number | boolean | null | undefined
2
+ type LocaleFallback = string | string[] | Record<string, string[]> | false
3
+
4
+ const API_BASE = '/api/lang/translations'
5
+ const TRANSLATION_FLAT_ENDPOINT = `${API_BASE}/flat`
6
+ const DEFAULT_LOCALE = 'en'
7
+
8
+ export interface FlatTranslationRow {
9
+ key: string
10
+ values: Record<string, TranslationValue>
11
+ /** Per-locale inherited module value (default workspace only). */
12
+ inherited?: Record<string, TranslationValue>
13
+ }
14
+
15
+ export interface FlatTranslations {
16
+ defaultLocale: string
17
+ locales: string[]
18
+ rows: FlatTranslationRow[]
19
+ localeProgress: Record<string, number>
20
+ localeMissing: Record<string, number>
21
+ totalKeys: number
22
+ }
23
+
24
+ export const EMPTY_FLAT: FlatTranslations = {
25
+ defaultLocale: '',
26
+ locales: [],
27
+ rows: [],
28
+ localeProgress: {},
29
+ localeMissing: {},
30
+ totalKeys: 0,
31
+ }
32
+
33
+ export function isLocaleValueMissing(value: unknown): boolean {
34
+ return value === undefined || value === null || value === ''
35
+ }
36
+
37
+ export function resolveDefaultLocale(fallback: LocaleFallback): string {
38
+ if (typeof fallback === 'string') return fallback
39
+ if (Array.isArray(fallback)) return fallback[0] ?? DEFAULT_LOCALE
40
+ return (fallback && fallback.default?.[0]) || DEFAULT_LOCALE
41
+ }
42
+
43
+ export const useTranslationProgress = () => {
44
+ const { $authFetch } = useAuthFetch()
45
+ const { fallbackLocale } = useI18n()
46
+
47
+ async function fetchFlat(
48
+ workspace: string = DEFAULT_WORKSPACE,
49
+ ): Promise<FlatTranslations | null> {
50
+ const defaultLocale = resolveDefaultLocale(fallbackLocale.value)
51
+ try {
52
+ const response = await $authFetch<Partial<FlatTranslations>>(
53
+ TRANSLATION_FLAT_ENDPOINT,
54
+ { query: { defaultLocale, workspace } },
55
+ )
56
+
57
+ return {
58
+ defaultLocale: response?.defaultLocale ?? String(defaultLocale),
59
+ locales: response?.locales ?? [],
60
+ rows: response?.rows ?? [],
61
+ localeProgress: response?.localeProgress ?? {},
62
+ localeMissing: response?.localeMissing ?? {},
63
+ totalKeys: response?.totalKeys ?? 0,
64
+ }
65
+ } catch {
66
+ return null
67
+ }
68
+ }
69
+
70
+ return {
71
+ fetchFlat,
72
+ }
73
+ }
@@ -0,0 +1,27 @@
1
+ import type { WorkspaceSummary } from "./useI18nWorkspaces";
2
+
3
+ /**
4
+ * Read-only view of the globally selected workspace and of what the current
5
+ * user may do with it, shared by every page and widget of the module.
6
+ */
7
+ export const useWorkspaceContext = () => {
8
+ const { workspaces, editable, selectedWorkspace } = useI18nWorkspaces();
9
+
10
+ const current = computed(
11
+ () =>
12
+ workspaces.value.find(
13
+ (workspace: WorkspaceSummary) =>
14
+ workspace.id === selectedWorkspace.value,
15
+ ) ?? null,
16
+ );
17
+
18
+ const isDefault = computed(() => current.value?.kind === "default");
19
+ const isModules = computed(() => current.value?.kind === "modules");
20
+ const isAdded = computed(() => current.value?.kind === "added");
21
+ const isEditable = computed(
22
+ () => editable.value && (current.value?.editable ?? false),
23
+ );
24
+ const canManage = computed(() => isAdded.value && isEditable.value);
25
+
26
+ return { current, isDefault, isModules, isAdded, isEditable, canManage };
27
+ };