@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/package.json
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/dms-lang",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Language and translation management for the AntelopeJS DMS: coverage overview, translation matrix, translation queue and public translation workspaces.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"antelopejs",
|
|
7
|
+
"dms",
|
|
8
|
+
"dms-module",
|
|
9
|
+
"i18n",
|
|
10
|
+
"localization",
|
|
11
|
+
"translations"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://dms.antelopejs.com/docs/modules/lang",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/AntelopeJS/dms-lang/issues"
|
|
16
|
+
},
|
|
4
17
|
"license": "Apache-2.0",
|
|
5
18
|
"repository": {
|
|
6
19
|
"type": "git",
|
|
@@ -10,7 +23,8 @@
|
|
|
10
23
|
"dist",
|
|
11
24
|
"!dist/test",
|
|
12
25
|
"!dist/.tsbuildinfo",
|
|
13
|
-
"frontend-vue"
|
|
26
|
+
"frontend-vue",
|
|
27
|
+
"skills"
|
|
14
28
|
],
|
|
15
29
|
"main": "dist/index.js",
|
|
16
30
|
"types": "dist/index.d.ts",
|
|
@@ -45,18 +59,18 @@
|
|
|
45
59
|
"knip:all": "knip"
|
|
46
60
|
},
|
|
47
61
|
"dependencies": {
|
|
48
|
-
"@antelopejs/interface-api": ">=0.0.
|
|
49
|
-
"@antelopejs/interface-api-util": ">=0.1.
|
|
50
|
-
"@antelopejs/interface-core": ">=0.
|
|
51
|
-
"@antelopejs/interface-dms": ">=0.
|
|
62
|
+
"@antelopejs/interface-api": ">=0.0.15 <1.0.0",
|
|
63
|
+
"@antelopejs/interface-api-util": ">=0.1.3 <1.0.0",
|
|
64
|
+
"@antelopejs/interface-core": ">=0.2.4 <1.0.0",
|
|
65
|
+
"@antelopejs/interface-dms": ">=0.7.2 <1.0.0",
|
|
52
66
|
"@intlify/message-compiler": "^11.1.12",
|
|
53
67
|
"zod": "~3.24.2"
|
|
54
68
|
},
|
|
55
69
|
"devDependencies": {
|
|
56
|
-
"@antelopejs/core": "1.
|
|
57
|
-
"@antelopejs/dms": ">=0.
|
|
58
|
-
"@antelopejs/dms-frontend": "0.
|
|
59
|
-
"@antelopejs/tooling-configs": ">=0.0.
|
|
70
|
+
"@antelopejs/core": "1.16.0",
|
|
71
|
+
"@antelopejs/dms": ">=0.9.3 <1.0.0",
|
|
72
|
+
"@antelopejs/dms-frontend": "0.6.3",
|
|
73
|
+
"@antelopejs/tooling-configs": ">=0.0.9 <1.0.0",
|
|
60
74
|
"@types/chai": "^5.2.3",
|
|
61
75
|
"@types/mocha": "^10.0.10",
|
|
62
76
|
"@types/node": "^24.0.0",
|
|
@@ -77,6 +91,9 @@
|
|
|
77
91
|
"antelopeJs": {
|
|
78
92
|
"baseUrl": "dist",
|
|
79
93
|
"implements": [],
|
|
80
|
-
"test": "src/test/harness.ts"
|
|
94
|
+
"test": "src/test/harness.ts",
|
|
95
|
+
"skills": [
|
|
96
|
+
"./skills"
|
|
97
|
+
]
|
|
81
98
|
}
|
|
82
99
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dms-lang
|
|
3
|
+
description: Manages translations with the @antelopejs/dms-lang module of the AntelopeJS DMS. Use when installing or configuring dms-lang, adding or translating i18n keys of a DMS project (app-*.json), overriding a module's texts, creating a translation workspace served as public JSON to another app (website, mobile), or debugging read-only, missing or 404 translations.
|
|
4
|
+
icon: i-lucide-languages
|
|
5
|
+
category: i18n
|
|
6
|
+
tags: [i18n, translations, locales, workspaces, dms-module]
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# dms-lang
|
|
10
|
+
|
|
11
|
+
Translation management for the DMS, under `/modules/lang` (owner-only, like every module page).
|
|
12
|
+
User docs: `docs/` of this package, published at https://dms.antelopejs.com/docs/modules/lang.
|
|
13
|
+
|
|
14
|
+
## When to reach for it
|
|
15
|
+
|
|
16
|
+
- A project needs its dashboard texts (`$app.*` keys) translated or edited without touching JSON by hand.
|
|
17
|
+
- Another app (website, mobile app) needs translation files hosted and edited in the DMS.
|
|
18
|
+
- A module's built-in text must read differently in one project: override the key, never edit the module's files.
|
|
19
|
+
|
|
20
|
+
## Setup
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
ajs project modules add @antelopejs/dms-lang
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
- `config.editable: true` in `antelope.config.ts` allows every write. Default `false`: writes fail with a read-only error.
|
|
27
|
+
- The project's own frontend module needs `options: { dmsI18nAppLayer: true }` in `AddFrontendModule`; its `i18n/locales/app-<locale>.json` files become the writable **Project files** workspace.
|
|
28
|
+
- A new frontend module is discovered at backend start only; file edits show on the next read.
|
|
29
|
+
- Lang 0.2 requires `@antelopejs/dms` >=0.9 (interface-dms 0.7, renderer `@antelopejs/dms-frontend` 0.6); Lang 0.1 is the DMS 0.8 line.
|
|
30
|
+
|
|
31
|
+
## Workspaces
|
|
32
|
+
|
|
33
|
+
| Id | Kind | Editable | Public |
|
|
34
|
+
| --- | --- | --- | --- |
|
|
35
|
+
| `default` | Project files (`app-*.json`) | yes, with `editable` | no |
|
|
36
|
+
| `modules` | Files shipped by the DMS and installed modules | no, override into `default` | no |
|
|
37
|
+
| any other | Created in the UI or by `POST /api/lang/translations/workspace` / `import` | yes, with `editable` | `GET <apiBaseUrl>/i18n/<id>/<locale>.json`, any origin |
|
|
38
|
+
|
|
39
|
+
Created workspaces live in the module's `i18n-workspaces/<id>/` folder: back them up (Download backup) before reinstalling.
|
|
40
|
+
|
|
41
|
+
## Pages and links
|
|
42
|
+
|
|
43
|
+
Overview, Translation matrix (`translations`), Translation queue (`language?locale=`), Workspaces, Workspace settings (`workspace`). Every page takes `?workspace=<id>`; `?action=add-key|add-language|new-workspace` opens the dialog, `?filter=missing` filters the matrix.
|
|
44
|
+
|
|
45
|
+
## Gotchas
|
|
46
|
+
|
|
47
|
+
- Messages use the vue-i18n format: `{name}` placeholders, `one | many` plurals, a literal `@` written `{'@'}`. A placeholder that differs from the base text is flagged as an issue.
|
|
48
|
+
- In `default`, a key a module already translates counts as translated ("From a module"); writing a value overrides it.
|
|
49
|
+
- Write routes check page-action permissions (`modules.lang.translate.translations.scoped.matrix.edit`, `….keys`, `modules.lang.manage.workspaces.list.create`, …) on top of `@AuthOwnerOnly`.
|
|
50
|
+
- Writes publish on the realtime topic `dms-lang.translations`.
|
|
51
|
+
- Pages render on the server (`useApiData`); a page without `?workspace=` is redirected server-side to the remembered workspace or `default`.
|
|
52
|
+
- The public files are declared to the frontend server (`backendProxies: [{ path: "/i18n/**", auth: "none" }]`), so they answer on the dashboard origin as well as the backend's.
|
|
53
|
+
- Labels of a page or custom block you write stay i18n keys (`$app.my_page.title`) in `app-*.json`; Lang is where people translate them, never a reason to hard-code text.
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/** A text of a served dialog: an i18n key with `$`, else a literal with `{param}` fill-ins. */
|
|
2
|
-
type ServedText = string
|
|
3
|
-
|
|
4
|
-
const KEY_PREFIX = '$'
|
|
5
|
-
const PARAM_PATTERN = /{(\w+)}/g
|
|
6
|
-
|
|
7
|
-
interface ServedImpact {
|
|
8
|
-
icon: string
|
|
9
|
-
label: ServedText
|
|
10
|
-
count?: number | string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface ServedDownload {
|
|
14
|
-
type: 'download'
|
|
15
|
-
url: string
|
|
16
|
-
filename?: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface ServedSecondaryAction {
|
|
20
|
-
label: ServedText
|
|
21
|
-
icon?: string
|
|
22
|
-
target: ServedDownload
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** A confirmation dialog as a `confirm: { from }` route serves it (interface-dms `ConfirmDialogSerialized`). */
|
|
26
|
-
export interface ServedDialog {
|
|
27
|
-
title: ServedText
|
|
28
|
-
description?: ServedText
|
|
29
|
-
params?: Record<string, unknown>
|
|
30
|
-
color?: 'primary' | 'warning' | 'error' | 'neutral'
|
|
31
|
-
icon?: string
|
|
32
|
-
confirmLabel?: ServedText
|
|
33
|
-
cancelLabel?: ServedText
|
|
34
|
-
confirmText?: string
|
|
35
|
-
impact?: ServedImpact[]
|
|
36
|
-
secondaryAction?: ServedSecondaryAction
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type ConfirmRun = () => Promise<unknown>
|
|
40
|
-
|
|
41
|
-
type Params = Record<string, unknown>
|
|
42
|
-
|
|
43
|
-
/** What resolving and running a served dialog needs from the DMS. */
|
|
44
|
-
interface ServedContext {
|
|
45
|
-
t: ReturnType<typeof useI18n>['t']
|
|
46
|
-
authFetch: ReturnType<typeof useAuthFetch>['$authFetch']
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function fillLiteral(text: string, params: Params): string {
|
|
50
|
-
return text.replace(PARAM_PATTERN, (match, name: string) =>
|
|
51
|
-
params[name] === undefined ? match : String(params[name]),
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function resolveText(
|
|
56
|
-
{ t }: ServedContext,
|
|
57
|
-
value: ServedText,
|
|
58
|
-
params: Params,
|
|
59
|
-
): string {
|
|
60
|
-
if (!value.startsWith(KEY_PREFIX)) return fillLiteral(value, params)
|
|
61
|
-
const key = value.slice(KEY_PREFIX.length)
|
|
62
|
-
const { count } = params
|
|
63
|
-
return typeof count === 'number' ? t(key, params, count) : t(key, params)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Fetches a served download with the user's session and saves it. */
|
|
67
|
-
async function download(
|
|
68
|
-
context: ServedContext,
|
|
69
|
-
target: ServedDownload,
|
|
70
|
-
params: Params,
|
|
71
|
-
): Promise<void> {
|
|
72
|
-
const url = interpolateUrl(target.url, params)
|
|
73
|
-
const response = await context.authFetch.raw<Blob, 'blob'>(url, {
|
|
74
|
-
responseType: 'blob',
|
|
75
|
-
})
|
|
76
|
-
const objectUrl = URL.createObjectURL(response._data ?? new Blob([]))
|
|
77
|
-
try {
|
|
78
|
-
downloadFile(objectUrl, interpolateRowText(target.filename ?? '', params))
|
|
79
|
-
} finally {
|
|
80
|
-
URL.revokeObjectURL(objectUrl)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function secondaryOf(
|
|
85
|
-
context: ServedContext,
|
|
86
|
-
dialog: ServedDialog,
|
|
87
|
-
params: Params,
|
|
88
|
-
) {
|
|
89
|
-
const action = dialog.secondaryAction
|
|
90
|
-
if (!action) return undefined
|
|
91
|
-
return {
|
|
92
|
-
label: resolveText(context, action.label, params),
|
|
93
|
-
icon: action.icon,
|
|
94
|
-
run: () => download(context, action.target, params),
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** A served dialog with its texts resolved, ready for `useConfirm()`. */
|
|
99
|
-
function confirmOptionsOf(context: ServedContext, dialog: ServedDialog) {
|
|
100
|
-
const params = dialog.params ?? {}
|
|
101
|
-
const text = (value?: ServedText) =>
|
|
102
|
-
value === undefined ? undefined : resolveText(context, value, params)
|
|
103
|
-
return {
|
|
104
|
-
title: text(dialog.title) ?? '',
|
|
105
|
-
description: text(dialog.description),
|
|
106
|
-
color: dialog.color,
|
|
107
|
-
icon: dialog.icon,
|
|
108
|
-
confirmLabel: text(dialog.confirmLabel),
|
|
109
|
-
cancelLabel: text(dialog.cancelLabel),
|
|
110
|
-
confirmText: dialog.confirmText,
|
|
111
|
-
impact: dialog.impact?.map((entry) => ({
|
|
112
|
-
...entry,
|
|
113
|
-
label: text(entry.label) ?? '',
|
|
114
|
-
})),
|
|
115
|
-
secondaryAction: secondaryOf(context, dialog, params),
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Asks with the dialog the server words for an action (the one a table row
|
|
121
|
-
* action asks with, through `confirm: { from }`), so the action asks the
|
|
122
|
-
* same question wherever it starts: its texts, its impact, the code to type
|
|
123
|
-
* and its download. Resolves whether the user confirmed and `run` succeeded.
|
|
124
|
-
*/
|
|
125
|
-
export function useServedConfirm() {
|
|
126
|
-
const context: ServedContext = {
|
|
127
|
-
t: useI18n().t,
|
|
128
|
-
authFetch: useAuthFetch().$authFetch,
|
|
129
|
-
}
|
|
130
|
-
const { confirm } = useConfirm()
|
|
131
|
-
const { reportFailure } = useMutationToast()
|
|
132
|
-
|
|
133
|
-
async function loadDialog(url: string): Promise<ServedDialog | null> {
|
|
134
|
-
try {
|
|
135
|
-
return await context.authFetch<ServedDialog>(url)
|
|
136
|
-
} catch (error) {
|
|
137
|
-
reportFailure(error)
|
|
138
|
-
return null
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return async (url: string, run: ConfirmRun): Promise<boolean> => {
|
|
143
|
-
const dialog = await loadDialog(url)
|
|
144
|
-
if (!dialog) return false
|
|
145
|
-
return confirm({
|
|
146
|
-
...confirmOptionsOf(context, dialog),
|
|
147
|
-
onConfirm: async () => {
|
|
148
|
-
await run()
|
|
149
|
-
},
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
}
|