@antelopejs/dms-lang 0.1.1 → 0.2.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.
- package/README.md +64 -39
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/validation/workspace.schema.d.ts +2 -2
- package/frontend-vue/app/build/composables/useMatrixView.ts +12 -14
- package/frontend-vue/app/components/WorkspaceList.vue +15 -23
- package/frontend-vue/app/components/WorkspaceScope.vue +4 -42
- package/frontend-vue/app/composables/translation/useI18nWorkspaces.ts +58 -63
- package/frontend-vue/app/composables/translation/useKeyActions.ts +1 -1
- package/frontend-vue/app/composables/translation/useLanguageActions.ts +12 -9
- package/frontend-vue/app/composables/translation/useWorkspaceActions.ts +3 -5
- package/frontend-vue/app/composables/translation/useWorkspaceFill.ts +50 -0
- package/frontend-vue/app/composables/translation/useWorkspaceFlat.ts +182 -208
- package/frontend-vue/app/composables/translation/useWorkspaceRoute.ts +2 -12
- package/frontend-vue/package.json +3 -3
- package/package.json +28 -11
- package/skills/dms-lang/SKILL.md +53 -0
- package/frontend-vue/app/composables/translation/useServedConfirm.ts +0 -152
package/README.md
CHANGED
|
@@ -1,68 +1,93 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# @antelopejs/dms-lang
|
|
2
4
|
|
|
3
|
-
<
|
|
4
|
-
<a href="./LICENSE"><img alt="License" src="https://img.shields.io/
|
|
5
|
-
<a href="https://discord.gg/sjK28QHrA7"><img src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000"
|
|
6
|
-
<a href="https://antelopejs.com"><img src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000"
|
|
7
|
-
</div>
|
|
5
|
+
<a href="https://www.npmjs.com/package/@antelopejs/dms-lang"><img alt="npm" src="https://img.shields.io/npm/v/@antelopejs/dms-lang?style=for-the-badge&labelColor=000000&color=000000"></a>
|
|
6
|
+
<a href="./LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@antelopejs/dms-lang?style=for-the-badge&labelColor=000000&color=000000"></a>
|
|
7
|
+
<a href="https://discord.gg/sjK28QHrA7"><img alt="Discord" src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000"></a>
|
|
8
|
+
<a href="https://dms.antelopejs.com/docs/modules/lang"><img alt="Documentation" src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000"></a>
|
|
8
9
|
|
|
9
|
-
Language and translation management for AntelopeJS DMS
|
|
10
|
+
Language and translation management for the AntelopeJS DMS.
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
</div>
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
- **Translate › Translations**: a key-by-language matrix with per-cell save state, placeholder checks, "Missing in" and namespace filters, a key editor drawer and CSV export.
|
|
15
|
-
- **Language** (opened from Overview): a translation queue for one language, with its progress by namespace.
|
|
16
|
-
- **Manage › Workspaces**: every workspace with its kind, size and coverage, and the creation of new ones.
|
|
17
|
-
- **Workspace settings** (opened from Workspaces): name, base language, languages, ready-to-paste app snippets and a danger zone.
|
|
14
|
+

