@fiduswriter/frontend 0.1.31 → 0.1.33
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/css/admin.css +23 -0
- package/css/colors.css +60 -0
- package/css/document_overview.css +15 -0
- package/css/document_template_admin.css +34 -0
- package/css/errorlist.css +14 -0
- package/css/feedback.css +136 -0
- package/css/figure.css +88 -0
- package/css/flatpage.css +44 -0
- package/css/fonts.css +398 -0
- package/css/forms.css +309 -0
- package/css/header_menu.css +114 -0
- package/css/inline_tools.css +84 -0
- package/css/prelogin.css +173 -0
- package/css/reset.css +175 -0
- package/css/show_profile.css +94 -0
- package/css/text.css +38 -0
- package/css/two_factor.css +247 -0
- package/css/user_template_manager.css +18 -0
- package/dist/css/admin.css +23 -0
- package/dist/css/bibliography/bibliography.css +180 -0
- package/dist/css/bibliography/colors.css +8 -0
- package/dist/css/bibliography/forms.css +102 -0
- package/dist/css/colors.css +60 -0
- package/dist/css/document/document.css +388 -0
- package/dist/css/document-template-editor/document_template_designer.css +198 -0
- package/dist/css/document_overview.css +15 -0
- package/dist/css/document_template_admin.css +34 -0
- package/dist/css/editor/access_rights_dialog.css +75 -0
- package/dist/css/editor/carets.css +17 -0
- package/dist/css/editor/chat.css +70 -0
- package/dist/css/editor/citation_dialog.css +71 -0
- package/dist/css/editor/colors.css +97 -0
- package/dist/css/editor/contributors.css +13 -0
- package/dist/css/editor/document.css +286 -0
- package/dist/css/editor/dot_menu.css +42 -0
- package/dist/css/editor/e2ee.css +331 -0
- package/dist/css/editor/editor.css +1484 -0
- package/dist/css/editor/footnotes.css +81 -0
- package/dist/css/editor/margin_boxes.css +514 -0
- package/dist/css/editor/merge.css +197 -0
- package/dist/css/editor/review.css +7 -0
- package/dist/css/editor/table.css +13 -0
- package/dist/css/editor/tags.css +36 -0
- package/dist/css/editor/tracking.css +63 -0
- package/dist/css/errorlist.css +14 -0
- package/dist/css/feedback.css +136 -0
- package/dist/css/figure.css +88 -0
- package/dist/css/flatpage.css +44 -0
- package/dist/css/fonts.css +398 -0
- package/dist/css/forms.css +309 -0
- package/dist/css/fwtoolkit/add_remove_dialog.css +18 -0
- package/dist/css/fwtoolkit/alerts.css +72 -0
- package/dist/css/fwtoolkit/buttons.css +373 -0
- package/dist/css/fwtoolkit/checkable_list.css +34 -0
- package/dist/css/fwtoolkit/colors.css +119 -0
- package/dist/css/fwtoolkit/common.css +196 -0
- package/dist/css/fwtoolkit/content_menu.css +105 -0
- package/dist/css/fwtoolkit/data_table.css +279 -0
- package/dist/css/fwtoolkit/dialog.css +214 -0
- package/dist/css/fwtoolkit/dialog_table.css +125 -0
- package/dist/css/fwtoolkit/drop_up.css +89 -0
- package/dist/css/fwtoolkit/faq_dialog.css +16 -0
- package/dist/css/fwtoolkit/file_selector.css +25 -0
- package/dist/css/fwtoolkit/forms.css +120 -0
- package/dist/css/fwtoolkit/fwtoolkit.css +2683 -0
- package/dist/css/fwtoolkit/inline_tools.css +84 -0
- package/dist/css/fwtoolkit/input_list.css +33 -0
- package/dist/css/fwtoolkit/loader.css +38 -0
- package/dist/css/fwtoolkit/overview_menu.css +194 -0
- package/dist/css/fwtoolkit/progress_task.css +140 -0
- package/dist/css/fwtoolkit/pulldown.css +118 -0
- package/dist/css/fwtoolkit/pulldown_menu.css +47 -0
- package/dist/css/fwtoolkit/two_pane_selector.css +51 -0
- package/dist/css/fwtoolkit/type_switch.css +81 -0
- package/dist/css/fwtoolkit/ui_tabs.css +65 -0
- package/dist/css/header_menu.css +114 -0
- package/dist/css/image-manager/dialog_usermedia.css +8 -0
- package/dist/css/inline_tools.css +84 -0
- package/dist/css/manifest.json +68 -0
- package/dist/css/prelogin.css +173 -0
- package/dist/css/reset.css +175 -0
- package/dist/css/show_profile.css +94 -0
- package/dist/css/text.css +38 -0
- package/dist/css/two_factor.css +247 -0
- package/dist/css/user_template_manager.css +18 -0
- package/dist/i18n/index.d.ts +49 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +136 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/static/fonts/document/Cardo-Bold.woff +0 -0
- package/dist/static/fonts/document/Cardo-Italic.woff +0 -0
- package/dist/static/fonts/document/Cardo-Regular.woff +0 -0
- package/dist/static/fonts/document/CrimsonText-Bold.woff +0 -0
- package/dist/static/fonts/document/CrimsonText-BoldItalic.woff +0 -0
- package/dist/static/fonts/document/CrimsonText-Italic.woff +0 -0
- package/dist/static/fonts/document/CrimsonText-Roman.woff +0 -0
- package/dist/static/fonts/document/Lobster-1.4.woff +0 -0
- package/dist/static/fonts/document/NoticiaText-Bold.woff +0 -0
- package/dist/static/fonts/document/NoticiaText-BoldItalic.woff +0 -0
- package/dist/static/fonts/document/NoticiaText-Italic.woff +0 -0
- package/dist/static/fonts/document/NoticiaText-Regular.woff +0 -0
- package/dist/static/fonts/document/OpenSans-Bold.woff +0 -0
- package/dist/static/fonts/document/OpenSans-Regular.woff +0 -0
- package/dist/static/fonts/document/SourceSansPro-Bold.woff +0 -0
- package/dist/static/fonts/lato/lato-300.woff2 +0 -0
- package/dist/static/fonts/lato/lato-400.woff2 +0 -0
- package/dist/static/fonts/lato/lato-700.woff2 +0 -0
- package/dist/static/fonts/lato/lato-900.woff2 +0 -0
- package/dist/static/fonts/lato/lato-ext-300.woff2 +0 -0
- package/dist/static/fonts/lato/lato-ext-400.woff2 +0 -0
- package/dist/static/fonts/lato/lato-ext-700.woff2 +0 -0
- package/dist/static/fonts/lato/lato-ext-900.woff2 +0 -0
- package/dist/static/fonts/lato/lato-ext-italic-400.woff2 +0 -0
- package/dist/static/fonts/lato/lato-italic-400.woff2 +0 -0
- package/dist/static/fonts/roboto/roboto-300.woff2 +0 -0
- package/dist/static/fonts/roboto/roboto-700.woff2 +0 -0
- package/dist/static/img/accept_change.avif +0 -0
- package/dist/static/img/default_avatar.avif +0 -0
- package/dist/static/img/error.avif +0 -0
- package/dist/static/img/favicon.avif +0 -0
- package/dist/static/img/fidus_face.avif +0 -0
- package/dist/static/img/free_star.avif +0 -0
- package/dist/static/img/icon_192.avif +0 -0
- package/dist/static/img/icon_512.avif +0 -0
- package/dist/static/ogg/chat_notification.ogg +0 -0
- package/dist/static/svg/icon.svg +211 -0
- package/locale/ar/messages.json +359 -0
- package/locale/bg/messages.json +359 -0
- package/locale/cs/messages.json +359 -0
- package/locale/da/messages.json +359 -0
- package/locale/de/messages.json +359 -0
- package/locale/en/messages.json +359 -0
- package/locale/en_US/messages.json +359 -0
- package/locale/es/messages.json +359 -0
- package/locale/fr/messages.json +359 -0
- package/locale/it/messages.json +359 -0
- package/locale/ja/messages.json +359 -0
- package/locale/ko/messages.json +359 -0
- package/locale/nb/messages.json +359 -0
- package/locale/nl/messages.json +359 -0
- package/locale/pl/messages.json +359 -0
- package/locale/pt_BR/messages.json +359 -0
- package/locale/pt_PT/messages.json +359 -0
- package/locale/ru/messages.json +359 -0
- package/locale/sv/messages.json +359 -0
- package/locale/tr/messages.json +359 -0
- package/locale/zh_Hans/messages.json +359 -0
- package/package.json +76 -12
- package/scripts/aggregate-assets.js +260 -0
- package/scripts/compile-i18n.js +114 -0
- package/scripts/deploy-pages.sh +31 -0
- package/scripts/extract-fwtoolkit-i18n.js +230 -0
- package/scripts/extract-i18n-generic.js +278 -0
- package/scripts/split-translations.js +304 -0
- package/src/i18n/index.ts +165 -0
- package/static/fonts/lato/lato-300.woff2 +0 -0
- package/static/fonts/lato/lato-400.woff2 +0 -0
- package/static/fonts/lato/lato-700.woff2 +0 -0
- package/static/fonts/lato/lato-900.woff2 +0 -0
- package/static/fonts/lato/lato-ext-300.woff2 +0 -0
- package/static/fonts/lato/lato-ext-400.woff2 +0 -0
- package/static/fonts/lato/lato-ext-700.woff2 +0 -0
- package/static/fonts/lato/lato-ext-900.woff2 +0 -0
- package/static/fonts/lato/lato-ext-italic-400.woff2 +0 -0
- package/static/fonts/lato/lato-italic-400.woff2 +0 -0
- package/static/fonts/roboto/roboto-300.woff2 +0 -0
- package/static/fonts/roboto/roboto-700.woff2 +0 -0
- package/static/img/default_avatar.avif +0 -0
- package/static/img/error.avif +0 -0
- package/static/img/favicon.avif +0 -0
- package/static/img/fidus_face.avif +0 -0
- package/static/img/free_star.avif +0 -0
- package/static/img/icon_192.avif +0 -0
- package/static/img/icon_512.avif +0 -0
- package/static/svg/icon.svg +211 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* aggregate-assets.js
|
|
5
|
+
*
|
|
6
|
+
* Aggregates CSS and static assets from @fiduswriter/frontend and all
|
|
7
|
+
* its sub-dependencies into dist/css/ and dist/static/.
|
|
8
|
+
*
|
|
9
|
+
* This script is called during @fiduswriter/frontend's postinstall so
|
|
10
|
+
* that consumers (the main Django app, alternative backends) can copy
|
|
11
|
+
* everything from a single location.
|
|
12
|
+
*
|
|
13
|
+
* Usage: node scripts/aggregate-assets.js
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "node:fs"
|
|
17
|
+
import { cpSync, readdirSync } from "node:fs"
|
|
18
|
+
import { join, dirname, relative } from "node:path"
|
|
19
|
+
import { fileURLToPath } from "node:url"
|
|
20
|
+
|
|
21
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
22
|
+
const root = join(__dirname, "..")
|
|
23
|
+
const dist = join(root, "dist")
|
|
24
|
+
const distCss = join(dist, "css")
|
|
25
|
+
const distStatic = join(dist, "static")
|
|
26
|
+
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Helpers
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
/** Ensure a directory exists (mkdir -p). */
|
|
32
|
+
function ensureDir(dir) {
|
|
33
|
+
if (!existsSync(dir)) {
|
|
34
|
+
mkdirSync(dir, { recursive: true })
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Recursively copy a directory.
|
|
40
|
+
* @param {string} src
|
|
41
|
+
* @param {string} dest
|
|
42
|
+
*/
|
|
43
|
+
function copyDir(src, dest) {
|
|
44
|
+
if (!existsSync(src)) {
|
|
45
|
+
console.warn(` (skip: source not found) ${src}`)
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
ensureDir(dirname(dest))
|
|
49
|
+
cpSync(src, dest, { recursive: true })
|
|
50
|
+
const count = readdirSync(src, { recursive: true }).filter(
|
|
51
|
+
(f) => !f.endsWith("/")
|
|
52
|
+
).length
|
|
53
|
+
console.log(` copied ${count} files: ${relative(root, src)} → ${relative(root, dest)}`)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Read a dependency's package.json relative to node_modules.
|
|
58
|
+
* @param {string} pkgName e.g. "fwtoolkit" or "@fiduswriter/editor"
|
|
59
|
+
* @returns {object|null}
|
|
60
|
+
*/
|
|
61
|
+
function readDepPackage(pkgName) {
|
|
62
|
+
const path = join(root, "node_modules", pkgName, "package.json")
|
|
63
|
+
if (!existsSync(path)) return null
|
|
64
|
+
return JSON.parse(readFileSync(path, "utf8"))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// Step 1a — Copy frontend's own CSS
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
console.log("Step 1a: Copying @fiduswriter/frontend CSS...")
|
|
71
|
+
|
|
72
|
+
copyDir(join(root, "css"), distCss)
|
|
73
|
+
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// Step 1b — Copy frontend's static assets (fonts, images, svg)
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
console.log("Step 1b: Copying @fiduswriter/frontend static assets...")
|
|
78
|
+
|
|
79
|
+
if (existsSync(join(root, "static"))) {
|
|
80
|
+
copyDir(join(root, "static"), distStatic)
|
|
81
|
+
} else {
|
|
82
|
+
console.log(" (no static/ directory)")
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
// Step 1c — Copy editor's static assets (fonts, images, ogg)
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
console.log("Step 1c: Copying @fiduswriter/editor static assets...")
|
|
89
|
+
|
|
90
|
+
const editorStatic = join(root, "node_modules", "@fiduswriter/editor", "static")
|
|
91
|
+
if (existsSync(editorStatic)) {
|
|
92
|
+
copyDir(editorStatic, distStatic)
|
|
93
|
+
} else {
|
|
94
|
+
console.log(" (not found)")
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
// Step 2 — Copy CSS from sub-dependencies
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
console.log("\nStep 2: Copying sub-dependency CSS...")
|
|
101
|
+
|
|
102
|
+
/** @type {{name: string, cssDir: string, destDir: string}[]} */
|
|
103
|
+
const subDeps = [
|
|
104
|
+
{ name: "fwtoolkit", cssDir: "css", destDir: "fwtoolkit" },
|
|
105
|
+
{ name: "@fiduswriter/editor", cssDir: "css", destDir: "editor" },
|
|
106
|
+
{
|
|
107
|
+
name: "@fiduswriter/bibliography-manager",
|
|
108
|
+
cssDir: "css",
|
|
109
|
+
destDir: "bibliography",
|
|
110
|
+
},
|
|
111
|
+
{ name: "@fiduswriter/image-manager", cssDir: "css", destDir: "image-manager" },
|
|
112
|
+
{
|
|
113
|
+
name: "@fiduswriter/document-template-editor",
|
|
114
|
+
cssDir: "css",
|
|
115
|
+
destDir: "document-template-editor",
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: "@fiduswriter/document",
|
|
119
|
+
cssDir: "src/css",
|
|
120
|
+
destDir: "document",
|
|
121
|
+
},
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
for (const dep of subDeps) {
|
|
125
|
+
const src = join(root, "node_modules", dep.name, dep.cssDir)
|
|
126
|
+
const dest = join(distCss, dep.destDir)
|
|
127
|
+
if (!existsSync(src)) {
|
|
128
|
+
console.log(` ${dep.name}: skipped (not found at ${src})`)
|
|
129
|
+
continue
|
|
130
|
+
}
|
|
131
|
+
console.log(` ${dep.name}:`)
|
|
132
|
+
copyDir(src, dest)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ---------------------------------------------------------------------------
|
|
136
|
+
// Step 3 — Generate CSS manifest from package declarations
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
138
|
+
console.log("\nStep 3: Generating CSS manifest...")
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @typedef {Object} CssDecl
|
|
142
|
+
* @property {string[]} fwtoolkit
|
|
143
|
+
* @property {{additive: string[], component: string[]}} own
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Read the fiduswriter.css declaration from a package.
|
|
148
|
+
* @param {string} pkgName
|
|
149
|
+
* @returns {CssDecl|null}
|
|
150
|
+
*/
|
|
151
|
+
function readCssDecl(pkgName) {
|
|
152
|
+
const pkg = readDepPackage(pkgName)
|
|
153
|
+
if (!pkg) return null
|
|
154
|
+
const decl = pkg?.fiduswriter?.css
|
|
155
|
+
if (!decl) return null
|
|
156
|
+
return decl
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** @type {Object<string, string[]>} */
|
|
160
|
+
const manifest = {
|
|
161
|
+
reset: [],
|
|
162
|
+
tokens: [],
|
|
163
|
+
typography: [],
|
|
164
|
+
components: [],
|
|
165
|
+
additive: [],
|
|
166
|
+
chrome: [],
|
|
167
|
+
editor: [],
|
|
168
|
+
packages: [],
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Layer 0: Reset
|
|
172
|
+
manifest.reset.push("@fiduswriter/frontend/css/reset.css")
|
|
173
|
+
|
|
174
|
+
// Layer 1: Tokens (fwtoolkit colors base)
|
|
175
|
+
manifest.tokens.push("fwtoolkit/css/colors.css")
|
|
176
|
+
|
|
177
|
+
// Layer 2: Typography (frontend fonts/text)
|
|
178
|
+
manifest.typography.push(
|
|
179
|
+
"@fiduswriter/frontend/css/fonts.css",
|
|
180
|
+
"@fiduswriter/frontend/css/text.css"
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
// Layer 3: All fwtoolkit component CSS (used by the full SPA)
|
|
184
|
+
const allFwtCss = readdirSync(join(root, "node_modules", "fwtoolkit", "css")).filter(
|
|
185
|
+
(f) => f.endsWith(".css")
|
|
186
|
+
)
|
|
187
|
+
// Remove colors.css (already in tokens), common.css (goes in components)
|
|
188
|
+
const fwtComponents = allFwtCss
|
|
189
|
+
.filter((f) => f !== "colors.css" && f !== "fwtoolkit.css")
|
|
190
|
+
.map((f) => `fwtoolkit/css/${f}`)
|
|
191
|
+
manifest.components.push(...fwtComponents)
|
|
192
|
+
|
|
193
|
+
// Layer 4: Additive overrides from all packages
|
|
194
|
+
const additivePackages = [
|
|
195
|
+
["@fiduswriter/frontend", "frontend"],
|
|
196
|
+
["@fiduswriter/editor", "editor"],
|
|
197
|
+
["@fiduswriter/bibliography-manager", "bibliography"],
|
|
198
|
+
]
|
|
199
|
+
for (const [pkgName] of additivePackages) {
|
|
200
|
+
const decl = readCssDecl(pkgName)
|
|
201
|
+
if (decl?.own?.additive) {
|
|
202
|
+
for (const f of decl.own.additive) {
|
|
203
|
+
manifest.additive.push(
|
|
204
|
+
pkgName === "@fiduswriter/frontend"
|
|
205
|
+
? `@fiduswriter/frontend/css/${f}`
|
|
206
|
+
: `${pkgName}/css/${f}`
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Layer 5: SPA Chrome (frontend component CSS)
|
|
213
|
+
const frontendDecl = readCssDecl("@fiduswriter/frontend")
|
|
214
|
+
if (frontendDecl?.own?.component) {
|
|
215
|
+
for (const f of frontendDecl.own.component) {
|
|
216
|
+
manifest.chrome.push(`@fiduswriter/frontend/css/${f}`)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Layer 6: Editor component CSS
|
|
221
|
+
const editorDecl = readCssDecl("@fiduswriter/editor")
|
|
222
|
+
if (editorDecl?.own?.component) {
|
|
223
|
+
for (const f of editorDecl.own.component) {
|
|
224
|
+
manifest.editor.push(`@fiduswriter/editor/css/${f}`)
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Layer 7: Other packages
|
|
229
|
+
const otherPackages = [
|
|
230
|
+
["@fiduswriter/bibliography-manager", "bibliography"],
|
|
231
|
+
["@fiduswriter/image-manager", "image-manager"],
|
|
232
|
+
["@fiduswriter/document-template-editor", "document-template-editor"],
|
|
233
|
+
]
|
|
234
|
+
for (const [pkgName] of otherPackages) {
|
|
235
|
+
const decl = readCssDecl(pkgName)
|
|
236
|
+
if (decl?.own?.component) {
|
|
237
|
+
for (const f of decl.own.component) {
|
|
238
|
+
manifest.packages.push(`${pkgName}/css/${f}`)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Write manifest
|
|
244
|
+
const manifestPath = join(distCss, "manifest.json")
|
|
245
|
+
ensureDir(dirname(manifestPath))
|
|
246
|
+
writeFileSync(manifestPath, JSON.stringify({ layers: manifest }, null, 2) + "\n")
|
|
247
|
+
console.log(` written: ${relative(root, manifestPath)}`)
|
|
248
|
+
|
|
249
|
+
// ---------------------------------------------------------------------------
|
|
250
|
+
// Step 4 — Summary
|
|
251
|
+
// ---------------------------------------------------------------------------
|
|
252
|
+
console.log("\nAggregation complete.")
|
|
253
|
+
console.log(`Output: ${relative(root, distCss)}/`)
|
|
254
|
+
console.log(`Manifest: ${relative(root, manifestPath)}`)
|
|
255
|
+
|
|
256
|
+
// Count total CSS files
|
|
257
|
+
const allCss = readdirSync(distCss, { recursive: true }).filter(
|
|
258
|
+
(f) => f.endsWith(".css")
|
|
259
|
+
)
|
|
260
|
+
console.log(`Total CSS files: ${allCss.length}`)
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* compile-i18n.js
|
|
5
|
+
*
|
|
6
|
+
* Compiles .po translation files to .json catalog files.
|
|
7
|
+
*
|
|
8
|
+
* Each package ships .po files in locale/<lang>/LC_MESSAGES/messages.po.
|
|
9
|
+
* This script reads them and writes locale/<lang>/messages.json.
|
|
10
|
+
*
|
|
11
|
+
* The JSON format is a flat msgid → msgstr map, with a special ""
|
|
12
|
+
* entry containing metadata (language, plural-forms).
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* node scripts/compile-i18n.js # compile all languages
|
|
16
|
+
* node scripts/compile-i18n.js de fr # compile specific languages
|
|
17
|
+
*
|
|
18
|
+
* Requires: gettext-parser (npm install --save-dev gettext-parser)
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { readFileSync, writeFileSync, mkdirSync, readdirSync, existsSync } from "node:fs"
|
|
22
|
+
import { join, dirname } from "node:path"
|
|
23
|
+
import { fileURLToPath } from "node:url"
|
|
24
|
+
|
|
25
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
26
|
+
const root = join(__dirname, "..")
|
|
27
|
+
const localeDir = join(root, "locale")
|
|
28
|
+
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Helpers
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
let parsePo
|
|
34
|
+
try {
|
|
35
|
+
const gettextParser = await import("gettext-parser")
|
|
36
|
+
parsePo = gettextParser.po?.parse || gettextParser.default?.po?.parse || gettextParser.parse
|
|
37
|
+
} catch {
|
|
38
|
+
console.error(
|
|
39
|
+
"gettext-parser not found. Install it with:\n npm install --save-dev gettext-parser"
|
|
40
|
+
)
|
|
41
|
+
process.exit(1)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function ensureDir(dir) {
|
|
45
|
+
if (!existsSync(dir)) {
|
|
46
|
+
mkdirSync(dir, { recursive: true })
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Main
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
const langs = process.argv.slice(2)
|
|
55
|
+
const allLangs = langs.length > 0
|
|
56
|
+
? langs
|
|
57
|
+
: readdirSync(localeDir, { withFileTypes: true })
|
|
58
|
+
.filter((e) => e.isDirectory())
|
|
59
|
+
.map((e) => e.name)
|
|
60
|
+
|
|
61
|
+
let total = 0
|
|
62
|
+
|
|
63
|
+
for (const lang of allLangs) {
|
|
64
|
+
const poFile = join(localeDir, lang, "LC_MESSAGES", "messages.po")
|
|
65
|
+
if (!existsSync(poFile)) {
|
|
66
|
+
console.log(` ${lang}: no messages.po found, skipping`)
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const poContent = readFileSync(poFile, "utf8")
|
|
71
|
+
const parsed = parsePo(poContent)
|
|
72
|
+
|
|
73
|
+
/** @type {Record<string, string>} */
|
|
74
|
+
const catalog = {}
|
|
75
|
+
|
|
76
|
+
// Extract metadata
|
|
77
|
+
const headers = parsed.headers || {}
|
|
78
|
+
catalog[""] = [
|
|
79
|
+
headers["language"] || lang,
|
|
80
|
+
headers["plural-forms"] || "",
|
|
81
|
+
].filter(Boolean).join("; ")
|
|
82
|
+
|
|
83
|
+
// Extract translations
|
|
84
|
+
const translations = parsed.translations || {}
|
|
85
|
+
for (const [, entries] of Object.entries(translations)) {
|
|
86
|
+
for (const [msgid, entry] of Object.entries(entries)) {
|
|
87
|
+
if (!msgid) continue // skip header entry
|
|
88
|
+
const msgstr = entry.msgstr
|
|
89
|
+
if (Array.isArray(msgstr)) {
|
|
90
|
+
catalog[msgid] = msgstr.join("\x00")
|
|
91
|
+
} else if (msgstr) {
|
|
92
|
+
catalog[msgid] = msgstr
|
|
93
|
+
}
|
|
94
|
+
// Plural forms
|
|
95
|
+
if (entry.msgid_plural) {
|
|
96
|
+
const key = `${msgid}\x00${entry.msgid_plural}`
|
|
97
|
+
catalog[key] = Array.isArray(msgstr)
|
|
98
|
+
? msgstr.join("\x00")
|
|
99
|
+
: msgstr || ""
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Write JSON
|
|
105
|
+
const jsonFile = join(localeDir, lang, "messages.json")
|
|
106
|
+
ensureDir(dirname(jsonFile))
|
|
107
|
+
writeFileSync(jsonFile, JSON.stringify(catalog, null, 2) + "\n")
|
|
108
|
+
|
|
109
|
+
const count = Object.keys(catalog).length - (catalog[""] ? 1 : 0)
|
|
110
|
+
console.log(` ${lang}: ${count} strings → ${jsonFile}`)
|
|
111
|
+
total += count
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
console.log(`\nCompiled ${allLangs.length} languages, ${total} total strings.`)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -e
|
|
3
|
+
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
|
4
|
+
cd "$ROOT"
|
|
5
|
+
|
|
6
|
+
echo "Building @fiduswriter/common..."
|
|
7
|
+
npm run build
|
|
8
|
+
|
|
9
|
+
echo "Preparing pages build..."
|
|
10
|
+
BUILD_DIR="$ROOT/.pages-build"
|
|
11
|
+
rm -rf "$BUILD_DIR"
|
|
12
|
+
mkdir "$BUILD_DIR"
|
|
13
|
+
|
|
14
|
+
cp -r "$ROOT/demo/"* "$BUILD_DIR/"
|
|
15
|
+
cp -r "$ROOT/dist" "$BUILD_DIR/"
|
|
16
|
+
cp "$ROOT/logo.svg" "$BUILD_DIR/" 2>/dev/null || true
|
|
17
|
+
|
|
18
|
+
cd "$BUILD_DIR"
|
|
19
|
+
git init
|
|
20
|
+
git checkout -b pages
|
|
21
|
+
git add .
|
|
22
|
+
git commit -m "Deploy @fiduswriter/common to Codeberg Pages"
|
|
23
|
+
|
|
24
|
+
REMOTE=$(cd "$ROOT" && git remote get-url origin)
|
|
25
|
+
echo "Pushing to $REMOTE pages branch..."
|
|
26
|
+
git remote add origin "$REMOTE"
|
|
27
|
+
git push -f origin pages
|
|
28
|
+
|
|
29
|
+
cd "$ROOT"
|
|
30
|
+
rm -rf "$BUILD_DIR"
|
|
31
|
+
echo "Done. Available at https://fiduswriter.codeberg.page/common/"
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* extract-fwtoolkit-i18n.js
|
|
5
|
+
*
|
|
6
|
+
* Scans fwtoolkit/src/ for gettext() calls, extracts unique msgids,
|
|
7
|
+
* looks up translations from the Django djangojs.po files, and writes
|
|
8
|
+
* per-language messages.po files into fwtoolkit/locale/.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* node scripts/extract-fwtoolkit-i18n.js <path-to-django-locale> <path-to-fwtoolkit>
|
|
12
|
+
*
|
|
13
|
+
* Example:
|
|
14
|
+
* node scripts/extract-fwtoolkit-i18n.js \
|
|
15
|
+
* ../../fiduswriter/fiduswriter/locale \
|
|
16
|
+
* ../../fwtoolkit
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { readFileSync, writeFileSync, mkdirSync, readdirSync, existsSync } from "node:fs"
|
|
20
|
+
import { join } from "node:path"
|
|
21
|
+
|
|
22
|
+
const djangoLocalePath = process.argv[2]
|
|
23
|
+
const fwtoolkitPath = process.argv[3]
|
|
24
|
+
|
|
25
|
+
if (!djangoLocalePath || !fwtoolkitPath) {
|
|
26
|
+
console.error("Usage: node extract-fwtoolkit-i18n.js <django-locale-dir> <fwtoolkit-dir>")
|
|
27
|
+
process.exit(1)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// Step 1 — Scan fwtoolkit/src/ for gettext() calls
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
/** Simple regex: matches gettext("...") with optional whitespace.
|
|
35
|
+
* Does NOT handle gettext(msgid_variable) or template literals. */
|
|
36
|
+
const GETTEXT_RE = /gettext\s*\(\s*["']([^"']+)["']\s*\)/g
|
|
37
|
+
|
|
38
|
+
/** @type {Set<string>} */
|
|
39
|
+
const msgids = new Set()
|
|
40
|
+
|
|
41
|
+
function scanDir(dir) {
|
|
42
|
+
if (!existsSync(dir)) return
|
|
43
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
44
|
+
const full = join(dir, entry.name)
|
|
45
|
+
if (entry.isDirectory() && entry.name !== "node_modules" && !entry.name.startsWith(".")) {
|
|
46
|
+
scanDir(full)
|
|
47
|
+
} else if (entry.isFile() && (entry.name.endsWith(".ts") || entry.name.endsWith(".js"))) {
|
|
48
|
+
const content = readFileSync(full, "utf8")
|
|
49
|
+
let match
|
|
50
|
+
while ((match = GETTEXT_RE.exec(content)) !== null) {
|
|
51
|
+
msgids.add(match[1])
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
console.log(`Scanning ${fwtoolkitPath}/src/ for gettext() calls...`)
|
|
58
|
+
scanDir(join(fwtoolkitPath, "src"))
|
|
59
|
+
console.log(`Found ${msgids.size} unique msgids.\n`)
|
|
60
|
+
|
|
61
|
+
if (msgids.size === 0) {
|
|
62
|
+
console.log("No gettext() calls found. Exiting.")
|
|
63
|
+
process.exit(0)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
// Step 2 — Look up translations from Django djangojs.po
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
const languages = readdirSync(djangoLocalePath, { withFileTypes: true })
|
|
71
|
+
.filter((e) => e.isDirectory())
|
|
72
|
+
.map((e) => e.name)
|
|
73
|
+
|
|
74
|
+
console.log(`Looking up translations in ${languages.length} languages...`)
|
|
75
|
+
|
|
76
|
+
let totalTranslated = 0
|
|
77
|
+
|
|
78
|
+
for (const lang of languages) {
|
|
79
|
+
const poFile = join(djangoLocalePath, lang, "LC_MESSAGES", "djangojs.po")
|
|
80
|
+
if (!existsSync(poFile)) continue
|
|
81
|
+
|
|
82
|
+
const poContent = readFileSync(poFile, "utf8")
|
|
83
|
+
|
|
84
|
+
// Build translation map from this language's djangojs.po
|
|
85
|
+
/** @type {Map<string, {msgstr: string, comment: string}>} */
|
|
86
|
+
const translationMap = new Map()
|
|
87
|
+
|
|
88
|
+
let currentMsgid = null
|
|
89
|
+
let currentComment = ""
|
|
90
|
+
for (const line of poContent.split("\n")) {
|
|
91
|
+
const trimmed = line.trim()
|
|
92
|
+
|
|
93
|
+
// Comment lines
|
|
94
|
+
if (trimmed.startsWith("#:")) {
|
|
95
|
+
if (currentMsgid === null) {
|
|
96
|
+
currentComment += line + "\n"
|
|
97
|
+
}
|
|
98
|
+
continue
|
|
99
|
+
}
|
|
100
|
+
if (trimmed.startsWith("#,") || trimmed.startsWith("#.") || trimmed.startsWith("#|")) {
|
|
101
|
+
if (currentMsgid === null) {
|
|
102
|
+
currentComment += line + "\n"
|
|
103
|
+
}
|
|
104
|
+
continue
|
|
105
|
+
}
|
|
106
|
+
if (trimmed.startsWith("#") && !trimmed.startsWith("#:")) {
|
|
107
|
+
continue
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// msgid line
|
|
111
|
+
if (trimmed.startsWith('msgid "')) {
|
|
112
|
+
currentMsgid = unescapePo(trimmed.slice(7, -1))
|
|
113
|
+
continue
|
|
114
|
+
}
|
|
115
|
+
if (trimmed.startsWith('msgid ')) {
|
|
116
|
+
currentMsgid = unescapePo(trimmed.slice(6))
|
|
117
|
+
continue
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// msgstr line — capture translation
|
|
121
|
+
if (trimmed.startsWith('msgstr "') && currentMsgid !== null) {
|
|
122
|
+
const msgstr = unescapePo(trimmed.slice(8, -1))
|
|
123
|
+
if (msgstr) {
|
|
124
|
+
translationMap.set(currentMsgid, {
|
|
125
|
+
msgstr,
|
|
126
|
+
comment: currentComment.trim(),
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
currentMsgid = null
|
|
130
|
+
currentComment = ""
|
|
131
|
+
continue
|
|
132
|
+
}
|
|
133
|
+
if (trimmed.startsWith('msgstr ') && currentMsgid !== null) {
|
|
134
|
+
const msgstr = unescapePo(trimmed.slice(7))
|
|
135
|
+
if (msgstr) {
|
|
136
|
+
translationMap.set(currentMsgid, {
|
|
137
|
+
msgstr,
|
|
138
|
+
comment: currentComment.trim(),
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
currentMsgid = null
|
|
142
|
+
currentComment = ""
|
|
143
|
+
continue
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Plural forms — skip for simplicity (fwtoolkit doesn't use ngettext)
|
|
147
|
+
if (trimmed.startsWith('msgid_plural') || trimmed.startsWith('msgstr[')) {
|
|
148
|
+
currentMsgid = null
|
|
149
|
+
currentComment = ""
|
|
150
|
+
continue
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Continuation of msgid
|
|
154
|
+
if (trimmed.startsWith('"') && currentMsgid !== null) {
|
|
155
|
+
currentMsgid += unescapePo(trimmed.slice(1, -1))
|
|
156
|
+
continue
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Build .po file content
|
|
161
|
+
const entries = []
|
|
162
|
+
for (const msgid of msgids) {
|
|
163
|
+
const translation = translationMap.get(msgid)
|
|
164
|
+
const msgstr = translation ? translation.msgstr : ""
|
|
165
|
+
const comment = translation ? translation.comment : ""
|
|
166
|
+
entries.push({ msgid, msgstr, comment })
|
|
167
|
+
|
|
168
|
+
if (msgstr) totalTranslated++
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Sort by msgid for stable output
|
|
172
|
+
entries.sort((a, b) => a.msgid.localeCompare(b.msgid))
|
|
173
|
+
|
|
174
|
+
const header = [
|
|
175
|
+
`# Translations for fwtoolkit`,
|
|
176
|
+
`# Language: ${lang}`,
|
|
177
|
+
`# Auto-generated by extract-fwtoolkit-i18n.js`,
|
|
178
|
+
`# Source: fwtoolkit/src/ (gettext() calls)`,
|
|
179
|
+
`#`,
|
|
180
|
+
`msgid ""`,
|
|
181
|
+
`msgstr ""`,
|
|
182
|
+
`"Content-Type: text/plain; charset=UTF-8\\n"`,
|
|
183
|
+
`"Language: ${lang}\\n"`,
|
|
184
|
+
`"Plural-Forms: nplurals=2; plural=(n != 1);\\n"`,
|
|
185
|
+
``,
|
|
186
|
+
].join("\n")
|
|
187
|
+
|
|
188
|
+
const body = entries
|
|
189
|
+
.map((e) => {
|
|
190
|
+
let lines = ""
|
|
191
|
+
if (e.comment) lines += e.comment + "\n"
|
|
192
|
+
lines += `msgid "${escapePo(e.msgid)}"\n`
|
|
193
|
+
lines += `msgstr "${escapePo(e.msgstr)}"\n`
|
|
194
|
+
return lines + "\n"
|
|
195
|
+
})
|
|
196
|
+
.join("")
|
|
197
|
+
|
|
198
|
+
const langDir = join(fwtoolkitPath, "locale", lang, "LC_MESSAGES")
|
|
199
|
+
mkdirSync(langDir, { recursive: true })
|
|
200
|
+
const outFile = join(langDir, "messages.po")
|
|
201
|
+
writeFileSync(outFile, header + body, "utf8")
|
|
202
|
+
|
|
203
|
+
const translated = entries.filter((e) => e.msgstr).length
|
|
204
|
+
console.log(` ${lang}: ${entries.length} entries, ${translated} translated`)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
console.log(`\nTotal translated strings across all languages: ${totalTranslated}`)
|
|
208
|
+
console.log("Done.")
|
|
209
|
+
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
// Helpers
|
|
212
|
+
// ---------------------------------------------------------------------------
|
|
213
|
+
|
|
214
|
+
function escapePo(s) {
|
|
215
|
+
return s
|
|
216
|
+
.replace(/\\/g, "\\\\")
|
|
217
|
+
.replace(/"/g, '\\"')
|
|
218
|
+
.replace(/\n/g, "\\n")
|
|
219
|
+
.replace(/\r/g, "\\r")
|
|
220
|
+
.replace(/\t/g, "\\t")
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function unescapePo(s) {
|
|
224
|
+
return s
|
|
225
|
+
.replace(/\\"/g, '"')
|
|
226
|
+
.replace(/\\n/g, "\n")
|
|
227
|
+
.replace(/\\r/g, "\r")
|
|
228
|
+
.replace(/\\t/g, "\t")
|
|
229
|
+
.replace(/\\\\/g, "\\")
|
|
230
|
+
}
|