next-intl 4.13.7 → 4.14.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.
Files changed (39) hide show
  1. package/dist/cjs/development/BuiltInPoCodec-B6w-kmTx.cjs +34 -0
  2. package/dist/cjs/development/plugin.cjs +1607 -8
  3. package/dist/esm/development/extractor/catalog/CatalogManager.js +3 -2
  4. package/dist/esm/development/extractor/catalog/CatalogPersister.js +21 -2
  5. package/dist/esm/development/extractor/catalogLoader.js +38 -16
  6. package/dist/esm/development/extractor/extractor/MessageExtractor.js +8 -1
  7. package/dist/esm/development/extractor/format/ExtractorCodec.js +3 -0
  8. package/dist/esm/development/extractor/format/codecs/BuiltInPoCodec.js +22 -0
  9. package/dist/esm/development/extractor/format/index.js +19 -4
  10. package/dist/esm/development/extractor/utils.js +8 -27
  11. package/dist/esm/development/plugin/getNextConfig.js +6 -2
  12. package/dist/esm/production/extractor/catalog/CatalogManager.js +1 -1
  13. package/dist/esm/production/extractor/catalog/CatalogPersister.js +1 -1
  14. package/dist/esm/production/extractor/catalogLoader.js +1 -1
  15. package/dist/esm/production/extractor/extractor/MessageExtractor.js +1 -1
  16. package/dist/esm/production/extractor/format/codecs/BuiltInPoCodec.js +1 -0
  17. package/dist/esm/production/extractor/format/index.js +1 -1
  18. package/dist/esm/production/extractor/utils.js +1 -1
  19. package/dist/esm/production/plugin/getNextConfig.js +1 -1
  20. package/dist/types/extractor/catalog/CatalogManager.d.ts +1 -1
  21. package/dist/types/extractor/catalog/CatalogPersister.d.ts +2 -0
  22. package/dist/types/extractor/extractor/MessageExtractor.d.ts +2 -2
  23. package/dist/types/extractor/format/ExtractorCodec.d.ts +11 -27
  24. package/dist/types/extractor/format/codecs/fixtures/POCodecLegacy.d.ts +50 -0
  25. package/dist/types/extractor/format/index.d.ts +2 -2
  26. package/dist/types/extractor/types.d.ts +9 -21
  27. package/dist/types/extractor/utils.d.ts +1 -1
  28. package/package.json +9 -12
  29. package/dist/cjs/development/ExtractorCodec-D9Tw618d.cjs +0 -7
  30. package/dist/cjs/development/JSONCodec-CzA8ubPy.cjs +0 -55
  31. package/dist/cjs/development/POCodec-CWGHK-Gp.cjs +0 -111
  32. package/dist/cjs/development/plugin-DlFYUFWh.cjs +0 -1613
  33. package/dist/esm/development/extractor/format/codecs/JSONCodec.js +0 -47
  34. package/dist/esm/development/extractor/format/codecs/POCodec.js +0 -99
  35. package/dist/esm/production/extractor/format/codecs/JSONCodec.js +0 -1
  36. package/dist/esm/production/extractor/format/codecs/POCodec.js +0 -1
  37. package/dist/types/extractor/format/codecs/POCodec.d.ts +0 -2
  38. package/dist/types/extractor/format/codecs/fixtures/POCodecSourceMessageKey.d.ts +0 -2
  39. /package/dist/types/extractor/format/codecs/{JSONCodec.d.ts → BuiltInPoCodec.d.ts} +0 -0
@@ -1,33 +1,19 @@
1
+ import type { defineCodec } from '@eloqnt/config';
1
2
  import type { MessagesFormat } from './format/types.js';
2
3
  export type Locale = string;
3
- export type ExtractorMessageReference = {
4
- path: string;
5
- line?: number;
6
- };
4
+ type SharedSeparateFileCodec = Extract<ReturnType<ReturnType<typeof defineCodec>>, {
5
+ decode: unknown;
6
+ }>;
7
+ export type ExtractorMessageReference = ExtractorMessage['references'][number];
7
8
  /** A single statically extracted source-code usage before any aggregation. */
