@lingui/format-po 6.1.0 → 6.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.
package/dist/po.d.mts CHANGED
@@ -66,6 +66,37 @@ type PoFormatterOptions = {
66
66
  printPlaceholdersInComments?: boolean | {
67
67
  limit?: number;
68
68
  };
69
+ /**
70
+ * Maximum line width before folding long strings.
71
+ *
72
+ * When a string exceeds this length, it will be split across multiple lines.
73
+ * Set to `0` to disable folding (strings will only break on actual newlines).
74
+ *
75
+ * @default 0
76
+ */
77
+ foldLength?: number;
78
+ /**
79
+ * Use compact format for multiline strings.
80
+ *
81
+ * When `true` (default), multiline strings start with content on the first line:
82
+ * ```po
83
+ * msgid "First line\n"
84
+ * "Second line"
85
+ * ```
86
+ *
87
+ * When `false`, uses GNU gettext's traditional format with an empty first line:
88
+ * ```po
89
+ * msgid ""
90
+ * "First line\n"
91
+ * "Second line"
92
+ * ```
93
+ *
94
+ * The compact format is recommended as it's compatible with translation
95
+ * platforms that may strip empty first lines, avoiding unnecessary diffs.
96
+ *
97
+ * @default true
98
+ */
99
+ compactMultiline?: boolean;
69
100
  };
70
101
  declare function formatter(options?: PoFormatterOptions): CatalogFormatter;
71
102
 
package/dist/po.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import PO from 'pofile';
1
+ import { parsePo, createPoFile, stringifyPo, createItem } from 'pofile-ts';
2
2
  import { generateMessageId } from '@lingui/message-utils/generateMessageId';
3
3
 
4
4
  function normalizePlaceholderValue(text) {
@@ -48,7 +48,7 @@ const GENERATED_ID_FLAG = "js-lingui-generated-id";
48
48
  const serialize = (catalog, options, ctx) => {
49
49
  return Object.keys(catalog).map((id) => {
50
50
  const message = catalog[id];
51
- const item = new PO.Item();
51
+ const item = createItem();
52
52
  item.extractedComments = [
53
53
  ...message.comments?.length ? splitMultiLineComments(message.comments) : []
54
54
  ];
@@ -144,21 +144,22 @@ function formatter(options = {}) {
144
144
  options = {
145
145
  origins: true,
146
146
  lineNumbers: true,
147
+ foldLength: 0,
147
148
  ...options
148
149
  };
149
150
  return {
150
151
  catalogExtension: ".po",
151
152
  templateExtension: ".pot",
152
153
  parse(content) {
153
- const po = PO.parse(content);
154
+ const po = parsePo(content);
154
155
  return deserialize(po.items, options);
155
156
  },
156
157
  serialize(catalog, ctx) {
157
158
  let po;
158
159
  if (ctx.existing) {
159
- po = PO.parse(ctx.existing);
160
+ po = parsePo(ctx.existing);
160
161
  } else {
161
- po = new PO();
162
+ po = createPoFile();
162
163
  po.headers = getCreateHeaders(
163
164
  ctx.locale,
164
165
  options.customHeaderAttributes
@@ -169,7 +170,14 @@ function formatter(options = {}) {
169
170
  locale: ctx.locale,
170
171
  sourceLocale: ctx.sourceLocale
171
172
  });
172
- return po.toString();
173
+ const serializeOptions = {};
174
+ if (options.foldLength !== void 0) {
175
+ serializeOptions.foldLength = options.foldLength;
176
+ }
177
+ if (options.compactMultiline !== void 0) {
178
+ serializeOptions.compactMultiline = options.compactMultiline;
179
+ }
180
+ return stringifyPo(po, serializeOptions);
173
181
  }
174
182
  };
175
183
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/format-po",
3
- "version": "6.1.0",
3
+ "version": "6.3.0",
4
4
  "description": "Gettext PO formatter for Lingui message catalogs",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -42,16 +42,17 @@
42
42
  "dist/"
43
43
  ],
44
44
  "dependencies": {
45
- "@lingui/conf": "6.1.0",
46
- "@lingui/message-utils": "6.1.0",
47
- "pofile": "^1.1.4"
45
+ "@lingui/conf": "6.3.0",
46
+ "@lingui/message-utils": "6.3.0",
47
+ "pofile-ts": "^4.0.3"
48
48
  },
49
49
  "devDependencies": {
50
+ "typescript": "catalog:",
50
51
  "unbuild": "catalog:",
51
52
  "vitest": "catalog:"
52
53
  },
53
54
  "unbuild": {
54
55
  "declaration": "node16"
55
56
  },
56
- "gitHead": "46a340af0dbfc8e4ac483cc607c2b24ac48ab56b"
57
+ "gitHead": "f5f432578a13f07c5e261896eed65ec4f82998d3"
57
58
  }