@fiduswriter/frontend 0.1.31 → 0.1.32

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 (154) hide show
  1. package/css/admin.css +23 -0
  2. package/css/colors.css +60 -0
  3. package/css/document_overview.css +15 -0
  4. package/css/document_template_admin.css +34 -0
  5. package/css/errorlist.css +14 -0
  6. package/css/feedback.css +136 -0
  7. package/css/figure.css +88 -0
  8. package/css/flatpage.css +44 -0
  9. package/css/fonts.css +398 -0
  10. package/css/forms.css +309 -0
  11. package/css/header_menu.css +114 -0
  12. package/css/inline_tools.css +84 -0
  13. package/css/prelogin.css +173 -0
  14. package/css/reset.css +175 -0
  15. package/css/show_profile.css +94 -0
  16. package/css/text.css +38 -0
  17. package/css/two_factor.css +247 -0
  18. package/css/user_template_manager.css +18 -0
  19. package/dist/css/admin.css +23 -0
  20. package/dist/css/bibliography/bibliography.css +180 -0
  21. package/dist/css/bibliography/colors.css +8 -0
  22. package/dist/css/bibliography/forms.css +102 -0
  23. package/dist/css/colors.css +60 -0
  24. package/dist/css/document/document.css +388 -0
  25. package/dist/css/document-template-editor/document_template_designer.css +198 -0
  26. package/dist/css/document_overview.css +15 -0
  27. package/dist/css/document_template_admin.css +34 -0
  28. package/dist/css/editor/access_rights_dialog.css +75 -0
  29. package/dist/css/editor/carets.css +17 -0
  30. package/dist/css/editor/chat.css +70 -0
  31. package/dist/css/editor/citation_dialog.css +71 -0
  32. package/dist/css/editor/colors.css +97 -0
  33. package/dist/css/editor/contributors.css +13 -0
  34. package/dist/css/editor/document.css +286 -0
  35. package/dist/css/editor/dot_menu.css +42 -0
  36. package/dist/css/editor/e2ee.css +331 -0
  37. package/dist/css/editor/editor.css +1484 -0
  38. package/dist/css/editor/footnotes.css +81 -0
  39. package/dist/css/editor/margin_boxes.css +514 -0
  40. package/dist/css/editor/merge.css +197 -0
  41. package/dist/css/editor/review.css +7 -0
  42. package/dist/css/editor/table.css +13 -0
  43. package/dist/css/editor/tags.css +36 -0
  44. package/dist/css/editor/tracking.css +63 -0
  45. package/dist/css/errorlist.css +14 -0
  46. package/dist/css/feedback.css +136 -0
  47. package/dist/css/figure.css +88 -0
  48. package/dist/css/flatpage.css +44 -0
  49. package/dist/css/fonts.css +398 -0
  50. package/dist/css/forms.css +309 -0
  51. package/dist/css/fwtoolkit/add_remove_dialog.css +18 -0
  52. package/dist/css/fwtoolkit/alerts.css +72 -0
  53. package/dist/css/fwtoolkit/buttons.css +373 -0
  54. package/dist/css/fwtoolkit/checkable_list.css +34 -0
  55. package/dist/css/fwtoolkit/colors.css +119 -0
  56. package/dist/css/fwtoolkit/common.css +196 -0
  57. package/dist/css/fwtoolkit/content_menu.css +105 -0
  58. package/dist/css/fwtoolkit/data_table.css +279 -0
  59. package/dist/css/fwtoolkit/dialog.css +214 -0
  60. package/dist/css/fwtoolkit/dialog_table.css +125 -0
  61. package/dist/css/fwtoolkit/drop_up.css +89 -0
  62. package/dist/css/fwtoolkit/faq_dialog.css +16 -0
  63. package/dist/css/fwtoolkit/file_selector.css +25 -0
  64. package/dist/css/fwtoolkit/forms.css +120 -0
  65. package/dist/css/fwtoolkit/fwtoolkit.css +2683 -0
  66. package/dist/css/fwtoolkit/inline_tools.css +84 -0
  67. package/dist/css/fwtoolkit/input_list.css +33 -0
  68. package/dist/css/fwtoolkit/loader.css +38 -0
  69. package/dist/css/fwtoolkit/overview_menu.css +194 -0
  70. package/dist/css/fwtoolkit/progress_task.css +140 -0
  71. package/dist/css/fwtoolkit/pulldown.css +118 -0
  72. package/dist/css/fwtoolkit/pulldown_menu.css +47 -0
  73. package/dist/css/fwtoolkit/two_pane_selector.css +51 -0
  74. package/dist/css/fwtoolkit/type_switch.css +81 -0
  75. package/dist/css/fwtoolkit/ui_tabs.css +65 -0
  76. package/dist/css/header_menu.css +114 -0
  77. package/dist/css/image-manager/dialog_usermedia.css +8 -0
  78. package/dist/css/inline_tools.css +84 -0
  79. package/dist/css/manifest.json +68 -0
  80. package/dist/css/prelogin.css +173 -0
  81. package/dist/css/reset.css +175 -0
  82. package/dist/css/show_profile.css +94 -0
  83. package/dist/css/text.css +38 -0
  84. package/dist/css/two_factor.css +247 -0
  85. package/dist/css/user_template_manager.css +18 -0
  86. package/dist/i18n/index.d.ts +49 -0
  87. package/dist/i18n/index.d.ts.map +1 -0
  88. package/dist/i18n/index.js +136 -0
  89. package/dist/i18n/index.js.map +1 -0
  90. package/dist/static/fonts/document/Cardo-Bold.woff +0 -0
  91. package/dist/static/fonts/document/Cardo-Italic.woff +0 -0
  92. package/dist/static/fonts/document/Cardo-Regular.woff +0 -0
  93. package/dist/static/fonts/document/CrimsonText-Bold.woff +0 -0
  94. package/dist/static/fonts/document/CrimsonText-BoldItalic.woff +0 -0
  95. package/dist/static/fonts/document/CrimsonText-Italic.woff +0 -0
  96. package/dist/static/fonts/document/CrimsonText-Roman.woff +0 -0
  97. package/dist/static/fonts/document/Lobster-1.4.woff +0 -0
  98. package/dist/static/fonts/document/NoticiaText-Bold.woff +0 -0
  99. package/dist/static/fonts/document/NoticiaText-BoldItalic.woff +0 -0
  100. package/dist/static/fonts/document/NoticiaText-Italic.woff +0 -0
  101. package/dist/static/fonts/document/NoticiaText-Regular.woff +0 -0
  102. package/dist/static/fonts/document/OpenSans-Bold.woff +0 -0
  103. package/dist/static/fonts/document/OpenSans-Regular.woff +0 -0
  104. package/dist/static/fonts/document/SourceSansPro-Bold.woff +0 -0
  105. package/dist/static/fonts/lato/lato-300.woff2 +0 -0
  106. package/dist/static/fonts/lato/lato-400.woff2 +0 -0
  107. package/dist/static/fonts/lato/lato-700.woff2 +0 -0
  108. package/dist/static/fonts/lato/lato-900.woff2 +0 -0
  109. package/dist/static/fonts/lato/lato-ext-300.woff2 +0 -0
  110. package/dist/static/fonts/lato/lato-ext-400.woff2 +0 -0
  111. package/dist/static/fonts/lato/lato-ext-700.woff2 +0 -0
  112. package/dist/static/fonts/lato/lato-ext-900.woff2 +0 -0
  113. package/dist/static/fonts/lato/lato-ext-italic-400.woff2 +0 -0
  114. package/dist/static/fonts/lato/lato-italic-400.woff2 +0 -0
  115. package/dist/static/fonts/roboto/roboto-300.woff2 +0 -0
  116. package/dist/static/fonts/roboto/roboto-700.woff2 +0 -0
  117. package/dist/static/img/accept_change.avif +0 -0
  118. package/dist/static/img/default_avatar.avif +0 -0
  119. package/dist/static/img/error.avif +0 -0
  120. package/dist/static/img/favicon.avif +0 -0
  121. package/dist/static/img/fidus_face.avif +0 -0
  122. package/dist/static/img/free_star.avif +0 -0
  123. package/dist/static/img/icon_192.avif +0 -0
  124. package/dist/static/img/icon_512.avif +0 -0
  125. package/dist/static/ogg/chat_notification.ogg +0 -0
  126. package/dist/static/svg/icon.svg +211 -0
  127. package/package.json +74 -11
  128. package/scripts/aggregate-assets.js +260 -0
  129. package/scripts/compile-i18n.js +114 -0
  130. package/scripts/deploy-pages.sh +31 -0
  131. package/scripts/extract-fwtoolkit-i18n.js +230 -0
  132. package/scripts/extract-i18n-generic.js +278 -0
  133. package/scripts/split-translations.js +304 -0
  134. package/src/i18n/index.ts +165 -0
  135. package/static/fonts/lato/lato-300.woff2 +0 -0
  136. package/static/fonts/lato/lato-400.woff2 +0 -0
  137. package/static/fonts/lato/lato-700.woff2 +0 -0
  138. package/static/fonts/lato/lato-900.woff2 +0 -0
  139. package/static/fonts/lato/lato-ext-300.woff2 +0 -0
  140. package/static/fonts/lato/lato-ext-400.woff2 +0 -0
  141. package/static/fonts/lato/lato-ext-700.woff2 +0 -0
  142. package/static/fonts/lato/lato-ext-900.woff2 +0 -0
  143. package/static/fonts/lato/lato-ext-italic-400.woff2 +0 -0
  144. package/static/fonts/lato/lato-italic-400.woff2 +0 -0
  145. package/static/fonts/roboto/roboto-300.woff2 +0 -0
  146. package/static/fonts/roboto/roboto-700.woff2 +0 -0
  147. package/static/img/default_avatar.avif +0 -0
  148. package/static/img/error.avif +0 -0
  149. package/static/img/favicon.avif +0 -0
  150. package/static/img/fidus_face.avif +0 -0
  151. package/static/img/free_star.avif +0 -0
  152. package/static/img/icon_192.avif +0 -0
  153. package/static/img/icon_512.avif +0 -0
  154. package/static/svg/icon.svg +211 -0
