docs-i18n 0.2.3 → 0.3.0

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.
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  assemble
3
- } from "./chunk-OSMPWXSQ.js";
4
- import "./chunk-I74LIORX.js";
3
+ } from "./chunk-A3YQNPKZ.js";
4
+ import "./chunk-YN4VJHCQ.js";
5
5
  import {
6
6
  TranslationCache
7
7
  } from "./chunk-XEOYZUHS.js";
8
8
  import {
9
9
  flattenSources
10
- } from "./chunk-PHDMD6EM.js";
10
+ } from "./chunk-SKKZIV3L.js";
11
11
 
12
12
  // src/commands/assemble.ts
13
13
  import {
@@ -3,7 +3,7 @@ import {
3
3
  init_parser,
4
4
  normalize,
5
5
  parseMdx
6
- } from "./chunk-I74LIORX.js";
6
+ } from "./chunk-YN4VJHCQ.js";
7
7
 
8
8
  // src/core/assembler.ts
9
9
  init_normalize();
@@ -1,21 +1,10 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
- }) : x)(function(x) {
10
- if (typeof require !== "undefined") return require.apply(this, arguments);
11
- throw Error('Dynamic require of "' + x + '" is not supported');
12
- });
13
5
  var __esm = (fn, res) => function __init() {
14
6
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
15
7
  };
16
- var __commonJS = (cb, mod) => function __require2() {
17
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18
- };
19
8
  var __export = (target, all) => {
20
9
  for (var name in all)
21
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -28,14 +17,6 @@ var __copyProps = (to, from, except, desc) => {
28
17
  }
29
18
  return to;
30
19
  };
31
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
32
- // If the importer is in node compatibility mode or this is not an ESM
33
- // file that has been converted to a CommonJS file using a Babel-
34
- // compatible transform (i.e. "__esModule" has not been set), then set
35
- // "default" to the CommonJS "module.exports" for node compatibility.
36
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
- mod
38
- ));
39
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
21
 
41
22
  // src/config.ts
@@ -65,11 +46,8 @@ function flattenSources(config) {
65
46
  }
66
47
 
67
48
  export {
68
- __require,
69
49
  __esm,
70
- __commonJS,
71
50
  __export,
72
- __toESM,
73
51
  __toCommonJS,
74
52
  loadConfig,
75
53
  flattenSources
@@ -0,0 +1,122 @@
1
+ import {
2
+ __esm
3
+ } from "./chunk-SKKZIV3L.js";
4
+
5
+ // src/core/normalize.ts
6
+ function normalize(content) {
7
+ let result = content;
8
+ result = result.replace(
9
+ /^(<(?:AppOnly|PagesOnly|details[^>]*|div[^>]*)>)\n(?!\n)/gm,
10
+ "$1\n\n"
11
+ );
12
+ result = result.replace(
13
+ /(?<!\n)\n(<\/(?:AppOnly|PagesOnly|details|div)>)/gm,
14
+ "\n\n$1"
15
+ );
16
+ result = result.replace(
17
+ /^(<\/(?:AppOnly|PagesOnly|details|div)>)\n(?!\n)/gm,
18
+ "$1\n\n"
19
+ );
20
+ return result;
21
+ }
22
+ var init_normalize = __esm({
23
+ "src/core/normalize.ts"() {
24
+ "use strict";
25
+ }
26
+ });
27
+
28
+ // src/core/parser.ts
29
+ import crypto from "crypto";
30
+ import { remark } from "remark";
31
+ function isHtmlPureTag(text) {
32
+ const lines = text.trim().split("\n");
33
+ return lines.every((line) => {
34
+ const trimmed = line.trim();
35
+ if (trimmed === "") return true;
36
+ if (/^<\w[^>]*\/>$/.test(trimmed)) return true;
37
+ if (/^<\/?\w[\w-]*[^>]*>$/.test(trimmed)) return true;
38
+ return false;
39
+ });
40
+ }
41
+ function computeHash(text) {
42
+ return crypto.createHash("md5").update(text).digest("hex");
43
+ }
44
+ function parseMdx(rawContent) {
45
+ const content = normalize(rawContent);
46
+ const tree = remark().parse(content);
47
+ const nodes = [];
48
+ let frontmatterHandled = false;
49
+ if (content.startsWith("---") && tree.children.length >= 2 && tree.children[0].type === "thematicBreak") {
50
+ const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
51
+ if (fmMatch) {
52
+ const fmEnd = fmMatch[0].length;
53
+ const fmText = fmMatch[0];
54
+ nodes.push({
55
+ type: "frontmatter",
56
+ rawText: fmText,
57
+ needsTranslation: true,
58
+ md5: computeHash(fmText),
59
+ startOffset: 0,
60
+ endOffset: fmEnd
61
+ });
62
+ frontmatterHandled = true;
63
+ }
64
+ }
65
+ for (const child of tree.children) {
66
+ const startOffset = child.position?.start.offset ?? 0;
67
+ const endOffset = child.position?.end.offset ?? 0;
68
+ if (frontmatterHandled && startOffset < nodes[0].endOffset) {
69
+ continue;
70
+ }
71
+ const rawText = content.substring(startOffset, endOffset);
72
+ const type = child.type;
73
+ let needsTranslation;
74
+ if (TRANSLATABLE_TYPES.has(type)) {
75
+ needsTranslation = true;
76
+ } else if (type === "html") {
77
+ needsTranslation = !isHtmlPureTag(rawText);
78
+ } else {
79
+ needsTranslation = false;
80
+ }
81
+ const node = {
82
+ type,
83
+ rawText,
84
+ needsTranslation,
85
+ startOffset,
86
+ endOffset
87
+ };
88
+ if (needsTranslation) {
89
+ node.md5 = computeHash(rawText);
90
+ }
91
+ nodes.push(node);
92
+ }
93
+ return nodes;
94
+ }
95
+ var TRANSLATABLE_TYPES, FRONTMATTER_TRANSLATABLE_FIELDS;
96
+ var init_parser = __esm({
97
+ "src/core/parser.ts"() {
98
+ "use strict";
99
+ init_normalize();
100
+ TRANSLATABLE_TYPES = /* @__PURE__ */ new Set([
101
+ "paragraph",
102
+ "heading",
103
+ "list",
104
+ "blockquote"
105
+ ]);
106
+ FRONTMATTER_TRANSLATABLE_FIELDS = [
107
+ "title",
108
+ "description",
109
+ "nav_title",
110
+ "related.title",
111
+ "related.description"
112
+ ];
113
+ }
114
+ });
115
+
116
+ export {
117
+ normalize,
118
+ init_normalize,
119
+ FRONTMATTER_TRANSLATABLE_FIELDS,
120
+ parseMdx,
121
+ init_parser
122
+ };
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  loadConfig
4
- } from "./chunk-PHDMD6EM.js";
4
+ } from "./chunk-SKKZIV3L.js";
5
5
 
