@lingui/format-po 6.1.0 → 6.2.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 80
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
  ];
@@ -150,15 +150,15 @@ function formatter(options = {}) {
150
150
  catalogExtension: ".po",
151
151
  templateExtension: ".pot",
152
152
  parse(content) {
153
- const po = PO.parse(content);
153
+ const po = parsePo(content);
154
154
  return deserialize(po.items, options);
155
155
  },
156
156
  serialize(catalog, ctx) {
157
157
  let po;
158
158
  if (ctx.existing) {
159
- po = PO.parse(ctx.existing);
159
+ po = parsePo(ctx.existing);
160
160
  } else {
161
- po = new PO();
161
+ po = createPoFile();
162
162
  po.headers = getCreateHeaders(
163
163
  ctx.locale,
164
164
  options.customHeaderAttributes
@@ -169,7 +169,14 @@ function formatter(options = {}) {
169
169
  locale: ctx.locale,
170
170
  sourceLocale: ctx.sourceLocale
171
171
  });
172
- return po.toString();
172
+ const serializeOptions = {};
173
+ if (options.foldLength !== void 0) {
174
+ serializeOptions.foldLength = options.foldLength;
175
+ }
176
+ if (options.compactMultiline !== void 0) {
177
+ serializeOptions.compactMultiline = options.compactMultiline;
178
+ }
179
+ return stringifyPo(po, serializeOptions);
173
180
  }
174
181
  };
175
182
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/format-po",
3
- "version": "6.1.0",
3
+ "version": "6.2.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.2.0",
46
+ "@lingui/message-utils": "6.2.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": "9f2a37bc4a9e3de323b4b9094898e8f05cf05956"
57
58
  }