@@ -0,0 +1,278 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * extract-i18n.js
5
+ *
6
+ * Scans src/ for gettext() calls, extracts unique msgids, looks up
7
+ * translations from a Django djangojs.po file (including obsolete #~ entries),
8
+ * and writes per-language messages.po into locale/.
9
+ *
10
+ * Usage:
11
+ * node scripts/extract-i18n.js <path-to-django-locale>
12
+ */
13
+
14
+ import { readFileSync, writeFileSync, mkdirSync, readdirSync, existsSync } from "node:fs"
15
+ import { join, dirname } from "node:path"
16
+ import { fileURLToPath } from "node:url"
17
+
18
+ const __dirname = dirname(fileURLToPath(import.meta.url))
19
+ const root = join(__dirname, "..")
20
+ const djangoLocalePath = process.argv[2]
21
+
22
+ if (!djangoLocalePath) {
23
+ console.error("Usage: node scripts/extract-i18n.js <django-locale-dir>")
24
+ process.exit(1)
25
+ }
26
+
27
+ const GETTEXT_RE = /gettext\s*\(\s*["']([^"']+)["']\s*\)/g
28
+
29
+ const msgids = new Set()
30
+
31
+ function scanDir(dir) {
32
+ if (!existsSync(dir)) return
33
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
34
+ const full = join(dir, entry.name)
35
+ if (entry.isDirectory() && entry.name !== "node_modules" && !entry.name.startsWith(".")) {
36
+ scanDir(full)
37
+ } else if (entry.isFile() && (entry.name.endsWith(".ts") || entry.name.endsWith(".js") || entry.name.endsWith(".mjs"))) {
38
+ const content = readFileSync(full, "utf8")
39
+ let match
40
+ while ((match = GETTEXT_RE.exec(content)) !== null) {
41
+ msgids.add(match[1])
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ console.log("Scanning src/ for gettext() calls...")
48
+ scanDir(join(root, "src"))
49
+ console.log(`Found ${msgids.size} unique msgids.\n`)
50
+
51
+ if (msgids.size === 0) {
52
+ console.log("No gettext() calls found.")
53
+ process.exit(0)
54
+ }
55
+
56
+ // Build translation maps from djangojs.po — including obsolete #~ entries
57
+ const languages = readdirSync(djangoLocalePath, { withFileTypes: true })
58
+ .filter((e) => e.isDirectory())
59
+ .map((e) => e.name)
60
+
61
+ console.log(`Looking up translations in ${languages.length} languages (including obsolete entries)...`)
62
+
63
+ let totalTranslated = 0
64
+
65
+ for (const lang of languages) {
66
+ const poFile = join(djangoLocalePath, lang, "LC_MESSAGES", "djangojs.po")
67
+ if (!existsSync(poFile)) continue
68
+
69
+ const poContent = readFileSync(poFile, "utf8")
70
+ const translationMap = new Map()
71
+
72
+ // Parse active entries
73
+ let currentMsgid = null
74
+ let currentComment = ""
75
+ for (const line of poContent.split("\n")) {
76
+ const trimmed = line.trim()
77
+ // Skip obsolete lines for active parsing
78
+ if (trimmed.startsWith("#~")) continue
79
+
80
+ if (trimmed.startsWith("#:")) {
81
+ if (currentMsgid === null) currentComment += line + "\n"
82
+ continue
83
+ }
84
+ if (trimmed.startsWith("#,") || trimmed.startsWith("#.") || trimmed.startsWith("#|")) {
85
+ if (currentMsgid === null) currentComment += line + "\n"
86
+ continue
87
+ }
88
+ if (trimmed.startsWith("#") && !trimmed.startsWith("#:")) continue
89
+ if (trimmed.startsWith('msgid "')) {
90
+ currentMsgid = unescapePo(trimmed.slice(7, -1))
91
+ continue
92
+ }
93
+ if (trimmed.startsWith("msgid ")) {
94
+ currentMsgid = unescapePo(trimmed.slice(6))
95
+ continue
96
+ }
97
+ if (trimmed.startsWith('msgstr "') && currentMsgid !== null) {
98
+ const msgstr = unescapePo(trimmed.slice(8, -1))
99
+ if (msgstr) translationMap.set(currentMsgid, { msgstr, comment: currentComment.trim() })
100
+ currentMsgid = null
101
+ currentComment = ""
102
+ continue
103
+ }
104
+ if (trimmed.startsWith("msgstr ") && currentMsgid !== null) {
105
+ const msgstr = unescapePo(trimmed.slice(7))
106
+ if (msgstr) translationMap.set(currentMsgid, { msgstr, comment: currentComment.trim() })
107
+ currentMsgid = null
108
+ currentComment = ""
109
+ continue
110
+ }
111
+ if (trimmed.startsWith("msgid_plural") || trimmed.startsWith("msgstr[")) {
112
+ currentMsgid = null
113
+ currentComment = ""
114
+ continue
115
+ }
116
+ if (trimmed.startsWith('"') && currentMsgid !== null) {
117
+ currentMsgid += unescapePo(trimmed.slice(1, -1))
118
+ }
119
+ }
120
+
121
+ // Also parse obsolete entries (#~ msgid ... #~ msgstr ...)
122
+ // State machine: null = awaiting entry, "msgid" = building msgid, "msgstr" = building msgstr
123
+ let obsState = null // null | "msgid" | "msgstr"
124
+ let obsMsgid = "" // accumulating msgid (may span multiple #~ "..." lines)
125
+ let obsMsgstr = "" // accumulating msgstr
126
+ let obsPrevMsgid = null
127
+
128
+ function saveObsolete() {
129
+ if (obsMsgid && obsMsgstr && !translationMap.has(obsMsgid)) {
130
+ translationMap.set(obsMsgid, { msgstr: obsMsgstr, comment: "" })
131
+ }
132
+ if (obsPrevMsgid && obsMsgstr && !translationMap.has(obsPrevMsgid)) {
133
+ translationMap.set(obsPrevMsgid, { msgstr: obsMsgstr, comment: "" })
134
+ }
135
+ }
136
+
137
+ for (const line of poContent.split("\n")) {
138
+ const trimmed = line.trim()
139
+
140
+ // ----------- start of obsolete msgid -----------
141
+ if (trimmed.startsWith('#~ msgid "')) {
142
+ saveObsolete() // save any previous entry
143
+ obsState = "msgid"
144
+ obsMsgid = unescapePo(trimmed.slice(10, -1))
145
+ obsMsgstr = ""
146
+ obsPrevMsgid = null
147
+ continue
148
+ }
149
+ // Also handle msgid without quotes (rare)
150
+ if (trimmed.startsWith("#~ msgid ") && !trimmed.startsWith('#~ msgid "')) {
151
+ saveObsolete()
152
+ obsState = "msgid"
153
+ obsMsgid = unescapePo(trimmed.slice(9))
154
+ obsMsgstr = ""
155
+ obsPrevMsgid = null
156
+ continue
157
+ }
158
+ // ----------- previous msgid marker -----------
159
+ if (trimmed.startsWith('#~| msgid "')) {
160
+ obsPrevMsgid = unescapePo(trimmed.slice(12, -1))
161
+ continue
162
+ }
163
+ // ----------- start of obsolete msgstr -----------
164
+ if (trimmed.startsWith('#~ msgstr "') && obsState === "msgid") {
165
+ obsState = "msgstr"
166
+ obsMsgstr = unescapePo(trimmed.slice(11, -1))
167
+ // If the msgid is non-empty and this is a single-line msgstr, save immediately
168
+ continue
169
+ }
170
+ if (trimmed.startsWith("#~ msgstr ") && obsState === "msgid" && !trimmed.startsWith('#~ msgstr "')) {
171
+ obsState = "msgstr"
172
+ obsMsgstr = unescapePo(trimmed.slice(10))
173
+ continue
174
+ }
175
+ // ----------- multi-line continuation -----------
176
+ if (trimmed.startsWith('#~ "') && obsState !== null) {
177
+ const fragment = unescapePo(trimmed.slice(4, -1))
178
+ if (obsState === "msgid") {
179
+ obsMsgid += fragment
180
+ } else if (obsState === "msgstr") {
181
+ obsMsgstr += fragment
182
+ }
183
+ continue
184
+ }
185
+ // ----------- end of entry (next #~ msgid or non-obsolete line) -----------
186
+ if (obsState === "msgstr" && (trimmed.startsWith('#~ msgid') || !trimmed.startsWith("#~"))) {
187
+ saveObsolete()
188
+ obsState = null
189
+ obsMsgid = ""
190
+ obsMsgstr = ""
191
+ }
192
+ }
193
+ // Save any trailing entry
194
+ if (obsState === "msgstr") {
195
+ saveObsolete()
196
+ }
197
+
198
+ // Build entries — merge existing translations from the target .po file
199
+ // if it already exists, so translations added by translate_all.py or
200
+ // manual editing are preserved across re-extractions.
201
+ const existingPo = join(root, "locale", lang, "LC_MESSAGES", "messages.po")
202
+ const existingTranslations = new Map()
203
+ if (existsSync(existingPo)) {
204
+ const existingContent = readFileSync(existingPo, "utf8")
205
+ let curMsgid = null
206
+ for (const line of existingContent.split("\n")) {
207
+ const trimmed = line.trim()
208
+ if (trimmed.startsWith('msgid "')) {
209
+ curMsgid = unescapePo(trimmed.slice(7, -1))
210
+ continue
211
+ }
212
+ if (trimmed.startsWith('msgstr "') && curMsgid !== null) {
213
+ const ms = unescapePo(trimmed.slice(8, -1))
214
+ if (ms) existingTranslations.set(curMsgid, ms)
215
+ curMsgid = null
216
+ continue
217
+ }
218
+ if (trimmed.startsWith('"') && curMsgid !== null) {
219
+ curMsgid += unescapePo(trimmed.slice(1, -1))
220
+ }
221
+ }
222
+ }
223
+
224
+ const entries = []
225
+ for (const msgid of msgids) {
226
+ // Prefer existing translation over djangojs.po lookup (no synthetic comment)
227
+ const existing = existingTranslations.get(msgid)
228
+ const t = existing ? { msgstr: existing, comment: "" } : translationMap.get(msgid)
229
+ entries.push({
230
+ msgid,
231
+ msgstr: t ? t.msgstr : "",
232
+ comment: t ? t.comment : "",
233
+ })
234
+ if (t?.msgstr) totalTranslated++
235
+ }
236
+ entries.sort((a, b) => a.msgid.localeCompare(b.msgid))
237
+
238
+ const header = [
239
+ `# Translations for this package`,
240
+ `# Language: ${lang}`,
241
+ "# Auto-generated by extract-i18n.js",
242
+ "#",
243
+ 'msgid ""',
244
+ 'msgstr ""',
245
+ '"Content-Type: text/plain; charset=UTF-8\\n"',
246
+ `"Language: ${lang}\\n"`,
247
+ '"Plural-Forms: nplurals=2; plural=(n != 1);\\n"',
248
+ "",
249
+ ].join("\n")
250
+
251
+ const body = entries
252
+ .map((e) => {
253
+ let lines = ""
254
+ if (e.comment && !e.comment.startsWith("# obsolete")) {
255
+ lines += e.comment + "\n"
256
+ }
257
+ lines += `msgid "${escapePo(e.msgid)}"\n`
258
+ lines += `msgstr "${escapePo(e.msgstr)}"\n`
259
+ return lines + "\n"
260
+ })
261
+ .join("")
262
+
263
+ const langDir = join(root, "locale", lang, "LC_MESSAGES")
264
+ mkdirSync(langDir, { recursive: true })
265
+ writeFileSync(join(langDir, "messages.po"), header + body, "utf8")
266
+
267
+ const translated = entries.filter((e) => e.msgstr).length
268
+ console.log(` ${lang}: ${entries.length} entries, ${translated} translated`)
269
+ }
270
+
271
+ console.log(`\nTotal translated strings: ${totalTranslated}`)
272
+
273
+ function escapePo(s) {
274
+ return s.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t")
275
+ }
276
+ function unescapePo(s) {
277
+ return s.replace(/\\"/g, '"').replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\t/g, "\t").replace(/\\\\/g, "\\")
278
+ }
@@ -0,0 +1,304 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * split-translations.js
5
+ *
6
+ * Reads the existing djangojs.po file from the Django locale/ directory
7
+ * and splits translations into per-package .po files.
8
+ *
9
+ * Strategy:
10
+ * 1. Read each language's djangojs.po
11
+ * 2. Parse source references (#: comments) to determine which package
12
+ * each string belongs to
13
+ * 3. Write per-package locale/<lang>/LC_MESSAGES/messages.po
14
+ *
15
+ * The package mapping is based on the known directory renames from
16
+ * the frontend reorganization (see docs/plans/reorganization-handoff.md).
17
+ *
18
+ * Usage:
19
+ * node scripts/split-translations.js <path-to-django-locale>
20
+ * node scripts/split-translations.js /path/to/fiduswriter/fiduswriter/locale
21
+ *
22
+ * Requires: gettext-parser
23
+ */
24
+
25
+ import { readFileSync, writeFileSync, mkdirSync, readdirSync, existsSync } from "node:fs"
26
+ import { join, dirname } from "node:path"
27
+ import { fileURLToPath } from "node:url"
28
+
29
+ const __dirname = dirname(fileURLToPath(import.meta.url))
30
+ const root = join(__dirname, "..")
31
+
32
+ // Resolve gettext-parser
33
+ let poParse
34
+ try {
35
+ const gp = await import("gettext-parser")
36
+ poParse = gp.po?.parse || gp.default?.po?.parse || gp.parse
37
+ } catch {
38
+ console.error("gettext-parser not found. Install: npm install --save-dev gettext-parser")
39
+ process.exit(1)
40
+ }
41
+
42
+ // ---------------------------------------------------------------------------
43
+ // Package mapping: old Django source paths → npm package source paths
44
+ // ---------------------------------------------------------------------------
45
+
46
+ /**
47
+ * Map of package name → array of [old path prefix, new source path prefix].
48
+ * Order matters: first match wins. More specific paths come first.
49
+ */
50
+ const PACKAGE_MAP = {
51
+ "@fiduswriter/frontend": [
52
+ // SPA router + chrome
53
+ ["base/static/js/modules/app/", "src/app/"],
54
+ ["base/static/js/modules/indexed_db/", "src/indexed_db/"],
55
+ ["base/static/js/modules/prelogin/", "src/prelogin/"],
56
+ ["base/static/js/modules/404/", "src/pages/404.ts"],
57
+ ["base/static/js/modules/offline/", "src/pages/offline.ts"],
58
+ ["base/static/js/modules/setup/", "src/pages/setup.ts"],
59
+ ["base/static/js/modules/flatpage/", "src/pages/flatpage.ts"],
60
+ ["base/static/js/modules/admin_console/", "src/admin_console/"],
61
+ ["base/static/js/modules/error_hook/", "src/error_hook/"],
62
+ ["base/static/js/modules/common/", "src/common/"],
63
+ ["base/static/js/modules/menu/", "src/menu/"],
64
+ // Document overview + importers
65
+ ["document/static/js/modules/documents/overview/", "src/documents/overview/"],
66
+ ["document/static/js/modules/importer/", "src/documents/importer/"],
67
+ ["document/static/js/modules/documents/tools", "src/documents/tools.ts"],
68
+ ["document/static/js/modules/documents/revisions/", "src/documents/revisions/"],
69
+ // Maintenance
70
+ ["document/static/js/modules/maintenance/", "src/maintenance/"],
71
+ // User pages
72
+ ["user/static/js/modules/profile/", "src/user/profile/"],
73
+ ["user/static/js/modules/login/", "src/user/auth/login.ts"],
74
+ ["user/static/js/modules/signup/", "src/user/auth/signup.ts"],
75
+ ["user/static/js/modules/password_reset/", "src/user/auth/password-reset.ts"],
76
+ ["user/static/js/modules/email_confirm/", "src/user/auth/email-confirm.ts"],
77
+ ["user/static/js/modules/two_factor/", "src/user/auth/two-factor.ts"],
78
+ ["user/static/js/modules/contacts/", "src/user/contacts/"],
79
+ // Template manager
80
+ ["user_template_manager/static/js/modules/", "src/document_templates/"],
81
+ ],
82
+ "@fiduswriter/editor": [
83
+ ["document/static/js/modules/editor/", "src/"],
84
+ ["document/static/js/modules/exporter/", "src/exporter/"],
85
+ ["document/static/js/modules/importer/", "src/importer/"],
86
+ ["document/static/js/modules/citations/", "src/citations/"],
87
+ ["document/static/js/modules/comments/", "src/comments/"],
88
+ ["document/static/js/modules/collab/", "src/collab/"],
89
+ ["document/static/js/modules/track/", "src/track/"],
90
+ ["document/static/js/modules/footnotes/", "src/footnotes/"],
91
+ ["document/static/js/modules/e2ee/", "src/e2ee/"],
92
+ ["document/static/js/modules/clipboard/", "src/clipboard/"],
93
+ ["document/static/js/modules/marginboxes/", "src/marginboxes/"],
94
+ ["document/static/js/modules/navigator/", "src/navigator/"],
95
+ ["document/static/js/modules/tools/", "src/tools/"],
96
+ ],
97
+ "@fiduswriter/bibliography-manager": [
98
+ ["bibliography/static/js/modules/", "src/"],
99
+ ["base/static/js/modules/bibliography/", "src/"],
100
+ ],
101
+ "@fiduswriter/image-manager": [
102
+ ["usermedia/static/js/modules/", "src/"],
103
+ ["base/static/js/modules/usermedia/", "src/"],
104
+ ],
105
+ "@fiduswriter/document-template-editor": [
106
+ ["document/static/js/modules/document_template/", "src/"],
107
+ ],
108
+ }
109
+
110
+ // ---------------------------------------------------------------------------
111
+ // Main
112
+ // ---------------------------------------------------------------------------
113
+
114
+ const djangoLocalePath = process.argv[2]
115
+ if (!djangoLocalePath || !existsSync(djangoLocalePath)) {
116
+ console.error(`Usage: node split-translations.js <path-to-django-locale>`)
117
+ console.error(` e.g.: node scripts/split-translations.js ../../fiduswriter/fiduswriter/locale`)
118
+ process.exit(1)
119
+ }
120
+
121
+ /** Determine which package a source reference belongs to.
122
+ * Returns the package name, or null if the reference belongs to a Django
123
+ * plugin that should stay in Django's own locale/. */
124
+ function findPackage(ref) {
125
+ for (const [pkgName, prefixes] of Object.entries(PACKAGE_MAP)) {
126
+ for (const [oldPrefix] of prefixes) {
127
+ if (ref.startsWith(oldPrefix)) return pkgName
128
+ }
129
+ }
130
+ // Reference does not match any known npm package path.
131
+ // It belongs to a Django plugin (e.g. llm/static/js/, book/static/js/)
132
+ // or is otherwise unmapped — keep it in Django's locale, do not assign
133
+ // to any npm package.
134
+ return null
135
+ }
136
+
137
+ // ---------------------------------------------------------------------------
138
+ // Process each language
139
+ // ---------------------------------------------------------------------------
140
+
141
+ const languages = readdirSync(djangoLocalePath, { withFileTypes: true })
142
+ .filter((e) => e.isDirectory())
143
+ .map((e) => e.name)
144
+
145
+ console.log(`Found ${languages.length} languages in ${djangoLocalePath}\n`)
146
+
147
+ for (const lang of languages) {
148
+ const djangojsPo = join(djangoLocalePath, lang, "LC_MESSAGES", "djangojs.po")
149
+ if (!existsSync(djangojsPo)) {
150
+ console.log(` ${lang}: no djangojs.po, skipping`)
151
+ continue
152
+ }
153
+
154
+ const poContent = readFileSync(djangojsPo, "utf8")
155
+ let parsed
156
+ try {
157
+ parsed = poParse(poContent)
158
+ } catch (e) {
159
+ console.error(` ${lang}: failed to parse ${djangojsPo}: ${e.message}`)
160
+ continue
161
+ }
162
+
163
+ // Collect entries per package
164
+ /** @type {Record<string, Array<{msgid: string, msgid_plural?: string, msgstr: string|string[], comments: object}>>} */
165
+ const packageEntries = {}
166
+ for (const pkgName of Object.keys(PACKAGE_MAP)) {
167
+ packageEntries[pkgName] = []
168
+ }
169
+
170
+ const translations = parsed.translations || {}
171
+ for (const [, entries] of Object.entries(translations)) {
172
+ for (const [msgid, entry] of Object.entries(entries)) {
173
+ if (!msgid) continue // skip header
174
+
175
+ // Determine package from source references
176
+ const refs = entry.comments?.reference?.split(/\s+/) || []
177
+ let pkg = null
178
+ for (const ref of refs) {
179
+ // ref format: "file.js:line"
180
+ const filePath = ref.replace(/:\d+$/, "")
181
+ const found = findPackage(filePath)
182
+ if (found) {
183
+ pkg = found
184
+ break
185
+ }
186
+ }
187
+
188
+ // Skip strings from unmapped Django plugins (they stay in Django's locale/)
189
+ if (!pkg) continue
190
+
191
+ packageEntries[pkg].push({
192
+ msgid,
193
+ msgid_plural: entry.msgid_plural || undefined,
194
+ msgstr: entry.msgstr,
195
+ comments: entry.comments || {},
196
+ })
197
+ }
198
+ }
199
+
200
+ // Write per-package .po files
201
+ for (const [pkgName, entries] of Object.entries(packageEntries)) {
202
+ if (entries.length === 0) continue
203
+
204
+ // Build .po-like output
205
+ const header = [
206
+ `# Translations for ${pkgName}`,
207
+ `# Language: ${lang}`,
208
+ `# Auto-generated by split-translations.js`,
209
+ `#`,
210
+ `msgid ""`,
211
+ `msgstr ""`,
212
+ `"Content-Type: text/plain; charset=UTF-8\\n"`,
213
+ `"Language: ${lang}\\n"`,
214
+ `"Plural-Forms: nplurals=2; plural=(n != 1);\\n"`,
215
+ ``,
216
+ ].join("\n")
217
+
218
+ const body = entries
219
+ .map((e) => {
220
+ let lines = ""
221
+ // Comments
222
+ if (e.comments?.translator) {
223
+ lines += `# ${e.comments.translator}\n`
224
+ }
225
+ if (e.comments?.reference) {
226
+ const refs = e.comments.reference.split("\n").filter(Boolean)
227
+ for (const ref of refs) {
228
+ lines += `#: ${ref.trim()}\n`
229
+ }
230
+ }
231
+ if (e.comments?.flag) {
232
+ lines += `#, ${e.comments.flag}\n`
233
+ }
234
+ if (e.comments?.flag) {
235
+ lines += `#, ${e.comments.flag}\n`
236
+ }
237
+ // msgid
238
+ lines += `msgid "${escapePo(e.msgid)}"\n`
239
+ if (e.msgid_plural) {
240
+ lines += `msgid_plural "${escapePo(e.msgid_plural)}"\n`
241
+ }
242
+ // msgstr
243
+ if (Array.isArray(e.msgstr)) {
244
+ for (let i = 0; i < e.msgstr.length; i++) {
245
+ lines += `msgstr[${i}] "${escapePo(e.msgstr[i] || "")}"\n`
246
+ }
247
+ } else {
248
+ lines += `msgstr "${escapePo(e.msgstr || "")}"\n`
249
+ }
250
+ return lines + "\n"
251
+ })
252
+ .join("")
253
+
254
+ const output = header + "\n" + body
255
+
256
+ // Determine target directory
257
+ let pkgDir
258
+ switch (pkgName) {
259
+ case "@fiduswriter/frontend":
260
+ pkgDir = join(root, "locale")
261
+ break
262
+ case "@fiduswriter/editor":
263
+ pkgDir = join(root, "..", "fiduswriter-editor-js", "locale")
264
+ break
265
+ case "@fiduswriter/bibliography-manager":
266
+ pkgDir = join(root, "..", "fiduswriter-bibliography-manager-js", "locale")
267
+ break
268
+ case "@fiduswriter/image-manager":
269
+ pkgDir = join(root, "..", "fiduswriter-image-manager-js", "locale")
270
+ break
271
+ case "@fiduswriter/document-template-editor":
272
+ pkgDir = join(root, "..", "fiduswriter-document-template-editor-js", "locale")
273
+ break
274
+ default:
275
+ console.log(` ${lang}/${pkgName}: unknown package, skipping`)
276
+ continue
277
+ }
278
+
279
+ const langDir = join(pkgDir, lang, "LC_MESSAGES")
280
+ mkdirSync(langDir, { recursive: true })
281
+ const outFile = join(langDir, "messages.po")
282
+ writeFileSync(outFile, output, "utf8")
283
+
284
+ const translated = entries.filter(
285
+ (e) => {
286
+ const s = Array.isArray(e.msgstr) ? e.msgstr.join("") : e.msgstr
287
+ return s && s.length > 0
288
+ }
289
+ ).length
290
+ console.log(` ${lang}/${pkgName}: ${entries.length} entries (${translated} translated) → ${outFile}`)
291
+ }
292
+ }
293
+
294
+ console.log("\nDone. Run 'npm run compile-i18n' in each package to produce messages.json files.")
295
+
296
+ /** Escape a string for .po format. */
297
+ function escapePo(s) {
298
+ return s
299
+ .replace(/\\/g, "\\\\")
300
+ .replace(/"/g, '\\"')
301
+ .replace(/\n/g, "\\n")
302
+ .replace(/\r/g, "\\r")
303
+ .replace(/\t/g, "\\t")
304
+ }