6
6
  // src/cli.ts
7
7
  var args = process.argv.slice(2);
@@ -49,7 +49,7 @@ Options:
49
49
  console.error("Error: --lang is required");
50
50
  process.exit(1);
51
51
  }
52
- const { translate } = await import("./translate-2PCYIWIG.js");
52
+ const { translate } = await import("./translate-FI4IXXOP.js");
53
53
  await translate(config, {
54
54
  lang,
55
55
  project: getOpt("project") || void 0,
@@ -65,7 +65,7 @@ Options:
65
65
  break;
66
66
  }
67
67
  case "assemble": {
68
- const { assembleAll } = await import("./assemble-ZHDLGVTL.js");
68
+ const { assembleAll } = await import("./assemble-7H4QCW35.js");
69
69
  await assembleAll(config, {
70
70
  project: getOpt("project") || void 0,
71
71
  version: getOpt("version") || void 0,
@@ -74,7 +74,7 @@ Options:
74
74
  break;
75
75
  }
76
76
  case "rescan": {
77
- const { rescan } = await import("./rescan-OJTVWDAP.js");
77
+ const { rescan } = await import("./rescan-O5D3CYC2.js");
78
78
  await rescan(config, {
79
79
  project: getOpt("project") || void 0,
80
80
  version: getOpt("version") || void 0
@@ -82,13 +82,13 @@ Options:
82
82
  break;
83
83
  }
84
84
  case "status": {
85
- const { status } = await import("./status-ZG7F3FRT.js");
85
+ const { status } = await import("./status-F4MYIAAY.js");
86
86
  await status(config, { lang: getOpt("lang") || void 0 });
87
87
  break;
88
88
  }
89
89
  case "admin": {
90
90
  const port = Number(getOpt("port", "3456"));
91
- const { startAdmin } = await import("./server-U4KHO7JR.js");
91
+ const { startAdmin } = await import("./server-XRHMURM5.js");
92
92
  await startAdmin(config, port);
93
93
  break;
94
94
  }
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  init_parser,
3
3
  parseMdx
4
- } from "./chunk-I74LIORX.js";
4
+ } from "./chunk-YN4VJHCQ.js";
5
5
  import {
6
6
  TranslationCache
7
7
  } from "./chunk-XEOYZUHS.js";
8
8
  import {
9
9
  flattenSources
10
- } from "./chunk-PHDMD6EM.js";
10
+ } from "./chunk-SKKZIV3L.js";
11
11
 
12
12
  // src/commands/rescan.ts
13
13
  import { existsSync, readdirSync, readFileSync } from "fs";