8
- export type SourceMessage = {
9
+ export type SourceExtractedMessage = {
9
10
  id: string;
10
11
  message: string;
11
12
  description: string | null;
12
13
  reference: ExtractorMessageReference;
13
14
  };
14
15
  /** An aggregated message that can be read from or written to a catalog. */
15
- export type ExtractorMessage = {
16
- id: string;
17
- message: string;
18
- /**
19
- * All unique descriptions attached to messages (e.g. multiple `#.` lines in PO).
20
- * Ordered by source reference (path, then line).
21
- */
22
- description: Array<string>;
23
- /**
24
- * Source locations for this message (e.g. `#:` lines in PO). Ordered by path, then line.
25
- * Empty when the catalog format does not store references or none are known.
26
- */
27
- references: Array<ExtractorMessageReference>;
28
- /** Allows for additional properties like .po flags to be read and later written. */
29
- [key: string]: unknown;
30
- };
16
+ export type ExtractorMessage = ReturnType<SharedSeparateFileCodec['decode']>[number];
31
17
  /**
32
18
  * External extractor configuration (Next.js plugin, `extractMessages`).
33
19
  */
@@ -75,5 +61,7 @@ export type CatalogLoaderConfig = {
75
61
  messages: {
76
62
  format: MessagesFormat;
77
63
  precompile?: boolean;
64
+ sourceLocale: Locale;
78
65
  };
79
66
  };
67
+ export {};
@@ -3,7 +3,7 @@ export declare function normalizePathToPosix(filePath: string): string;
3
3
  export declare function isForbiddenObjectKey(key: string): boolean;
4
4
  export declare function hasLocalesToExtract(config: Pick<ExtractorConfig, 'extract'>): boolean;
5
5
  export declare function setNestedProperty(obj: Record<string, any>, keyPath: string, value: any): void;
6
- export declare function getSortedMessages(messages: Array<ExtractorMessage>): Array<ExtractorMessage>;
6
+ export declare function warnAboutMissingReferences(messages: Array<ExtractorMessage>): void;
7
7
  export declare function localeCompare(a: string, b: string): number;
8
8
  export declare function compareReferences(refA: ExtractorMessageReference, refB: ExtractorMessageReference): number;
9
9
  export declare function getDefaultProjectRoot(): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "4.13.7",
3
+ "version": "4.14.0",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -124,23 +124,20 @@
124
124
  "next.js"
125
125
  ],
126
126
  "dependencies": {
127
+ "@eloqnt/config": "^0.0.2",
128
+ "@eloqnt/format-json": "^0.0.3",
129
+ "@eloqnt/format-po": "^0.0.3",
127
130
  "@formatjs/intl-localematcher": "^0.8.1",
128
131
  "@parcel/watcher": "^2.4.1",
129
- "@swc/core": "~1.15.47",
130
- "icu-minify": "^4.13.7",
132
+ "@swc/core": "~1.16.0",
133
+ "icu-minify": "^4.14.0",
131
134
  "negotiator": "^1.0.0",
132
- "next-intl-swc-plugin-extractor": "4.13.7",
133
- "po-parser": "^2.1.1",
134
- "use-intl": "^4.13.7"
135
+ "next-intl-swc-plugin-extractor": "4.14.0",
136
+ "use-intl": "^4.14.0"
135
137
  },
136
138
  "peerDependencies": {
137
139
  "next": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
138
140
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || >=19.0.0-rc <19.0.0 || ^19.0.0"
139
141
  },