|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
## What it does
|
|
20
17
|
|
|
21
|
-
|
|
18
|
+
- Reads every locale file the dashboard loads and shows how complete each language is, with a namespace × language heatmap.
|
|
19
|
+
- Edits every key side by side in a translation matrix, with placeholder checks, filters and CSV export.
|
|
20
|
+
- Walks one language key by key in a translation queue, with the base text and the other languages for context.
|
|
21
|
+
- Hosts translation workspaces for your other apps and serves them as public JSON at `/i18n/<workspace>/<locale>.json`.
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Install
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Run the AntelopeJS CLI from the root of a project that already loads `@antelopejs/dms`:
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
28
|
ajs project modules add @antelopejs/dms-lang
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
##
|
|
31
|
+
## Quick start
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
the running process should be allowed to create, rename, and delete workspaces, locales, keys, and
|
|
35
|
-
translations:
|
|
33
|
+
The module starts read-only. Allow writes on the process that edits translations:
|
|
36
34
|
|
|
37
|
-
```
|
|
38
|
-
config
|
|
39
|
-
|
|
40
|
-
}
|
|
35
|
+
```ts
|
|
36
|
+
// antelope.config.ts
|
|
37
|
+
"dms-lang": {
|
|
38
|
+
source: { type: "package", package: "@antelopejs/dms-lang", version: "^0.2.0" },
|
|
39
|
+
config: {
|
|
40
|
+
editable: true,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
41
43
|
```
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
Restart the backend, then the frontend, and open **Modules › Translations** (`/modules/lang/overview`). To edit your own frontend module's locale files, register it with `options: { dmsI18nAppLayer: true }`: see [Installation](https://dms.antelopejs.com/docs/modules/lang/installation).
|
|
46
|
+
|
|
47
|
+
## Compatibility
|
|
48
|
+
|
|
49
|
+
| Package | Version |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| `@antelopejs/dms` | `>=0.9.0 <1.0.0` |
|
|
52
|
+
| `@antelopejs/interface-dms` | `>=0.7.0 <1.0.0` |
|
|
53
|
+
| `@antelopejs/dms-frontend` (renderer) | `>=0.6.0 <0.7.0` |
|
|
54
|
+
|
|
55
|
+
On DMS 0.8, use `@antelopejs/dms-lang` 0.1.
|
|
45
56
|
|
|
46
|
-
##
|
|
57
|
+
## Documentation
|
|
58
|
+
|
|
59
|
+
- [Introduction](https://dms.antelopejs.com/docs/modules/lang/introduction)
|
|
60
|
+
- [Installation](https://dms.antelopejs.com/docs/modules/lang/installation)
|
|
61
|
+
- [Configuration](https://dms.antelopejs.com/docs/modules/lang/configuration)
|
|
62
|
+
- [Usage](https://dms.antelopejs.com/docs/modules/lang/usage/overview)
|
|
63
|
+
- [Extending](https://dms.antelopejs.com/docs/modules/lang/extending)
|
|
64
|
+
- [FAQ](https://dms.antelopejs.com/docs/modules/lang/faq)
|
|
65
|
+
|
|
66
|
+
The canonical guide lives in [`docs/`](./docs), including the [supported extension boundary](./docs/5.extending.md#supported-extension-boundary). There is no separate DMS Lang interface package. The package also ships the `dms-lang` Claude Code skill in [`skills/`](./skills), declared under `antelopeJs.skills`.
|
|
67
|
+
|
|
68
|
+
## Contributing
|
|
69
|
+
|
|
70
|
+
Read [CONTRIBUTING.md](./CONTRIBUTING.md) before opening a pull request. The playground connects to MongoDB at `mongodb://localhost:27017`; set `MONGO_URL` to use another instance.
|
|
47
71
|
|
|
48
72
|
```bash
|
|
49
73
|
pnpm install
|
|
50
|
-
pnpm
|
|
74
|
+
pnpm dev # playground backend
|
|
75
|
+
pnpm frontend:dev # dashboard, in a second terminal
|
|
76
|
+
pnpm lint
|
|
77
|
+
pnpm typecheck
|
|
51
78
|
pnpm test
|
|
52
79
|
```
|
|
53
80
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
The backend registers `frontend-vue/dms.frontend.ts` through `AddFrontendModule` with the Vue 3 renderer. The module declares `componentPrefix: "DmsLang"` and registers every component of `app/components` and `app/build/components` under it; the backend pages name them (`CustomComponent("DmsLangTranslationMatrix")`). `dms.frontend.build.ts` declares `app/composables`, `app/utils` and `app/types` for auto-import; `app/build/` is private and imported by path. Nuxt is not required; `@nuxt/ui` provides its Vue components through the adapter's Vite integration.
|
|
57
|
-
|
|
58
|
-
The module compiles against the published `@antelopejs/interface-dms` package, its only DMS runtime dependency. The `@antelopejs/dms` backend and the `@antelopejs/dms-frontend` adapter are development dependencies, needed to run the tests and the playground. Run `pnpm install`, `pnpm build` and `pnpm test` here.
|
|
59
|
-
|
|
60
|
-
`pnpm test:unit` checks locale discovery, the coverage, placeholder and message helpers of the frontend and the locale files. The backend tests (`src/test`: keys, workspaces, validation, coverage, summaries) run with `pnpm test` only: every backend file reaches an AntelopeJS interface (`@antelopejs/interface-api` for the errors, `@antelopejs/interface-dms` for the pages), and an interface refuses to load outside the AntelopeJS runtime. `pnpm test:frontend` compiles the module alongside the published core DMS frontend with the adapter's source verifier.
|
|
81
|
+
<details>
|
|
82
|
+
<summary>Repository notes</summary>
|
|
61
83
|
|
|
62
|
-
|
|
84
|
+
- The backend registers `frontend-vue/dms.frontend.ts` through `AddFrontendModule` with the Vue 3 renderer, under the `DmsLang` component prefix: every component of `app/components` and `app/build/components` is registered under it, and the backend pages name them (`CustomComponent("DmsLangTranslationMatrix")`). `dms.frontend.build.ts` auto-imports `app/composables`, `app/utils` and `app/types`; `app/build/` is private and imported by path.
|
|
85
|
+
- The pages read their data with the DMS's `useApiData`, which the server render hands to the browser with the page. The public language files (`/i18n/**`) are declared to the frontend server as a backend prefix without a session (`backendProxies`).
|
|
86
|
+
- The module compiles against the published `@antelopejs/interface-dms`; `@antelopejs/dms` and `@antelopejs/dms-frontend` are development dependencies, needed by the tests and the playground.
|
|
87
|
+
- `pnpm test:unit` checks locale discovery, the coverage, placeholder and message helpers, and renders the workspace composables on a server (`tests/frontend-runtime.mjs`). The backend tests (`src/test`) run with `pnpm test` only, since an interface refuses to load outside the AntelopeJS runtime. `pnpm test:frontend` compiles the module against the published DMS frontend with the renderer's source verifier.
|
|
63
88
|
|
|
64
|
-
|
|
89
|
+
</details>
|
|
65
90
|
|
|
66
|
-
|
|
91
|
+
## License
|
|
67
92
|
|
|
68
|
-
|
|
93
|
+
[Apache-2.0](./LICENSE)
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ exports.start = start;
|
|
|
22
22
|
const node_path_1 = __importDefault(require("node:path"));
|
|
23
23
|
const page_1 = require("@antelopejs/interface-dms/page");
|
|
24
24
|
const config_1 = require("./utils/config");
|
|
25
|
+
const constants_1 = require("./utils/constants");
|
|
25
26
|
const registry_1 = require("./utils/registry");
|
|
26
27
|
__exportStar(require("./pages"), exports);
|
|
27
28
|
__exportStar(require("./routes"), exports);
|
|
@@ -38,6 +39,7 @@ async function construct(config = {}) {
|
|
|
38
39
|
renderer: { name: "vue", version: "3" },
|
|
39
40
|
configKey: "dmsLang",
|
|
40
41
|
priority: 0,
|
|
42
|
+
backendProxies: [{ path: `${constants_1.PUBLIC_PATH}/**`, auth: "none" }],
|
|
41
43
|
});
|
|
42
44
|
}
|
|
43
45
|
async function start() {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAaA,8BAiBC;AAED,sBAEC;AAlCD,0DAA6B;AAC7B,yDAAmE;AACnE,2CAAsD;AACtD,iDAAgD;AAChD,+CAA4D;AAE5D,0CAAwB;AACxB,2CAAyB;AAMlB,KAAK,UAAU,SAAS,CAAC,SAAwB,EAAE;IACxD,MAAM,UAAU,GAAG,mBAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;IAC3D,MAAM,aAAa,GAAG,mBAAI,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;IAEjE,IAAA,6BAAoB,EAAC;QACnB,aAAa;QACb,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,KAAK;KACnC,CAAC,CAAC;IAEH,MAAM,IAAA,wBAAiB,EAAC;QACtB,IAAI,EAAE,mCAAmC;QACzC,UAAU;QACV,QAAQ,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE;QACvC,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,CAAC;QACX,cAAc,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,uBAAW,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;KAC9D,CAAC,CAAC;AACL,CAAC;AAEM,KAAK,UAAU,KAAK;IACzB,MAAM,IAAA,mCAAwB,GAAE,CAAC;AACnC,CAAC"}
|
|
@@ -90,9 +90,9 @@ export declare const workspaceSchema: {
|
|
|
90
90
|
}, "strip", z.ZodTypeAny, {
|
|
91
91
|
id: string;
|
|
92
92
|
messages: Record<string, unknown>;
|
|
93
|
+
version?: number | undefined;
|
|
93
94
|
type?: "" | "mobile" | "dms" | "website" | "other" | null | undefined;
|
|
94
95
|
description?: string | null | undefined;
|
|
95
|
-
version?: number | undefined;
|
|
96
96
|
format?: "dms-lang.workspace" | undefined;
|
|
97
97
|
defaultLocale?: string | undefined;
|
|
98
98
|
locales?: {
|
|
@@ -103,9 +103,9 @@ export declare const workspaceSchema: {
|
|
|
103
103
|
}, {
|
|
104
104
|
id: string;
|
|
105
105
|
messages: Record<string, unknown>;
|
|
106
|
+
version?: number | undefined;
|
|
106
107
|
type?: "" | "mobile" | "dms" | "website" | "other" | null | undefined;
|
|
107
108
|
description?: string | null | undefined;
|
|
108
|
-
version?: number | undefined;
|
|
109
109
|
format?: "dms-lang.workspace" | undefined;
|
|
110
110
|
defaultLocale?: string | undefined;
|
|
111
111
|
locales?: {
|
|
@@ -126,27 +126,24 @@ function useFilterQuery() {
|
|
|
126
126
|
function useColumnOrder() {
|
|
127
127
|
const { selectedWorkspace } = useI18nWorkspaces()
|
|
128
128
|
const { flat } = useWorkspaceFlat()
|
|
129
|
-
const order = ref<string[]>([])
|
|
130
129
|
const stored = useStorage<Partial<StoredColumns> | null>(
|
|
131
130
|
() => `${COLUMNS_STORAGE}${selectedWorkspace.value}`,
|
|
132
131
|
null,
|
|
133
132
|
undefined,
|
|
134
133
|
{ serializer: StorageSerializers.object },
|
|
135
134
|
)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
{ immediate: true },
|
|
135
|
+
const isMounted = ref(false)
|
|
136
|
+
onMounted(() => {
|
|
137
|
+
isMounted.value = true
|
|
138
|
+
})
|
|
139
|
+
const order = computed(() =>
|
|
140
|
+
restoredOrder(
|
|
141
|
+
flat.value.locales,
|
|
142
|
+
flat.value.defaultLocale,
|
|
143
|
+
isMounted.value ? columnsOf(stored.value) : null,
|
|
144
|
+
),
|
|
147
145
|
)
|
|
148
146
|
function saveOrder(next: string[]) {
|
|
149
|
-
order.value = next
|
|
150
147
|
stored.value = {
|
|
151
148
|
shown: next,
|
|
152
149
|
hidden: flat.value.locales.filter((code) => !next.includes(code)),
|
|
@@ -159,7 +156,8 @@ function useColumnOrder() {
|
|
|
159
156
|
* The view of the matrix a user chose: the filters live in the URL (a link
|
|
160
157
|
* or a refresh shows the same keys, Back undoes a filter change made by a
|
|
161
158
|
* link) and the columns shown, in their order, are remembered per workspace
|
|
162
|
-
* in this browser
|
|
159
|
+
* in this browser and applied once the page is mounted: a server render
|
|
160
|
+
* shows every language, as the browser's first render does.
|
|
163
161
|
*/
|
|
164
162
|
export function useMatrixView() {
|
|
165
163
|
const { flat } = useWorkspaceFlat()
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from '../utils/workspaces'
|
|
10
10
|
import type { WorkspaceSort } from '../utils/workspaces'
|
|
11
11
|
import LocaleTile from '../build/components/LocaleTile.vue'
|
|
12
|
+
import { useWorkspaceSummary } from '../composables/translation/useI18nWorkspaces'
|
|
12
13
|
|
|
13
14
|
interface WorkspaceStat {
|
|
14
15
|
id: string
|
|
@@ -42,8 +43,7 @@ const SORT_LABELS: Record<WorkspaceSort, string> = {
|
|
|
42
43
|
|
|
43
44
|
const { t } = useI18n()
|
|
44
45
|
const { formatCount } = useLangFormat()
|
|
45
|
-
const {
|
|
46
|
-
useI18nWorkspaces()
|
|
46
|
+
const { selectedWorkspace, editable } = useI18nWorkspaces()
|
|
47
47
|
const { createWorkspace, importWorkspace } = useWorkspaceActions()
|
|
48
48
|
const { typeIcon, typeLabel, kindIcon } = useWorkspaceTypes()
|
|
49
49
|
const { pageAction, clearPageAction, selectWorkspace } = useWorkspaceRoute()
|
|
@@ -53,10 +53,17 @@ const { getPreference, setPreference } = usePreferences()
|
|
|
53
53
|
|
|
54
54
|
const canCreate = computed(() => editable.value && allows('createWorkspace'))
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
|
|
56
|
+
// The workspaces' figures, read with the page.
|
|
57
|
+
const summaryRead = useWorkspaceSummary()
|
|
58
|
+
const summary = computed<WorkspaceStats[]>(
|
|
59
|
+
() => summaryRead.data.value?.workspaces ?? [],
|
|
60
|
+
)
|
|
61
|
+
const isLoaded = computed(() => summaryRead.data.value !== null)
|
|
62
|
+
const isLoading = computed(() => summaryRead.pending.value)
|
|
63
|
+
// A failure kept while it is tried again still shows the skeleton.
|
|
64
|
+
const hasError = computed(
|
|
65
|
+
() => summaryRead.error.value != null && !isLoading.value,
|
|
66
|
+
)
|
|
60
67
|
const search = ref('')
|
|
61
68
|
const sort = computed<WorkspaceSort>({
|
|
62
69
|
get: () => {
|
|
@@ -88,19 +95,8 @@ function isWorkspaceSort(value: unknown): value is WorkspaceSort {
|
|
|
88
95
|
return typeof value === 'string' && Object.hasOwn(SORT_LABELS, value)
|
|
89
96
|
}
|
|
90
97
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
const response = await fetchSummary()
|
|
95
|
-
summary.value = response.workspaces
|
|
96
|
-
editable.value = response.editable
|
|
97
|
-
hasError.value = false
|
|
98
|
-
isLoaded.value = true
|
|
99
|
-
} catch {
|
|
100
|
-
hasError.value = true
|
|
101
|
-
} finally {
|
|
102
|
-
isLoading.value = false
|
|
103
|
-
}
|
|
98
|
+
function load() {
|
|
99
|
+
void summaryRead.refresh()
|
|
104
100
|
}
|
|
105
101
|
|
|
106
102
|
function statsOf(workspace: WorkspaceStats): WorkspaceStat[] {
|
|
@@ -212,10 +208,6 @@ watch(
|
|
|
212
208
|
{ immediate: true },
|
|
213
209
|
)
|
|
214
210
|
|
|
215
|
-
onMounted(() => {
|
|
216
|
-
load()
|
|
217
|
-
fetchWorkspaces()
|
|
218
|
-
})
|
|
219
211
|
</script>
|
|
220
212
|
|
|
221
213
|
<template>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { useLangChanges } from '../composables/translation/useWorkspaceFlat'
|
|
3
|
-
import { useDmsRouter, useDmsState } from '#dms/frontend-module'
|
|
4
3
|
import type { DropdownMenuItem } from '@nuxt/ui'
|
|
5
4
|
import type { WorkspaceSummary } from '../types/lang'
|
|
6
5
|
import LocaleTile from '../build/components/LocaleTile.vue'
|
|
@@ -13,8 +12,7 @@ const MENU_FILTER_FIELDS = ['label', 'description', 'workspaceId', 'summary']
|
|
|
13
12
|
|
|
14
13
|
const { t } = useI18n()
|
|
15
14
|
const { formatCount } = useLangFormat()
|
|
16
|
-
const { workspaces, editable, isLoaded,
|
|
17
|
-
useI18nWorkspaces()
|
|
15
|
+
const { workspaces, editable, isLoaded, whenLoaded } = useI18nWorkspaces()
|
|
18
16
|
const {
|
|
19
17
|
current,
|
|
20
18
|
isEditable,
|
|
@@ -25,14 +23,12 @@ const {
|
|
|
25
23
|
} = useWorkspaceContext()
|
|
26
24
|
useLangChanges()
|
|
27
25
|
const {
|
|
28
|
-
route,
|
|
29
26
|
switchLink,
|
|
30
27
|
queryWorkspace,
|
|
31
28
|
pageAction,
|
|
32
29
|
clearPageAction,
|
|
33
30
|
currentPage,
|
|
34
31
|
} = useWorkspaceRoute()
|
|
35
|
-
const router = useDmsRouter()
|
|
36
32
|
|
|
37
33
|
/** What the bar says about the workspace shown, from the workspace list. */
|
|
38
34
|
const scope = computed(() => ({
|
|
@@ -178,44 +174,10 @@ const firstRunActions = computed(() => [
|
|
|
178
174
|
},
|
|
179
175
|
])
|
|
180
176
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
* remembered, or the project files once that one turns out to be gone.
|
|
184
|
-
*/
|
|
185
|
-
const filledFromMemory = useDmsState<string>(
|
|
186
|
-
'dms-lang-workspace-filled',
|
|
187
|
-
() => '',
|
|
188
|
-
)
|
|
189
|
-
|
|
190
|
-
function fillWorkspace(workspace: string): void {
|
|
191
|
-
void router.replace(linkWithQuery(route.path, { ...route.query, workspace }))
|
|
177
|
+
if (import.meta.env.SSR && !queryWorkspace.value && !pageAction.value) {
|
|
178
|
+
await whenLoaded()
|
|
192
179
|
}
|
|
193
|
-
|
|
194
|
-
watch(
|
|
195
|
-
[queryWorkspace, pageAction],
|
|
196
|
-
([workspace, action]) => {
|
|
197
|
-
if (import.meta.env.SSR || workspace || action) return
|
|
198
|
-
const isKnown = workspaces.value.some(
|
|
199
|
-
(entry) => entry.id === selectedWorkspace.value,
|
|
200
|
-
)
|
|
201
|
-
const fallback =
|
|
202
|
-
isKnown || !isLoaded.value ? selectedWorkspace.value : DEFAULT_WORKSPACE
|
|
203
|
-
filledFromMemory.value = fallback
|
|
204
|
-
fillWorkspace(fallback)
|
|
205
|
-
},
|
|
206
|
-
{ immediate: true },
|
|
207
|
-
)
|
|
208
|
-
|
|
209
|
-
watch(
|
|
210
|
-
[isUnknown, queryWorkspace],
|
|
211
|
-
([unknown, workspace]) => {
|
|
212
|
-
if (import.meta.env.SSR || !unknown) return
|
|
213
|
-
if (!workspace || workspace !== filledFromMemory.value) return
|
|
214
|
-
filledFromMemory.value = ''
|
|
215
|
-
fillWorkspace(DEFAULT_WORKSPACE)
|
|
216
|
-
},
|
|
217
|
-
{ immediate: true },
|
|
218
|
-
)
|
|
180
|
+
useWorkspaceFill()
|
|
219
181
|
|
|
220
182
|
watch(
|
|
221
183
|
[pageAction, isResolved],
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useDmsCookie, useDmsState } from '#dms/frontend-module'
|
|
2
2
|
import type {
|
|
3
3
|
FlatCounts,
|
|
4
|
-
FlatTranslations,
|
|
5
4
|
KeyRowResponse,
|
|
6
5
|
ScopedWorkspace,
|
|
7
6
|
WorkspaceDetails,
|
|
@@ -34,7 +33,7 @@ type KeyValues = Record<string, unknown>
|
|
|
34
33
|
/** The routes of the module's API. */
|
|
35
34
|
export const LANG_API = '/api/lang/translations'
|
|
36
35
|
const API_BASE = LANG_API
|
|
37
|
-
const ENDPOINTS = {
|
|
36
|
+
export const ENDPOINTS = {
|
|
38
37
|
workspaces: `${API_BASE}/workspaces`,
|
|
39
38
|
flat: `${API_BASE}/flat`,
|
|
40
39
|
row: `${API_BASE}/row`,
|
|
@@ -86,23 +85,10 @@ function useWorkspacesState() {
|
|
|
86
85
|
const lastWorkspace = useLastWorkspace()
|
|
87
86
|
return {
|
|
88
87
|
lastWorkspace,
|
|
89
|
-
workspaces: useDmsState<ScopedWorkspace[]>(
|
|
90
|
-
'dms-lang-workspaces',
|
|
91
|
-
() => [],
|
|
92
|
-
),
|
|
93
|
-
editable: useDmsState<boolean>('dms-lang-workspaces-editable', () => false),
|
|
94
|
-
permissions: useDmsState<WorkspacePermissionIds | null>(
|
|
95
|
-
'dms-lang-workspaces-permissions',
|
|
96
|
-
() => null,
|
|
97
|
-
),
|
|
98
|
-
publicBaseUrl: useDmsState<string>('dms-lang-public-base-url', () => ''),
|
|
99
|
-
isLoading: useDmsState<boolean>('dms-lang-workspaces-loading', () => false),
|
|
100
|
-
isLoaded: useDmsState<boolean>('dms-lang-workspaces-loaded', () => false),
|
|
101
88
|
selectedWorkspace: useDmsState<string>(
|
|
102
89
|
'dms-lang-selected-workspace',
|
|
103
90
|
() => lastWorkspace.value || DEFAULT_WORKSPACE,
|
|
104
91
|
),
|
|
105
|
-
requestSeq: useDmsState<number>('dms-lang-workspaces-seq', () => 0),
|
|
106
92
|
}
|
|
107
93
|
}
|
|
108
94
|
|
|
@@ -172,55 +158,70 @@ function useWorkspaceWrites() {
|
|
|
172
158
|
}
|
|
173
159
|
}
|
|
174
160
|
|
|
175
|
-
|
|
161
|
+
/** The backup file a download saves: a file the user keeps, not data a page shows. */
|
|
162
|
+
function useWorkspaceDownloads() {
|
|
176
163
|
const { $authFetch } = useAuthFetch()
|
|
177
164
|
return {
|
|
178
|
-
fetchSummary: () => $authFetch<SummaryResponse>(ENDPOINTS.summary),
|
|
179
165
|
fetchBackup: (workspace: string) =>
|
|
180
166
|
$authFetch<WorkspaceBackup>(ENDPOINTS.backup, { query: { workspace } }),
|
|
181
|
-
fetchFlat: (workspace: string) =>
|
|
182
|
-
$authFetch<FlatTranslations>(ENDPOINTS.flat, { query: { workspace } }),
|
|
183
|
-
fetchRow: (workspace: string, key: string) =>
|
|
184
|
-
$authFetch<KeyRowResponse>(ENDPOINTS.row, { query: { workspace, key } }),
|
|
185
167
|
}
|
|
186
168
|
}
|
|
187
169
|
|
|
170
|
+
/** The workspaces with their figures, for the workspace list page. */
|
|
171
|
+
export const useWorkspaceSummary = () =>
|
|
172
|
+
useApiData<SummaryResponse>(ENDPOINTS.summary)
|
|
173
|
+
|
|
188
174
|
/**
|
|
189
175
|
* The workspaces of the module, the one selected for every page, and the
|
|
190
|
-
* routes that read and change them. The
|
|
191
|
-
*
|
|
192
|
-
*
|
|
176
|
+
* routes that read and change them. The list is read with the page, once for
|
|
177
|
+
* every block showing it: a server render hands it to the browser. The
|
|
178
|
+
* selection follows the page URL (`?workspace=`, see useWorkspaceRoute): a
|
|
179
|
+
* workspace the URL names but the list lacks stays selected, so the page can
|
|
180
|
+
* say it does not exist.
|
|
193
181
|
*/
|
|
194
182
|
export const useI18nWorkspaces = () => {
|
|
195
|
-
const { $authFetch } = useAuthFetch()
|
|
196
183
|
const state = useWorkspacesState()
|
|
184
|
+
const list = useApiData<WorkspacesResponse>(ENDPOINTS.workspaces)
|
|
185
|
+
const workspaces = computed(() => list.data.value?.workspaces ?? [])
|
|
197
186
|
|
|
198
187
|
function canUseWorkspaceId(id: string): boolean {
|
|
199
188
|
return (
|
|
200
189
|
isValidWorkspaceId(id) &&
|
|
201
|
-
!
|
|
190
|
+
!workspaces.value.some((workspace) => workspace.id === id)
|
|
202
191
|
)
|
|
203
192
|
}
|
|
204
193
|
|
|
205
|
-
function
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
194
|
+
function mapWorkspace(
|
|
195
|
+
id: string,
|
|
196
|
+
change: (workspace: ScopedWorkspace) => ScopedWorkspace,
|
|
197
|
+
): void {
|
|
198
|
+
const current = list.data.value
|
|
199
|
+
if (!current) return
|
|
200
|
+
list.data.value = {
|
|
201
|
+
...current,
|
|
202
|
+
workspaces: current.workspaces.map((workspace) =>
|
|
203
|
+
workspace.id === id ? change(workspace) : workspace,
|
|
204
|
+
),
|
|
205
|
+
}
|
|
211
206
|
}
|
|
212
207
|
|
|
213
208
|
/** Takes the figures a key write answered into the workspace list (the scope bar). */
|
|
214
209
|
function patchCounts(id: string, counts: FlatCounts): void {
|
|
215
|
-
|
|
216
|
-
workspace
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
210
|
+
mapWorkspace(id, (workspace) => ({
|
|
211
|
+
...workspace,
|
|
212
|
+
totalKeys: counts.totalKeys,
|
|
213
|
+
baseMissing: counts.baseMissing,
|
|
214
|
+
}))
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Takes the workspace a details write answered into the list, its figures kept. */
|
|
218
|
+
function patchSummary(summary: WorkspaceSummary): void {
|
|
219
|
+
mapWorkspace(summary.id, (workspace) => ({
|
|
220
|
+
...summary,
|
|
221
|
+
totalKeys: workspace.totalKeys,
|
|
222
|
+
baseMissing: workspace.baseMissing,
|
|
223
|
+
translatedStrings: workspace.translatedStrings,
|
|
224
|
+
}))
|
|
224
225
|
}
|
|
225
226
|
|
|
226
227
|
/** Remembers the workspace a page without `?workspace=` opens on (a new tab, a menu link). */
|
|
@@ -228,37 +229,31 @@ export const useI18nWorkspaces = () => {
|
|
|
228
229
|
if (state.lastWorkspace.value !== id) state.lastWorkspace.value = id
|
|
229
230
|
}
|
|
230
231
|
|
|
232
|
+
/** Reads the list again, after a write or a change heard from elsewhere. */
|
|
231
233
|
async function fetchWorkspaces(): Promise<ScopedWorkspace[]> {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
state.isLoading.value = true
|
|
235
|
-
try {
|
|
236
|
-
const response = await $authFetch<WorkspacesResponse>(
|
|
237
|
-
ENDPOINTS.workspaces,
|
|
238
|
-
)
|
|
239
|
-
if (sequence !== state.requestSeq.value) return state.workspaces.value
|
|
240
|
-
applyResponse(response)
|
|
241
|
-
return state.workspaces.value
|
|
242
|
-
} catch {
|
|
243
|
-
return state.workspaces.value
|
|
244
|
-
} finally {
|
|
245
|
-
if (sequence === state.requestSeq.value) state.isLoading.value = false
|
|
246
|
-
}
|
|
234
|
+
await list.refresh()
|
|
235
|
+
return workspaces.value
|
|
247
236
|
}
|
|
248
237
|
|
|
249
238
|
return {
|
|
250
|
-
workspaces
|
|
251
|
-
editable:
|
|
252
|
-
permissions:
|
|
253
|
-
publicBaseUrl:
|
|
239
|
+
workspaces,
|
|
240
|
+
editable: computed(() => list.data.value?.editable ?? false),
|
|
241
|
+
permissions: computed(() => list.data.value?.permissions ?? null),
|
|
242
|
+
publicBaseUrl: computed(() => list.data.value?.publicBaseUrl ?? ''),
|
|
254
243
|
selectedWorkspace: state.selectedWorkspace,
|
|
255
|
-
isLoading:
|
|
256
|
-
|
|
244
|
+
isLoading: computed(() => list.pending.value),
|
|
245
|
+
/** The list was read once: the page can tell a workspace it lacks. */
|
|
246
|
+
isLoaded: computed(() => list.data.value !== null),
|
|
247
|
+
/** Resolves once the list was read: what a server render waits for. */
|
|
248
|
+
whenLoaded: async (): Promise<void> => {
|
|
249
|
+
await list
|
|
250
|
+
},
|
|
257
251
|
fetchWorkspaces,
|
|
258
252
|
patchCounts,
|
|
253
|
+
patchSummary,
|
|
259
254
|
canUseWorkspaceId,
|
|
260
255
|
rememberWorkspace,
|
|
261
|
-
...
|
|
256
|
+
...useWorkspaceDownloads(),
|
|
262
257
|
...useWorkspaceWrites(),
|
|
263
258
|
...useKeyWrites(),
|
|
264
259
|
}
|
|
@@ -42,7 +42,7 @@ async function moduleRows(
|
|
|
42
42
|
context: KeyActionsContext,
|
|
43
43
|
): Promise<FlatTranslationRow[]> {
|
|
44
44
|
if (!context.isDefault.value) return []
|
|
45
|
-
return (await context.translations.
|
|
45
|
+
return (await context.translations.loadModules()).rows
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
async function addKey(context: KeyActionsContext): Promise<string[]> {
|
|
@@ -8,7 +8,7 @@ interface LanguageActionsContext {
|
|
|
8
8
|
t: ReturnType<typeof useI18n>['t']
|
|
9
9
|
toast: ReturnType<typeof useToast>
|
|
10
10
|
overlay: ReturnType<typeof useOverlay>
|
|
11
|
-
|
|
11
|
+
confirmFrom: ReturnType<typeof useConfirmFrom>['confirmFrom']
|
|
12
12
|
formatCount: ReturnType<typeof useLangFormat>['formatCount']
|
|
13
13
|
workspaces: ReturnType<typeof useI18nWorkspaces>
|
|
14
14
|
translations: ReturnType<typeof useWorkspaceFlat>
|
|
@@ -99,10 +99,11 @@ async function removeLanguage(
|
|
|
99
99
|
): Promise<boolean> {
|
|
100
100
|
const workspace = context.workspaces.selectedWorkspace.value
|
|
101
101
|
const route = languageRoute(context, code)
|
|
102
|
-
const removed = await context.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
const removed = await context.confirmFrom(`${route}/${REMOVAL_CONFIRM}`, {
|
|
103
|
+
onConfirm: async () => {
|
|
104
|
+
await context.workspaces.removeLocale(workspace, code)
|
|
105
|
+
},
|
|
106
|
+
})
|
|
106
107
|
if (!removed) return false
|
|
107
108
|
notify(context, context.t('dms_lang.language_remove.done'))
|
|
108
109
|
await dialogsLeft(context)
|
|
@@ -122,9 +123,11 @@ async function makeBase(
|
|
|
122
123
|
): Promise<boolean> {
|
|
123
124
|
const workspace = context.workspaces.selectedWorkspace.value
|
|
124
125
|
const route = languageRoute(context, code)
|
|
125
|
-
const confirmed = await context.
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
const confirmed = await context.confirmFrom(`${route}/${BASE_CONFIRM}`, {
|
|
127
|
+
onConfirm: async () => {
|
|
128
|
+
await context.workspaces.setDefaultLocale(workspace, code)
|
|
129
|
+
},
|
|
130
|
+
})
|
|
128
131
|
if (!confirmed) return false
|
|
129
132
|
await context.translations.refresh()
|
|
130
133
|
notify(
|
|
@@ -141,7 +144,7 @@ export const useLanguageActions = () => {
|
|
|
141
144
|
t: useI18n().t,
|
|
142
145
|
toast: useToast(),
|
|
143
146
|
overlay: useOverlay(),
|
|
144
|
-
|
|
147
|
+
confirmFrom: useConfirmFrom().confirmFrom,
|
|
145
148
|
formatCount: useLangFormat().formatCount,
|
|
146
149
|
workspaces: useI18nWorkspaces(),
|
|
147
150
|
translations: useWorkspaceFlat(),
|
|
@@ -146,13 +146,11 @@ async function updateDetails(
|
|
|
146
146
|
id: string,
|
|
147
147
|
change: DetailsChange,
|
|
148
148
|
): Promise<boolean> {
|
|
149
|
-
const
|
|
150
|
-
|
|
149
|
+
const { workspaces } = context
|
|
150
|
+
return context.failures.tryMutate(
|
|
151
|
+
async () => workspaces.patchSummary(await workspaces.updateWorkspace(id, change)),
|
|
151
152
|
{ title: context.t('dms_lang.workspace_details.save_failed') },
|
|
152
153
|
)
|
|
153
|
-
if (!ok) return false
|
|
154
|
-
await context.workspaces.fetchWorkspaces()
|
|
155
|
-
return true
|
|
156
154
|
}
|
|
157
155
|
|
|
158
156
|
async function downloadBackup(
|