140
- "peerDependenciesMeta": {
141
- "typescript": {
142
- "optional": true
143
- }
144
- },
145
- "gitHead": "4e5d46b00320e76e953c41e23afcabc675e14974"
142
+ "gitHead": "38845ed081a82fd2ab1bae8788620ca3d36334f5"
146
143
  }
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- function defineCodec(factory) {
4
- return factory;
5
- }
6
-
7
- exports.defineCodec = defineCodec;
@@ -1,55 +0,0 @@
1
- 'use strict';
2
-
3
- var plugin = require('./plugin-DlFYUFWh.cjs');
4
- var ExtractorCodec = require('./ExtractorCodec-D9Tw618d.cjs');
5
- require('fs/promises');
6
- require('path');
7
- require('@parcel/watcher');
8
- require('fs');
9
- require('module');
10
- require('@swc/core');
11
-
12
- var JSONCodec = ExtractorCodec.defineCodec(() => ({
13
- decode(source) {
14
- const json = JSON.parse(source);
15
- const messages = [];
16
- traverseMessages(json, (message, id) => {
17
- messages.push({
18
- id,
19
- message,
20
- references: [],
21
- description: []
22
- });
23
- });
24
- return messages;
25
- },
26
- encode(messages) {
27
- const root = {};
28
- for (const message of plugin.getSortedMessages(messages)) {
29
- plugin.setNestedProperty(root, message.id, message.message);
30
- }
31
- return JSON.stringify(root, null, 2) + '\n';
32
- },
33
- toJSONString(source) {
34
- return source;
35
- }
36
- }));
37
- function traverseMessages(obj, callback, path = '') {
38
- const NAMESPACE_SEPARATOR = '.';
39
- for (const key of Object.keys(obj)) {
40
- if (plugin.isForbiddenObjectKey(key)) {
41
- throw new Error(`Invalid message catalog key: \`${key}\`.`);
42
- }
43
- const newPath = path ? path + NAMESPACE_SEPARATOR + key : key;
44
- const value = obj[key];
45
- if (typeof value === 'string') {
46
- callback(value, newPath);
47
- } else if (Array.isArray(value)) {
48
- throw new Error(`Message at \`${newPath}\` resolved to an array, but only strings are supported. See https://next-intl.dev/docs/usage/translations#arrays-of-messages`);
49
- } else if (typeof value === 'object') {
50
- traverseMessages(value, callback, newPath);
51
- }
52
- }
53
- }
54
-
55
- exports.default = JSONCodec;
@@ -1,111 +0,0 @@
1
- 'use strict';
2
-
3
- var POParser = require('po-parser');
4
- var plugin = require('./plugin-DlFYUFWh.cjs');
5
- var ExtractorCodec = require('./ExtractorCodec-D9Tw618d.cjs');
6
- require('fs/promises');
7
- require('path');
8
- require('@parcel/watcher');
9
- require('fs');
10
- require('module');
11
- require('@swc/core');
12
-
13
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
14
-
15
- var POParser__default = /*#__PURE__*/_interopDefaultCompat(POParser);
16
-
17
- var POCodec = ExtractorCodec.defineCodec(() => {
18
- // See also https://www.gnu.org/software/gettext/manual/html_node/Header-Entry.html
19
- const DEFAULT_METADATA = {
20
- // Recommended by spec
21
- 'Content-Type': 'text/plain; charset=utf-8',
22
- 'Content-Transfer-Encoding': '8bit',
23
- // Otherwise other tools might set this
24
- 'X-Generator': 'next-intl',
25
- // Crowdin defaults to using msgid as source key
26
- 'X-Crowdin-SourceKey': 'msgstr'
27
- };
28
-
29
- // Move all parts before the last dot to msgctxt
30
- const NAMESPACE_SEPARATOR = '.';
31
-
32
- // Metadata is stored so it can be retained when writing
33
- const metadataByLocale = new Map();
34
- return {
35
- decode(content, context) {
36
- const catalog = POParser__default.default.parse(content);
37
- if (catalog.meta) {
38
- metadataByLocale.set(context.locale, catalog.meta);
39
- }
40
- const messages = catalog.messages || [];
41
- return messages.map(msg => {
42
- const {
43
- extractedComments,
44
- msgctxt,
45
- msgid,
46
- msgstr,
47
- references,
48
- ...rest
49
- } = msg;
50
- return {
51
- ...rest,
52
- id: msgctxt ? [msgctxt, msgid].join(NAMESPACE_SEPARATOR) : msgid,
53
- message: msgstr,
54
- description: extractedComments ?? [],
55
- references: references ?? []
56
- };
57
- });
58
- },
59
- encode(messages, context) {
60
- const encodedMessages = plugin.getSortedMessages(messages).map(msg => {
61
- const {
62
- description = [],
63
- id,
64
- message,
65
- references,
66
- ...rest
67
- } = msg;
68
- const lastDotIndex = id.lastIndexOf(NAMESPACE_SEPARATOR);
69
- const hasNamespace = id.includes(NAMESPACE_SEPARATOR);
70
- const msgid = hasNamespace ? id.slice(lastDotIndex + NAMESPACE_SEPARATOR.length) : id;
71
-
72
- // Path-only refs (no `:line`), unique paths
73
- const pathOnlyRefs = [...new Set(references.map(ref => ref.path))].map(path => ({
74
- path
75
- }));
76
- return {
77
- msgid,
78
- msgstr: message,
79
- ...(description.length > 0 && {
80
- extractedComments: description
81
- }),
82
- ...(hasNamespace && {
83
- msgctxt: id.slice(0, lastDotIndex)
84
- }),
85
- ...(pathOnlyRefs.length > 0 && {
86
- references: pathOnlyRefs
87
- }),
88
- ...rest
89
- };
90
- });
91
- return POParser__default.default.serialize({
92
- meta: {
93
- Language: context.locale,
94
- ...DEFAULT_METADATA,
95
- ...metadataByLocale.get(context.locale)
96
- },
97
- messages: encodedMessages
98
- });
99
- },
100
- toJSONString(source, context) {
101
- const parsed = this.decode(source, context);
102
- const messagesObject = {};
103
- for (const message of parsed) {
104
- plugin.setNestedProperty(messagesObject, message.id, message.message);
105
- }
106
- return JSON.stringify(messagesObject);
107
- }
108
- };
109
- });
110
-
111
- exports.default = POCodec;