next-intl 4.4.0 → 4.5.1
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/cjs/development/plugin.cjs +129 -8
- package/dist/esm/development/extractor/ExtractionCompiler.js +41 -0
- package/dist/esm/development/extractor/catalog/CatalogLocales.js +117 -0
- package/dist/esm/development/extractor/catalog/CatalogManager.js +286 -0
- package/dist/esm/development/extractor/catalog/CatalogPersister.js +45 -0
- package/dist/esm/development/extractor/catalog/SaveScheduler.js +66 -0
- package/dist/esm/development/extractor/catalogLoader.js +35 -0
- package/dist/esm/development/extractor/extractMessages.js +8 -0
- package/dist/esm/development/extractor/extractionLoader.js +22 -0
- package/dist/esm/development/extractor/extractor/ASTScope.js +18 -0
- package/dist/esm/development/extractor/extractor/KeyGenerator.js +11 -0
- package/dist/esm/development/extractor/extractor/LRUCache.js +30 -0
- package/dist/esm/development/extractor/extractor/MessageExtractor.js +402 -0
- package/dist/esm/development/extractor/formatters/Formatter.js +3 -0
- package/dist/esm/development/extractor/formatters/JSONFormatter.js +42 -0
- package/dist/esm/development/extractor/formatters/POFormatter.js +51 -0
- package/dist/esm/development/extractor/formatters/index.js +6 -0
- package/dist/esm/development/extractor/formatters/utils.js +13 -0
- package/dist/esm/development/extractor/source/SourceFileFilter.js +11 -0
- package/dist/esm/development/extractor/source/SourceFileScanner.js +27 -0
- package/dist/esm/development/extractor/utils/ObjectUtils.js +14 -0
- package/dist/esm/development/extractor/utils/POParser.js +222 -0
- package/dist/esm/development/extractor.js +1 -0
- package/dist/esm/development/index.react-client.js +2 -1
- package/dist/esm/development/index.react-server.js +1 -0
- package/dist/esm/development/middleware/utils.js +6 -2
- package/dist/esm/development/plugin/createNextIntlPlugin.js +1 -1
- package/dist/esm/development/plugin/{createMessagesDeclaration.js → declaration/createMessagesDeclaration.js} +2 -2
- package/dist/esm/development/plugin/getNextConfig.js +117 -8
- package/dist/esm/development/plugin/{hasStableTurboConfig.js → nextFlags.js} +7 -2
- package/dist/esm/development/react-client/index.js +0 -1
- package/dist/esm/development/react-server/useExtracted.js +9 -0
- package/dist/esm/development/server/react-client/index.js +2 -1
- package/dist/esm/development/server/react-server/getExtracted.js +24 -0
- package/dist/esm/development/server/react-server/getServerExtractor.js +38 -0
- package/dist/esm/development/server.react-client.js +1 -1
- package/dist/esm/development/server.react-server.js +1 -0
- package/dist/esm/development/shared/utils.js +2 -1
- package/dist/esm/production/extractor/ExtractionCompiler.js +1 -0
- package/dist/esm/production/extractor/catalog/CatalogLocales.js +1 -0
- package/dist/esm/production/extractor/catalog/CatalogManager.js +1 -0
- package/dist/esm/production/extractor/catalog/CatalogPersister.js +1 -0
- package/dist/esm/production/extractor/catalog/SaveScheduler.js +1 -0
- package/dist/esm/production/extractor/catalogLoader.js +1 -0
- package/dist/esm/production/extractor/extractMessages.js +1 -0
- package/dist/esm/production/extractor/extractionLoader.js +1 -0
- package/dist/esm/production/extractor/extractor/ASTScope.js +1 -0
- package/dist/esm/production/extractor/extractor/KeyGenerator.js +1 -0
- package/dist/esm/production/extractor/extractor/LRUCache.js +1 -0
- package/dist/esm/production/extractor/extractor/MessageExtractor.js +1 -0
- package/dist/esm/production/extractor/formatters/Formatter.js +1 -0
- package/dist/esm/production/extractor/formatters/JSONFormatter.js +1 -0
- package/dist/esm/production/extractor/formatters/POFormatter.js +1 -0
- package/dist/esm/production/extractor/formatters/index.js +1 -0
- package/dist/esm/production/extractor/formatters/utils.js +1 -0
- package/dist/esm/production/extractor/source/SourceFileFilter.js +1 -0
- package/dist/esm/production/extractor/source/SourceFileScanner.js +1 -0
- package/dist/esm/production/extractor/utils/ObjectUtils.js +1 -0
- package/dist/esm/production/extractor/utils/POParser.js +1 -0
- package/dist/esm/production/extractor.js +1 -0
- package/dist/esm/production/index.react-client.js +1 -1
- package/dist/esm/production/index.react-server.js +1 -1
- package/dist/esm/production/middleware/utils.js +1 -1
- package/dist/esm/production/plugin/createNextIntlPlugin.js +1 -1
- package/dist/esm/production/plugin/declaration/createMessagesDeclaration.js +1 -0
- package/dist/esm/production/plugin/getNextConfig.js +1 -1
- package/dist/esm/production/plugin/nextFlags.js +1 -0
- package/dist/esm/production/react-client/index.js +1 -1
- package/dist/esm/production/react-server/useExtracted.js +1 -0
- package/dist/esm/production/server/react-client/index.js +1 -1
- package/dist/esm/production/server/react-server/getExtracted.js +1 -0
- package/dist/esm/production/server/react-server/getServerExtractor.js +1 -0
- package/dist/esm/production/server.react-client.js +1 -1
- package/dist/esm/production/server.react-server.js +1 -1
- package/dist/esm/production/shared/utils.js +1 -1
- package/dist/types/extractor/ExtractionCompiler.d.ts +14 -0
- package/dist/types/extractor/catalog/CatalogLocales.d.ts +31 -0
- package/dist/types/extractor/catalog/CatalogManager.d.ts +46 -0
- package/dist/types/extractor/catalog/CatalogPersister.d.ts +11 -0
- package/dist/types/extractor/catalog/SaveScheduler.d.ts +17 -0
- package/dist/types/extractor/extractMessages.d.ts +2 -0
- package/dist/types/extractor/extractor/ASTScope.d.ts +12 -0
- package/dist/types/extractor/extractor/KeyGenerator.d.ts +3 -0
- package/dist/types/extractor/extractor/LRUCache.d.ts +7 -0
- package/dist/types/extractor/extractor/MessageExtractor.d.ts +20 -0
- package/dist/types/extractor/formatters/Formatter.d.ts +10 -0
- package/dist/types/extractor/formatters/JSONFormatter.d.ts +10 -0
- package/dist/types/extractor/formatters/POFormatter.d.ts +10 -0
- package/dist/types/extractor/formatters/index.d.ts +5 -0
- package/dist/types/extractor/formatters/utils.d.ts +2 -0
- package/dist/types/extractor/index.d.ts +1 -0
- package/dist/types/extractor/source/SourceFileFilter.d.ts +4 -0
- package/dist/types/extractor/source/SourceFileScanner.d.ts +4 -0
- package/dist/types/extractor/types.d.ts +23 -0
- package/dist/types/extractor/utils/ObjectUtils.d.ts +1 -0
- package/dist/types/extractor/utils/POParser.d.ts +24 -0
- package/dist/types/extractor.d.ts +1 -0
- package/dist/types/navigation/react-client/createNavigation.d.ts +9 -9
- package/dist/types/navigation/react-server/createNavigation.d.ts +9 -9
- package/dist/types/navigation/shared/createSharedNavigationFns.d.ts +10 -10
- package/dist/types/plugin/catalog/catalogLoader.d.ts +10 -0
- package/dist/types/plugin/declaration/index.d.ts +1 -0
- package/dist/types/plugin/extractor/extractionLoader.d.ts +3 -0
- package/dist/types/plugin/nextFlags.d.ts +2 -0
- package/dist/types/plugin/types.d.ts +18 -0
- package/dist/types/react-client/index.d.ts +3 -1
- package/dist/types/react-server/index.d.ts +1 -0
- package/dist/types/react-server/useExtracted.d.ts +2 -0
- package/dist/types/server/react-client/index.d.ts +2 -1
- package/dist/types/server/react-server/getExtracted.d.ts +10 -0
- package/dist/types/server/react-server/getServerExtractor.d.ts +5 -0
- package/dist/types/server/react-server/index.d.ts +1 -0
- package/extractor/catalogLoader.d.ts +4 -0
- package/extractor/extractionLoader.d.ts +4 -0
- package/extractor.d.ts +2 -0
- package/package.json +20 -5
- package/dist/esm/production/plugin/createMessagesDeclaration.js +0 -1
- package/dist/esm/production/plugin/hasStableTurboConfig.js +0 -1
- package/dist/types/plugin/hasStableTurboConfig.d.ts +0 -2
- /package/dist/types/plugin/{createMessagesDeclaration.d.ts → declaration/createMessagesDeclaration.d.ts} +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { cache } from 'react';
|
|
2
|
+
import getServerTranslator from './getServerTranslator.js';
|
|
3
|
+
|
|
4
|
+
// Note: This API is usually compiled into `useTranslations`,
|
|
5
|
+
// but there is some fallback handling which allows this hook
|
|
6
|
+
// to still work when not being compiled.
|
|
7
|
+
//
|
|
8
|
+
// This is relevant for:
|
|
9
|
+
// - Isolated environments like tests, Storybook, etc.
|
|
10
|
+
// - Fallbacks in case an extracted message is not yet available
|
|
11
|
+
function getServerExtractorImpl(config, namespace) {
|
|
12
|
+
const t = getServerTranslator(config, namespace);
|
|
13
|
+
function translateFn(...[message, values, formats]) {
|
|
14
|
+
return t(undefined, values, formats,
|
|
15
|
+
// @ts-expect-error -- Secret fallback parameter
|
|
16
|
+
message );
|
|
17
|
+
}
|
|
18
|
+
translateFn.rich = function translateRichFn(...[message, values, formats]) {
|
|
19
|
+
return t.rich(undefined, values, formats,
|
|
20
|
+
// @ts-expect-error -- Secret fallback parameter
|
|
21
|
+
message );
|
|
22
|
+
};
|
|
23
|
+
translateFn.markup = function translateMarkupFn(...[message, values, formats]) {
|
|
24
|
+
return t.markup(undefined, values, formats,
|
|
25
|
+
// @ts-expect-error -- Secret fallback parameter
|
|
26
|
+
message );
|
|
27
|
+
};
|
|
28
|
+
translateFn.has = function translateHasFn(
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
30
|
+
...[message]) {
|
|
31
|
+
// Not really something better we can do here
|
|
32
|
+
return true;
|
|
33
|
+
};
|
|
34
|
+
return translateFn;
|
|
35
|
+
}
|
|
36
|
+
var getServerExtractor = cache(getServerExtractorImpl);
|
|
37
|
+
|
|
38
|
+
export { getServerExtractor as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getFormatter, getLocale, getMessages, getNow, getRequestConfig, getTimeZone, getTranslations, setRequestLocale } from './server/react-client/index.js';
|
|
1
|
+
export { getExtracted, getFormatter, getLocale, getMessages, getNow, getRequestConfig, getTimeZone, getTranslations, setRequestLocale } from './server/react-client/index.js';
|
|
@@ -2,6 +2,7 @@ export { default as getRequestConfig } from './server/react-server/getRequestCon
|
|
|
2
2
|
export { default as getFormatter } from './server/react-server/getFormatter.js';
|
|
3
3
|
export { default as getNow } from './server/react-server/getNow.js';
|
|
4
4
|
export { default as getTimeZone } from './server/react-server/getTimeZone.js';
|
|
5
|
+
export { default as getExtracted } from './server/react-server/getExtracted.js';
|
|
5
6
|
export { default as getMessages } from './server/react-server/getMessages.js';
|
|
6
7
|
export { default as getLocale } from './server/react-server/getLocale.js';
|
|
7
8
|
export { default as getTranslations } from './server/react-server/getTranslations.js';
|
|
@@ -78,7 +78,8 @@ function getLocaleAsPrefix(locale) {
|
|
|
78
78
|
function templateToRegex(template) {
|
|
79
79
|
const regexPattern = template
|
|
80
80
|
// Replace optional catchall ('[[...slug]]')
|
|
81
|
-
.replace(
|
|
81
|
+
.replace(/\/\[\[(\.\.\.[^\]]+)\]\]/g, '(?:/(.*))?') // With leading slash
|
|
82
|
+
.replace(/\[\[(\.\.\.[^\]]+)\]\]/g, '(?:/(.*))?') // Without leading slash
|
|
82
83
|
// Replace catchall ('[...slug]')
|
|
83
84
|
.replace(/\[(\.\.\.[^\]]+)\]/g, '(.+)')
|
|
84
85
|
// Replace regular parameter ('[slug]')
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import a from"./catalog/CatalogManager.js";class i{isDevelopment=!1;constructor(i,e={}){this.manager=new a(i,e),this.isDevelopment=e.isDevelopment??!1,this.initialScanPromise=this.performInitialScan()}async compile(a,i){this.initialScanPromise&&(await this.initialScanPromise,this.initialScanPromise=void 0);const e=await this.manager.extractFileMessages(a,i);return this.isDevelopment&&e.changed&&this.manager.save(),e.source}async performInitialScan(){await this.manager.loadMessages(),await this.manager.save()}async extract(){await this.initialScanPromise}[Symbol.dispose](){this.manager.destroy()}}export{i as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"fs";import s from"fs/promises";import t from"path";class a{cleanupHandlers=[];onChangeCallbacks=(()=>new Set)();constructor(e){this.messagesDir=e.messagesDir,this.sourceLocale=e.sourceLocale,this.extension=e.extension,this.locales=e.locales}async getTargetLocales(){return this.targetLocales||("infer"===this.locales?this.targetLocales=await this.readTargetLocales():this.targetLocales=this.locales.filter((e=>e!==this.sourceLocale))),this.targetLocales}async readTargetLocales(){try{return(await s.readdir(this.messagesDir)).filter((e=>e.endsWith(this.extension))).map((e=>t.basename(e,this.extension))).filter((e=>e!==this.sourceLocale))}catch{return[]}}subscribeLocalesChange(e){this.onChangeCallbacks.add(e),"infer"!==this.locales||this.watcher||this.startWatcher()}unsubscribeLocalesChange(e){this.onChangeCallbacks.delete(e),0===this.onChangeCallbacks.size&&this.stopWatcher()}async startWatcher(){this.watcher||(await s.mkdir(this.messagesDir,{recursive:!0}),this.watcher=e.watch(this.messagesDir,{persistent:!1,recursive:!1},((e,s)=>{null!=s&&s.endsWith(this.extension)&&!s.includes(t.sep)&&this.onChange()})),this.setupCleanupHandlers())}stopWatcher(){this.watcher&&(this.watcher.close(),this.watcher=void 0);for(const e of this.cleanupHandlers)e();this.cleanupHandlers=[]}async onChange(){const e=new Set(this.targetLocales||[]);this.targetLocales=await this.readTargetLocales();const s=new Set(this.targetLocales),t=this.targetLocales.filter((s=>!e.has(s))),a=Array.from(e).filter((e=>!s.has(e)));if(t.length>0||a.length>0)for(const e of this.onChangeCallbacks)e({added:t,removed:a})}setupCleanupHandlers(){const e=()=>{this.watcher&&(this.watcher.close(),this.watcher=void 0)};function s(){e()}function t(){e(),process.exit(0)}function a(){e(),process.exit(0)}process.once("exit",s),process.once("SIGINT",t),process.once("SIGTERM",a),this.cleanupHandlers.push((()=>{process.removeListener("exit",s),process.removeListener("SIGINT",t),process.removeListener("SIGTERM",a)}))}}export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"fs/promises";import s from"path";import t from"../extractor/MessageExtractor.js";import a from"../formatters/index.js";import i from"../source/SourceFileScanner.js";import r from"./CatalogLocales.js";import o from"./CatalogPersister.js";import c from"./SaveScheduler.js";class n{messagesByFile=(()=>new Map)();messagesById=(()=>new Map)();translationsByTargetLocale=(()=>new Map)();lastWriteByLocale=(()=>new Map)();constructor(e,s={}){this.config=e,this.saveScheduler=new c(50),this.projectRoot=s.projectRoot||process.cwd(),this.isDevelopment=s.isDevelopment??!1,this.messageExtractor=new t({isDevelopment:this.isDevelopment,projectRoot:this.projectRoot})}async getFormatter(){if(this.formatter)return this.formatter;{const e=(await a[this.config.messages.format]()).default;return this.formatter=new e,this.formatter}}async getPersister(){return this.persister||(this.persister=new o(this.config.messages.path,await this.getFormatter())),this.persister}async getCatalogLocales(){if(this.catalogLocales)return this.catalogLocales;{const e=s.join(this.projectRoot,this.config.messages.path),t=await this.getFormatter();return this.catalogLocales=new r({messagesDir:e,sourceLocale:this.config.sourceLocale,extension:t.EXTENSION,locales:this.config.messages.locales}),this.catalogLocales}}async getTargetLocales(){return(await this.getCatalogLocales()).getTargetLocales()}getSrcPaths(){return(Array.isArray(this.config.srcPath)?this.config.srcPath:[this.config.srcPath]).map((e=>s.join(this.projectRoot,e)))}getFileMessages(e){return this.messagesByFile.get(e)}async loadMessages(){if(await this.loadSourceMessages(),await this.loadTargetMessages(),this.isDevelopment){(await this.getCatalogLocales()).subscribeLocalesChange(this.onLocalesChange)}}async loadSourceMessages(){await this.loadLocaleMessages(this.config.sourceLocale);const s=await i.getSourceFiles(this.getSrcPaths());await Promise.all(s.map((async s=>this.extractFileMessages(s,await e.readFile(s,"utf8")))))}async loadLocaleMessages(e){const s=await this.getPersister();try{const t=await s.read(e),a=await s.getLastModified(e);return this.lastWriteByLocale.set(e,a),t}catch{return[]}}async loadTargetMessages(){const e=await this.getTargetLocales();await Promise.all(e.map((async e=>{this.translationsByTargetLocale.set(e,new Map);const s=await this.loadLocaleMessages(e);for(const t of s){this.translationsByTargetLocale.get(e).set(t.id,t.message)}})))}async extractFileMessages(e,t){const a=await this.messageExtractor.processFileContent(e,t),i=this.messagesByFile.get(e),r=Array.from(i?.keys()??[]),o=new Map;for(let e of a.messages){const s=this.messagesById.get(e.id);if(s){const t=[...s.references??[]];e.references.forEach((e=>{t.some((s=>s.path===e.path))||t.push(e)})),e={...e,references:t},s.description&&!e.description&&(e={...e,description:s.description})}this.messagesById.set(e.id,e),o.set(e.id,e);const t=r.indexOf(e.id);-1!==t&&r.splice(t,1)}const c=s.relative(this.projectRoot,e);r.filter((e=>{const s=this.messagesById.get(e);return!s?.references?.some((e=>e.path!==c))})).forEach((e=>{this.messagesById.delete(e)}));a.messages.length>0?this.messagesByFile.set(e,o):this.messagesByFile.delete(e);const n=this.haveMessagesChanged(i,o);return{...a,changed:n}}haveMessagesChanged(e,s){if(!e)return s.size>0;if(e.size!==s.size)return!0;for(const[t,a]of e){const e=s.get(t);if(!e||!this.areMessagesEqual(a,e))return!0}return!1}areMessagesEqual(e,s){return e.id===s.id&&e.message===s.message&&e.description===s.description&&this.areReferencesEqual(e.references,s.references)}areReferencesEqual(e,s){if(!e&&!s)return!0;if(!e||!s)return!1;if(e.length!==s.length)return!1;for(let t=0;t<e.length;t++)if(e[t].path!==s[t].path)return!1;return!0}async save(){return this.saveScheduler.schedule((()=>this.saveImpl()))}async saveImpl(){const e=Array.from(this.messagesById.values()),s=await this.getPersister();await s.write(this.config.sourceLocale,e);for(const e of await this.getTargetLocales())await this.saveLocale(e);return e.length}async saveLocale(e){const s=Array.from(this.messagesById.values()),t=await this.getPersister(),a=this.lastWriteByLocale.get(e),i=await t.getLastModified(e);if(i&&a&&i>a){const s=await t.read(e),a=this.translationsByTargetLocale.get(e);for(const e of s)a.set(e.id,e.message)}const r=this.translationsByTargetLocale.get(e),o=s.map((e=>({...e,message:r.get(e.id)||""})));await t.write(e,o);const c=await t.getLastModified(e);this.lastWriteByLocale.set(e,c)}onLocalesChange=async e=>{for(const s of e.added){const e=new Map;this.translationsByTargetLocale.set(s,e);const t=await this.loadLocaleMessages(s);for(const s of t)e.set(s.id,s.message);await this.saveLocale(s)}for(const s of e.removed)this.translationsByTargetLocale.delete(s),this.lastWriteByLocale.delete(s)};destroy(){this.saveScheduler.destroy(),this.catalogLocales&&this.isDevelopment&&this.catalogLocales.unsubscribeLocalesChange(this.onLocalesChange)}}export{n as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"fs/promises";import e from"path";class a{constructor(t,e){this.messagesPath=t,this.formatter=e}getFilePath(t){return e.join(this.messagesPath,t+this.formatter.EXTENSION)}async read(e){const a=this.getFilePath(e),r=await t.readFile(a,"utf8");return this.formatter.parse(r,{locale:e})}async write(a,r){const i=this.getFilePath(a),s=this.formatter.serialize(r,{locale:a});try{const a=e.dirname(i);await t.mkdir(a,{recursive:!0}),await t.writeFile(i,s)}catch(t){console.error(`❌ Failed to write catalog: ${t}`)}}async getLastModified(e){const a=this.getFilePath(e);try{return(await t.stat(a)).mtime}catch{return}}}export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class e{isSaving=!1;pendingResolvers=[];constructor(e=50){this.delayMs=e}async schedule(e){return new Promise(((s,i)=>{this.pendingResolvers.push({resolve:s,reject:i}),1!==this.pendingResolvers.length||this.isSaving?this.pendingResolvers.length>1&&this.scheduleSave(e):this.executeSave(e)}))}scheduleSave(e){this.saveTimeout&&clearTimeout(this.saveTimeout),this.saveTimeout=setTimeout((()=>{this.executeSave(e)}),this.delayMs)}async executeSave(e){if(!this.isSaving){this.isSaving=!0;try{const s=await e();this.pendingResolvers.forEach((({resolve:e})=>e(s)))}catch(e){this.pendingResolvers.forEach((({reject:s})=>s(e)))}finally{this.pendingResolvers=[],this.isSaving=!1}}}destroy(){this.saveTimeout&&(clearTimeout(this.saveTimeout),this.saveTimeout=void 0),this.pendingResolvers=[],this.isSaving=!1}}export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"path";import e from"./formatters/index.js";let n=null;function s(s){const a=this.getOptions(),o=this.async();(async function(t){if(!n){const s=(await e[t.messages.format]()).default;n=new s}return n})(a).then((e=>{const n=t.basename(this.resourcePath,e.EXTENSION),a=e.toJSONString(s,{locale:n}),r=`export default JSON.parse(${JSON.stringify(a)});`;o(null,r)})).catch(o)}export{s as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"./ExtractionCompiler.js";async function a(a){const o=new t(a);await o.extract()}export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"./ExtractionCompiler.js";let e;function o(o){const n=this.getOptions(),s=this.async();e||(e=new t(n,{isDevelopment:"development"===process.env["NODE_ENV".trim()]})),e.compile(this.resourcePath,o).then((t=>{s(null,t)})).catch(s)}export{o as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class s{vars=(()=>new Map)();constructor(s){this.parent=s}define(s,t,a){this.vars.set(s,{kind:t,namespace:a})}lookup(s){return this.vars.has(s)?this.vars.get(s):this.parent?.lookup(s)}}export{s as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"crypto";class e{static generate(e){return t.createHash("sha512").update(e).digest().toString("base64").slice(0,6)}}export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class e{constructor(e){this.maxSize=e,this.cache=new Map}set(e,t){if(!this.cache.has(e)&&this.cache.size>=this.maxSize){const e=this.cache.keys().next().value;void 0!==e&&this.cache.delete(e)}this.cache.set(e,{key:e,value:t})}get(e){const t=this.cache.get(e);if(t)return this.cache.delete(e),this.cache.set(e,t),t.value}}export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"path";import{parse as t,print as s}from"@swc/core";import{warn as n}from"../../plugin/utils.js";import i from"./ASTScope.js";import r from"./KeyGenerator.js";import a from"./LRUCache.js";class o{static NAMESPACE_SEPARATOR=".";compileCache=(()=>new a(750))();constructor(e){this.isDevelopment=e.isDevelopment,this.projectRoot=e.projectRoot}async processFileContent(s,n){const i=n,r=this.compileCache.get(i);if(r)return r;if(!n.includes("useExtracted")&&!n.includes("getExtracted"))return{messages:[],source:n};const a=await t(n,{syntax:"typescript",tsx:!0,target:"es2022",decorators:!0}),o=e.relative(this.projectRoot,s),l=await this.processAST(a,o),p=l.source?l:{...l,source:n};return this.compileCache.set(i,p),p}async processAST(t,a){const l=[];let p=null,c=null;const u=this.isDevelopment,f=[new i];function y(){return f[f.length-1]}function m(e){if("StringLiteral"===e.type)return e.value;if("TemplateLiteral"===e.type){const t=e;if(0===t.expressions.length&&1===t.quasis.length)return t.quasis[0].cooked||t.quasis[0].raw}return null}return function t(s){if("object"==typeof s){switch(s.type){case"ImportDeclaration":{const d=s;if("next-intl"===d.source.value){for(const v of d.specifiers)if("ImportSpecifier"===v.type){const g=v.imported?.value,x=v.local.value;"useExtracted"!==g&&"useExtracted"!==x||(p=x,c="useTranslations",v.imported=void 0,v.local.value="useTranslations")}}else if("next-intl/server"===d.source.value)for(const h of d.specifiers)if("ImportSpecifier"===h.type){const b=h.imported?.value,j=h.local.value;"getExtracted"!==b&&"getExtracted"!==j||(p=j,c="getTranslations",h.imported=void 0,h.local.value="getTranslations")}break}case"VariableDeclarator":{const E=s;let I=null;if("CallExpression"===E.init?.type&&"Identifier"===E.init.callee.type&&E.init.callee.value===p?I=E.init:"AwaitExpression"===E.init?.type&&"CallExpression"===E.init.argument.type&&"Identifier"===E.init.argument.callee.type&&E.init.argument.callee.value===p&&(I=E.init.argument),I&&"Identifier"===E.id.type){let S;if(I.arguments.length>0){const A=I.arguments[0].expression;if("StringLiteral"===A.type)S=A.value;else if("ObjectExpression"===A.type){const k=A;for(const w of k.properties)if("KeyValueProperty"===w.type){const C=w.key;if("Identifier"===C.type&&"namespace"===C.value){const T=m(w.value);null!=T&&(S=T);break}}}}y().define(E.id.value,"translator",S),c&&(I.callee.value=c)}break}case"CallExpression":{const O=s;let L,R=!1;if("Identifier"===O.callee.type){const D=O.callee.value,P=y().lookup(D);R="translator"===P?.kind,L=P?.namespace}else if("MemberExpression"===O.callee.type){const F=O.callee;if("Identifier"===F.object.type&&"Identifier"===F.property.type){const M=F.object.value,q=F.property.value,K=y().lookup(M);R="translator"===K?.kind&&("rich"===q||"markup"===q||"has"===q),L=K?.namespace}}if(R){const N=O.arguments[0]?.expression;let V=null,_=null,z=null,B=null,G=null;function J(t){const s="span"in t&&t.span&&"object"==typeof t.span&&"start"in t.span?e.basename(a):void 0;n((s?`${s}: `:"")+"Cannot extract message from dynamic expression, messages need to be statically analyzable. If you need to provide runtime values, pass them as a separate argument.")}if(N)if("ObjectExpression"===N.type){const U=N;for(const $ of U.properties)if("KeyValueProperty"===$.type){const H=$.key;if("Identifier"===H.type&&"id"===H.value){const Q=m($.value);null!==Q&&(_=Q)}else if("Identifier"===H.type&&"message"===H.value){const W=m($.value);null!=W?V=W:J($.value)}else if("Identifier"===H.type&&"description"===H.value){const X=m($.value);null!=X?z=X:J($.value)}else"Identifier"===H.type&&"values"===H.value?B=$.value:"Identifier"===H.type&&"formats"===H.value&&(G=$.value)}}else{const Y=m(N);null!=Y?V=Y:J(N)}if(V){const Z=_||r.generate(V),ee={id:L?[L,Z].join(o.NAMESPACE_SEPARATOR):Z,message:V,references:[{path:a}]};if(z&&(ee.description=z),l.push(ee),"StringLiteral"===N.type)N.value=Z,N.raw=void 0;else if("TemplateLiteral"===N.type)Object.assign(N,{type:"StringLiteral",value:Z,raw:void 0});else if("ObjectExpression"===N.type&&(Object.assign(N,{type:"StringLiteral",value:Z,raw:void 0}),B&&(O.arguments.length<2?O.arguments.push({expression:B}):O.arguments[1].expression=B),G)){for(;O.arguments.length<2;)O.arguments.push({expression:{type:"Identifier",value:"undefined",optional:!1,ctxt:1,span:{start:0,end:0,ctxt:0}}});O.arguments.length<3?O.arguments.push({expression:G}):O.arguments[2].expression=G}const te="MemberExpression"===O.callee.type&&"Identifier"===O.callee.property.type&&"has"===O.callee.property.value;if(u&&!te){for(;O.arguments.length<3;)O.arguments.push({expression:{type:"Identifier",value:"undefined",optional:!1,ctxt:1,span:{start:0,end:0,ctxt:0}}});O.arguments.push({expression:{type:"StringLiteral",value:V,raw:JSON.stringify(V),ctxt:1,span:{start:0,end:0,ctxt:0}}})}}}break}case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":case"BlockStatement":f.push(new i(y()));for(const se of Object.keys(s)){const ne=s[se];Array.isArray(ne)?ne.forEach((e=>{e&&"object"==typeof e&&("expression"in e&&"object"==typeof e.expression&&"type"in e.expression?t(e.expression):"type"in e&&t(e))})):ne&&"object"==typeof ne&&"type"in ne&&t(ne)}return void f.pop()}for(const ie of Object.keys(s)){const re=s[ie];Array.isArray(re)?re.forEach((e=>{e&&"object"==typeof e&&("expression"in e&&e.expression&&"object"==typeof e.expression&&"type"in e.expression?t(e.expression):"type"in e&&t(e))})):re&&"object"==typeof re&&"type"in re&&t(re)}}}(t),{messages:l,source:(await s(t)).code}}}export{o as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class a{}export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{setNestedProperty as s}from"../utils/ObjectUtils.js";import t from"./Formatter.js";import{getSortedMessages as e}from"./utils.js";class r extends t{static NAMESPACE_SEPARATOR=".";EXTENSION=".json";parse(s){const t=JSON.parse(s),e=[];return this.traverseMessages(t,((s,t)=>{e.push({id:t,message:s})})),e}serialize(t){const r={};for(const o of e(t))s(r,o.id,o.message);return JSON.stringify(r,null,2)}toJSONString(s){return s}traverseMessages(s,t,e=""){for(const o of Object.keys(s)){const i=e?e+r.NAMESPACE_SEPARATOR+o:o,a=s[o];"string"==typeof a?t(a,i):"object"==typeof a&&this.traverseMessages(a,t,i)}}}export{r as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{setNestedProperty as t}from"../utils/ObjectUtils.js";import e from"../utils/POParser.js";import s from"./Formatter.js";import{getSortedMessages as a}from"./utils.js";class r extends s{static DEFAULT_METADATA={"Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"8bit","X-Generator":"next-intl","X-Crowdin-SourceKey":"msgstr"};EXTENSION=".po";metadataByLocale=(()=>new Map)();parse(t,s){const a=e.parse(t);return a.meta&&this.metadataByLocale.set(s.locale,a.meta),a.messages||[]}serialize(t,s){const o={Language:s.locale,...r.DEFAULT_METADATA,...this.metadataByLocale.get(s.locale)};return e.serialize({meta:o,messages:a(t)})}toJSONString(e,s){const a=this.parse(e,s),r={};for(const e of a)t(r,e.id,e.message);return JSON.stringify(r,null,2)}}export{r as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t={json:()=>import("./JSONFormatter.js"),po:()=>import("./POFormatter.js")};export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return e.toSorted(((e,r)=>{const s=e.references?.[0]?.path??e.message,a=r.references?.[0]?.path??r.message;return s===a?e.message.localeCompare(r.message):s.localeCompare(a)}))}export{e as getSortedMessages};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"path";class s{static EXTENSIONS=["ts","tsx","js","jsx"];static isSourceFile(a){const e=t.extname(a);return s.EXTENSIONS.map((t=>"."+t)).includes(e)}}export{s as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"fs/promises";import r from"path";import i from"./SourceFileFilter.js";class a{static async walkSourceFiles(s,t,o=[]){const l=await e.readdir(s,{withFileTypes:!0});for(const e of l){const l=r.join(s,e.name);e.isDirectory()?await a.walkSourceFiles(l,t,o):i.isSourceFile(e.name)&&o.push(l)}return o}static async getSourceFiles(e){return(await Promise.all(e.map((r=>a.walkSourceFiles(r,e))))).flat()}}export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(t,n,e){const l=n.split(".");let o=t;for(let t=0;t<l.length-1;t++){const n=l[t];n in o&&"object"==typeof o[n]&&null!==o[n]||(o[n]={}),o=o[n]}o[l[l.length-1]]=e}export{t as setNestedProperty};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class t{static KEYWORDS={MSGID:"msgid",MSGSTR:"msgstr",MSGCTXT:"msgctxt",MSGID_PLURAL:"msgid_plural"};static COMMENTS={REFERENCE:"#:",EXTRACTED:"#.",TRANSLATOR:"#",FLAG:"#,",PREVIOUS:"#|"};static NAMESPACE_SEPARATOR=".";static QUOTE='"';static NEWLINE="\\n";static FILE_COLUMN_SEPARATOR=":";static META_SEPARATOR=":";static parse(e){const s=t.splitLines(e),i=[],r={};let n,E="entry";for(let e=0;e<s.length;e++){const a=s[e].trim();if(a)if("meta"===E)if(a.startsWith(t.QUOTE)){const e=t.extractQuotedString(a,E),s=e.endsWith(t.NEWLINE)?e.slice(0,-2):e,i=s.indexOf(t.META_SEPARATOR);if(i>0){const t=s.substring(0,i).trim(),e=s.substring(i+1).trim();r[t]=e}}else t.throwWithLine("Encountered unexpected non-quoted metadata line",a);else{if(t.lineStartsWithPrefix(a,t.COMMENTS.TRANSLATOR)&&t.throwWithLine("Translator comments (#) are not supported, use inline descriptions instead",a),t.lineStartsWithPrefix(a,t.COMMENTS.FLAG)&&t.throwWithLine("Flag comments (#,) are not supported",a),t.lineStartsWithPrefix(a,t.COMMENTS.PREVIOUS)&&t.throwWithLine("Previous string key comments (#|) are not supported",a),t.lineStartsWithPrefix(a,t.COMMENTS.REFERENCE)){n=t.ensureEntry(n);const e=a.substring(t.COMMENTS.REFERENCE.length).trim().split(t.FILE_COLUMN_SEPARATOR).at(0);n.references??=[],n.references.push({path:e});continue}if(t.lineStartsWithPrefix(a,t.COMMENTS.EXTRACTED)){n=t.ensureEntry(n),n.description=a.substring(t.COMMENTS.EXTRACTED.length).trim();continue}if(t.lineStartsWithPrefix(a,t.KEYWORDS.MSGID_PLURAL)&&t.throwWithLine("Plural forms (msgid_plural) are not supported, use ICU pluralization instead",a),t.lineStartsWithPrefix(a,t.KEYWORDS.MSGCTXT)){n=t.ensureEntry(n),n.msgctxt=t.extractQuotedString(a.substring(t.KEYWORDS.MSGCTXT.length+1),E);continue}if(t.lineStartsWithPrefix(a,t.KEYWORDS.MSGID)){n=t.ensureEntry(n),n.msgid=t.extractQuotedString(a.substring(t.KEYWORDS.MSGID.length+1),E),t.isMetaEntry(n,i)&&(E="meta",n=void 0);continue}if(t.lineStartsWithPrefix(a,t.KEYWORDS.MSGSTR)){n=t.ensureEntry(n),n.msgstr=t.extractQuotedString(a.substring(t.KEYWORDS.MSGSTR.length+1),E),t.isMetaEntry(n,i)&&(E="meta",n=void 0);continue}a.startsWith(t.QUOTE)&&t.throwWithLine("Multi-line strings are not supported, use single-line strings instead",a)}else"entry"===E&&n&&(i.push(t.finishEntry(n)),n=void 0),E="entry"}return"entry"===E&&n&&i.push(t.finishEntry(n)),{meta:Object.keys(r).length>0?r:void 0,messages:i.length>0?i:void 0}}static isMetaEntry(t,e){return 0===e.length&&""===t.msgid&&""===t.msgstr}static serialize(e){const s=[];if(e.meta){s.push(`${t.KEYWORDS.MSGID} ${t.QUOTE}${t.QUOTE}`),s.push(`${t.KEYWORDS.MSGSTR} ${t.QUOTE}${t.QUOTE}`);for(const[i,r]of Object.entries(e.meta))s.push(`${t.QUOTE}${i}${t.META_SEPARATOR} ${r}${t.NEWLINE}${t.QUOTE}`);s.push("")}if(e.messages)for(const i of e.messages){if(i.description&&s.push(`${t.COMMENTS.EXTRACTED} ${i.description}`),i.references&&i.references.length>0)for(const e of i.references)s.push(`${t.COMMENTS.REFERENCE} ${e.path}`);let e,r;const n=i.id.lastIndexOf(t.NAMESPACE_SEPARATOR);n>0?(e=i.id.substring(0,n),r=i.id.substring(n+1)):r=i.id,e&&s.push(`${t.KEYWORDS.MSGCTXT} ${t.QUOTE}${e}${t.QUOTE}`),s.push(`${t.KEYWORDS.MSGID} ${t.QUOTE}${r}${t.QUOTE}`),s.push(`${t.KEYWORDS.MSGSTR} ${t.QUOTE}${i.message}${t.QUOTE}`),s.push("")}return s.join("\n")}static lineStartsWithPrefix(t,e){return t.startsWith(e+" ")}static throwWithLine(t,e){throw new Error(`${t}:\n> ${e}`)}static splitLines(t){return t.includes("\r")&&(t=t.replace(/\r\n/g,"\n")),t.split("\n")}static ensureEntry(t){return t||{}}static finishEntry(e){if(null==e.msgid||null==e.msgstr)throw new Error("Incomplete message entry: both msgid and msgstr are required");let s=e.msgid;return e.msgctxt&&(s=e.msgctxt+t.NAMESPACE_SEPARATOR+e.msgid),{id:s,message:e.msgstr,description:e.description,references:e.references}}static extractQuotedString(e,s){const i=e.trim(),r=i.indexOf(t.QUOTE,t.QUOTE.length);if(-1===r){if("meta"===s)return i.substring(t.QUOTE.length);t.throwWithLine("Incomplete quoted string",e)}return i.substring(t.QUOTE.length,r)}}export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{default as unstable_extractMessages}from"./extractor/extractMessages.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{useFormatter,useTranslations}from"./react-client/index.js";export{default as NextIntlClientProvider}from"./shared/NextIntlClientProvider.js";export*from"use-intl";
|
|
1
|
+
export{useFormatter,useTranslations}from"./react-client/index.js";export{default as NextIntlClientProvider}from"./shared/NextIntlClientProvider.js";export{IntlProvider,_useExtracted as useExtracted,useLocale,useMessages,useNow,useTimeZone}from"use-intl/react";export*from"use-intl/core";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{default as useLocale}from"./react-server/useLocale.js";export{default as useTranslations}from"./react-server/useTranslations.js";export{default as useFormatter}from"./react-server/useFormatter.js";export{default as useNow}from"./react-server/useNow.js";export{default as useTimeZone}from"./react-server/useTimeZone.js";export{default as useMessages}from"./react-server/useMessages.js";export{default as NextIntlClientProvider}from"./react-server/NextIntlClientProviderServer.js";export*from"use-intl/core";
|
|
1
|
+
export{default as useLocale}from"./react-server/useLocale.js";export{default as useTranslations}from"./react-server/useTranslations.js";export{default as useFormatter}from"./react-server/useFormatter.js";export{default as useNow}from"./react-server/useNow.js";export{default as useTimeZone}from"./react-server/useTimeZone.js";export{default as useMessages}from"./react-server/useMessages.js";export{default as NextIntlClientProvider}from"./react-server/NextIntlClientProviderServer.js";export{default as useExtracted}from"./react-server/useExtracted.js";export*from"use-intl/core";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{normalizeTrailingSlash as e,getSortedPathnames as t,matchesPathname as n,prefixPathname as r,getLocalePrefix as o,templateToRegex as c,getLocalizedTemplate as i}from"../shared/utils.js";function s(e,r,o){const c=t(Object.keys(e));for(const t of c){const c=e[t];if("string"==typeof c){if(n(c,r))return[void 0,t]}else{const s=Object.entries(c),f=s.findIndex((([e])=>e===o));f>0&&s.unshift(s.splice(f,1)[0]);for(const[o]of s){const c=i(e[t],o,t);if(n(c,r))return[o,t]}}}for(const t of Object.keys(e))if(n(t,r))return[void 0,t];return[void 0,void 0]}function f(t,n,r,o){let c="";return c+=h(r,d(n,t)),c=e(c),c}function l(t,n,r){t.endsWith("/")||(t+="/");const o=u(n,r),c=new RegExp(`^(${o.map((([,e])=>e.replaceAll("/","\\/"))).join("|")})/(.*)`,"i"),i=t.match(c);let s=i?"/"+i[2]:t;return"/"!==s&&(s=e(s)),s}function u(e,t,n=!0){const r=e.map((e=>[e,o(e,t)]));return n&&r.sort(((e,t)=>t[1].length-e[1].length)),r}function a(e,t,n,r){const o=u(t,n);r&&o.sort((([e],[t])=>{if(e===r.defaultLocale)return-1;if(t===r.defaultLocale)return 1;const n=r.locales.includes(e),o=r.locales.includes(t);return n&&!o?-1:!n&&o?1:0}));for(const[t,n]of o){let r,o;if(e===n||e.startsWith(n+"/"))r=o=!0;else{const t=e.toLowerCase(),c=n.toLowerCase();(t===c||t.startsWith(c+"/"))&&(r=!1,o=!0)}if(o)return{locale:t,prefix:n,matchedPrefix:e.slice(0,n.length),exact:r}}}function d(t,n){const r=e(n),o=e(t),i=c(o).exec(r);if(!i)return;const s={};for(let e=1;e<i.length;e++){const t=
|
|
1
|
+
import{normalizeTrailingSlash as e,getSortedPathnames as t,matchesPathname as n,prefixPathname as r,getLocalePrefix as o,templateToRegex as c,getLocalizedTemplate as i}from"../shared/utils.js";function s(e,r,o){const c=t(Object.keys(e));for(const t of c){const c=e[t];if("string"==typeof c){if(n(c,r))return[void 0,t]}else{const s=Object.entries(c),f=s.findIndex((([e])=>e===o));f>0&&s.unshift(s.splice(f,1)[0]);for(const[o]of s){const c=i(e[t],o,t);if(n(c,r))return[o,t]}}}for(const t of Object.keys(e))if(n(t,r))return[void 0,t];return[void 0,void 0]}function f(t,n,r,o){let c="";return c+=h(r,d(n,t)),c=e(c),c}function l(t,n,r){t.endsWith("/")||(t+="/");const o=u(n,r),c=new RegExp(`^(${o.map((([,e])=>e.replaceAll("/","\\/"))).join("|")})/(.*)`,"i"),i=t.match(c);let s=i?"/"+i[2]:t;return"/"!==s&&(s=e(s)),s}function u(e,t,n=!0){const r=e.map((e=>[e,o(e,t)]));return n&&r.sort(((e,t)=>t[1].length-e[1].length)),r}function a(e,t,n,r){const o=u(t,n);r&&o.sort((([e],[t])=>{if(e===r.defaultLocale)return-1;if(t===r.defaultLocale)return 1;const n=r.locales.includes(e),o=r.locales.includes(t);return n&&!o?-1:!n&&o?1:0}));for(const[t,n]of o){let r,o;if(e===n||e.startsWith(n+"/"))r=o=!0;else{const t=e.toLowerCase(),c=n.toLowerCase();(t===c||t.startsWith(c+"/"))&&(r=!1,o=!0)}if(o)return{locale:t,prefix:n,matchedPrefix:e.slice(0,n.length),exact:r}}}function d(t,n){const r=e(n),o=e(t),i=c(o).exec(r);if(!i)return;const s={},f=o.match(/\[([^\]]+)\]/g)??[];for(let e=1;e<i.length;e++){const t=f[e-1];if(!t)continue;const n=t.replace(/[[\]]/g,""),r=i[e]??"";s[n]=r}return s}function h(e,t){if(!t)return e;let n=e=e.replace(/\[\[/g,"[").replace(/\]\]/g,"]");return Object.entries(t).forEach((([e,t])=>{n=n.replace(`[${e}]`,t)})),n}function p(e,t,n){let o=e;return t&&(o=r(t,o)),n&&(o+=n),o}function g(e){return e.get("x-forwarded-host")??e.get("host")??void 0}function x(e,t){return t.defaultLocale===e||t.locales.includes(e)}function m(e,t,n){let r;return e&&x(t,e)&&(r=e),r||(r=n.find((e=>e.defaultLocale===t))),r||(r=n.find((e=>e.locales.includes(t)))),r}function j(t,n){return e(n+t)}function L(e){return`/${e}`}function v(e){return e.replace(/\\/g,"%5C").replace(/\/+/g,"/")}export{j as applyBasePath,p as formatPathname,h as formatPathnameTemplate,f as formatTemplatePathname,m as getBestMatchingDomain,g as getHost,s as getInternalTemplate,L as getLocaleAsPrefix,u as getLocalePrefixes,l as getNormalizedPathname,a as getPathnameMatch,d as getRouteParams,x as isLocaleSupportedOnDomain,v as sanitizePathname};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"./
|
|
1
|
+
import e from"./getNextConfig.js";import{warn as t}from"./utils.js";import n from"./declaration/createMessagesDeclaration.js";function r(r={}){const o="string"==typeof r?{requestConfig:r}:r;return function(r){return function(r,o){null!=o?.i18n&&t("\n[next-intl] An `i18n` property was found in your Next.js config. This likely causes conflicts and should therefore be removed if you use the App Router.\n\nIf you're in progress of migrating from the Pages Router, you can refer to this example: https://next-intl.dev/examples#app-router-migration\n");const i=r.experimental?.createMessagesDeclaration;return i&&n("string"==typeof i?[i]:i),e(r,o)}(o,r)}}export{r as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"fs";import s from"path";import{throwError as t}from"../utils.js";import o from"../watchFile.js";function n(o){var n;["info","start"].some((e=>process.argv.includes(e)))||(n=()=>{for(const n of o){const o=s.resolve(n);e.existsSync(o)||t(`\`createMessagesDeclaration\` points to a non-existent file: ${o}`),o.endsWith(".json")||t(`\`createMessagesDeclaration\` needs to point to a JSON file. Received: ${o}`);const c=process.env["NODE_ENV".trim()];i(n),"development"===c&&r(n)}},"1"!==process.env._NEXT_INTL_COMPILE_MESSAGES&&(process.env._NEXT_INTL_COMPILE_MESSAGES="1",n()))}function r(e){const s=o(e,(()=>{i(e,!0)}));process.on("exit",(()=>{s.close()}))}function i(s,t=!1){const o=s.replace(/\.json$/,".d.json.ts");function n(e){return`// This file is auto-generated by next-intl, do not edit directly.\n// See: https://next-intl.dev/docs/workflows/typescript#messages-arguments\n\ndeclare const messages: ${e.trim()};\nexport default messages;`}if(t)return e.promises.readFile(s,"utf-8").then((s=>e.promises.writeFile(o,n(s))));const r=e.readFileSync(s,"utf-8");e.writeFileSync(o,n(r))}export{n as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import e from"fs";import t from"path";import r from"../extractor/source/SourceFileFilter.js";import{isNextJs16OrHigher as s,hasStableTurboConfig as n}from"./nextFlags.js";import{throwError as o}from"./utils.js";function a(e){return[`${e}.ts`,`${e}.tsx`,`${e}.js`,`${e}.jsx`]}function i(r,s){function n(r){return e.existsSync(function(e){const r=[];return s&&r.push(s),r.push(e),t.resolve(...r)}(r))}if(r)return n(r)||o(`Could not find i18n config at ${r}, please provide a valid path.`),r;for(const e of[...a("./i18n/request"),...a("./src/i18n/request")])if(n(e))return e;o("Could not locate request configuration module.\n\nThis path is supported by default: ./(src/)i18n/request.{js,jsx,ts,tsx}\n\nAlternatively, you can specify a custom location in your Next.js config:\n\nconst withNextIntl = createNextIntlPlugin(\n\nAlternatively, you can specify a custom location in your Next.js config:\n\nconst withNextIntl = createNextIntlPlugin(\n './path/to/i18n/request.tsx'\n);")}function l(e,a){const l={};function u(){const t=e.experimental;return t.srcPath&&t.messages||o("`srcPath` and `messages` are required when using `extractor`."),{loader:"next-intl/extractor/extractionLoader",options:{srcPath:t.srcPath,sourceLocale:t.extract.sourceLocale,messages:t.messages}}}function c(){return{loader:"next-intl/extractor/catalogLoader",options:{messages:e.experimental.messages}}}function p(){return a?.turbopack?.rules||a?.experimental?.turbo?.rules||{}}function x(e,t,r){e[t]?Array.isArray(e[t])?e[t].push(r):e[t]=[e[t],r]:e[t]=r}if(null!=process.env.TURBOPACK){e.requestConfig&&t.isAbsolute(e.requestConfig)&&o("Turbopack support for next-intl currently does not support absolute paths, please provide a relative one (e.g. './src/i18n/config.ts').\n\nFound: "+e.requestConfig);const m={"next-intl/config":i(e.requestConfig)};let f;e.experimental?.extract&&(s()||o("Message extraction requires Next.js 16 or higher."),f??=p(),x(f,`*.{${r.EXTENSIONS.join(",")}}`,{loaders:[u()],condition:{path:(Array.isArray(e.experimental.srcPath)?`{${e.experimental.srcPath.join(",")}}`:e.experimental.srcPath)+"/**/*",content:/(useExtracted|getExtracted)/}})),e.experimental?.messages&&(s()||o("Message catalog loading requires Next.js 16 or higher."),f??=p(),x(f,`*.${e.experimental.messages.format}`,{loaders:[c()],condition:{path:`${e.experimental.messages.path}/**/*`},as:"*.js"})),n()&&!a?.experimental?.turbo?l.turbopack={...a?.turbopack,...f&&{rules:f},resolveAlias:{...a?.turbopack?.resolveAlias,...m}}:l.experimental={...a?.experimental,turbo:{...a?.experimental?.turbo,...f&&{rules:f},resolveAlias:{...a?.experimental?.turbo?.resolveAlias,...m}}}}else l.webpack=function(s,n){if(s.resolve||(s.resolve={}),s.resolve.alias||(s.resolve.alias={}),s.resolve.alias["next-intl/config"]=t.resolve(s.context,i(e.requestConfig,s.context)),e.experimental?.extract){s.module||(s.module={}),s.module.rules||(s.module.rules=[]);const n=e.experimental.srcPath;s.module.rules.push({test:new RegExp(`\\.(${r.EXTENSIONS.join("|")})$`),include:Array.isArray(n)?n.map((e=>t.resolve(s.context,e))):t.resolve(s.context,n||""),use:[u()]})}return e.experimental?.messages&&(s.module||(s.module={}),s.module.rules||(s.module.rules=[]),s.module.rules.push({test:new RegExp(`\\.${e.experimental.messages.format}$`),include:t.resolve(s.context,e.experimental.messages.path),use:[c()],type:"javascript/auto"})),"function"==typeof a?.webpack?a.webpack(s,n):s};return a?.trailingSlash&&(l.env={...a.env,_next_intl_trailing_slash:"true"}),Object.assign({},a,l)}export{l as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as t}from"module";function r(){try{const r=t(import.meta.url);return r("next/package.json").version}catch(t){throw new Error("Failed to get current Next.js version. This can happen if next-intl/plugin is imported into your app code outside of your next.config.js.",{cause:t})}}function n(t,r){const n=t.split(".").map(Number),e=r.split(".").map(Number);for(let t=0;t<3;t++){const r=n[t]||0,o=e[t]||0;if(r>o)return 1;if(r<o)return-1}return 0}function e(){return n(r(),"15.3.0")>=0}function o(){return n(r(),"16.0.0")>=0}export{e as hasStableTurboConfig,o as isNextJs16OrHigher};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useFormatter as r,useTranslations as t}from"use-intl";
|
|
1
|
+
import{useFormatter as r,useTranslations as t}from"use-intl";function o(r,t){return(...r)=>{try{return t(...r)}catch{throw new Error(void 0)}}}const n=o(0,t),e=o(0,r);export{e as useFormatter,n as useTranslations};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import r from"../server/react-server/getServerExtractor.js";import e from"./useConfig.js";function t(t){const o=e("useExtracted");return r(o,t)}export{t as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e){return()=>{throw new Error(`\`${e}\` is not supported in Client Components.`)}}function t(...t){return e("getRequestConfig")}const n=e("getFormatter"),o=e("getNow"),r=e("getTimeZone"),s=e("getMessages"),g=e("getLocale"),i=e("getTranslations"),u=e("setRequestLocale");export{n as getFormatter,g as getLocale,s as getMessages,o as getNow,t as getRequestConfig,r as getTimeZone,
|
|
1
|
+
function e(e){return()=>{throw new Error(`\`${e}\` is not supported in Client Components.`)}}function t(...t){return e("getRequestConfig")}const n=e("getFormatter"),o=e("getNow"),r=e("getTimeZone"),s=e("getMessages"),g=e("getLocale"),i=e("getExtracted"),a=e("getTranslations"),u=e("setRequestLocale");export{i as getExtracted,n as getFormatter,g as getLocale,s as getMessages,o as getNow,t as getRequestConfig,r as getTimeZone,a as getTranslations,u as setRequestLocale};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{cache as t}from"react";import r from"./getConfig.js";import o from"./getServerExtractor.js";const e=t((async function(t){let e,a;"string"==typeof t?e=t:t&&(a=t.locale,e=t.namespace);const n=await r(a);return o(n,e)}));export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{cache as r}from"react";import o from"./getServerTranslator.js";var t=r((function(r,t){const n=o(r,t);function i(...[r,o,t]){return n(void 0,o,t,void 0)}return i.rich=function(...[r,o,t]){return n.rich(void 0,o,t,void 0)},i.markup=function(...[r,o,t]){return n.markup(void 0,o,t,void 0)},i.has=function(...[r]){return!0},i}));export{t as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{getFormatter,getLocale,getMessages,getNow,getRequestConfig,getTimeZone,getTranslations,setRequestLocale}from"./server/react-client/index.js";
|
|
1
|
+
export{getExtracted,getFormatter,getLocale,getMessages,getNow,getRequestConfig,getTimeZone,getTranslations,setRequestLocale}from"./server/react-client/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{default as getRequestConfig}from"./server/react-server/getRequestConfig.js";export{default as getFormatter}from"./server/react-server/getFormatter.js";export{default as getNow}from"./server/react-server/getNow.js";export{default as getTimeZone}from"./server/react-server/getTimeZone.js";export{default as getMessages}from"./server/react-server/getMessages.js";export{default as getLocale}from"./server/react-server/getLocale.js";export{default as getTranslations}from"./server/react-server/getTranslations.js";export{setCachedRequestLocale as setRequestLocale}from"./server/react-server/RequestLocaleCache.js";
|
|
1
|
+
export{default as getRequestConfig}from"./server/react-server/getRequestConfig.js";export{default as getFormatter}from"./server/react-server/getFormatter.js";export{default as getNow}from"./server/react-server/getNow.js";export{default as getTimeZone}from"./server/react-server/getTimeZone.js";export{default as getExtracted}from"./server/react-server/getExtracted.js";export{default as getMessages}from"./server/react-server/getMessages.js";export{default as getLocale}from"./server/react-server/getLocale.js";export{default as getTranslations}from"./server/react-server/getTranslations.js";export{setCachedRequestLocale as setRequestLocale}from"./server/react-server/RequestLocaleCache.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function n(n){return function(n){return"object"==typeof n?null==n.host&&null==n.hostname:!/^[a-z]+:/i.test(n)}(n)&&!function(n){const t="object"==typeof n?n.pathname:n;return null!=t&&!t.startsWith("/")}(n)}function t(n,t){return n.replace(new RegExp(`^${t}`),"")||"/"}function e(n,t){let e=n;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),e+=t,e}function r(n,t){return t===n||t.startsWith(`${n}/`)}function u(n,t,e){return"string"==typeof n?n:n[t]||e}function i(n){const t=function(){try{return"true"===process.env._next_intl_trailing_slash}catch{return!1}}(),[e,...r]=n.split("#"),u=r.join("#");let i=e;if("/"!==i){const n=i.endsWith("/");t&&!n?i+="/":!t&&n&&(i=i.slice(0,-1))}return u&&(i+="#"+u),i}function c(n,t){const e=i(n),r=i(t);return s(e).test(r)}function o(n,t){return"never"!==t.mode&&t.prefixes?.[n]||f(n)}function f(n){return"/"+n}function s(n){const t=n.replace(
|
|
1
|
+
function n(n){return function(n){return"object"==typeof n?null==n.host&&null==n.hostname:!/^[a-z]+:/i.test(n)}(n)&&!function(n){const t="object"==typeof n?n.pathname:n;return null!=t&&!t.startsWith("/")}(n)}function t(n,t){return n.replace(new RegExp(`^${t}`),"")||"/"}function e(n,t){let e=n;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),e+=t,e}function r(n,t){return t===n||t.startsWith(`${n}/`)}function u(n,t,e){return"string"==typeof n?n:n[t]||e}function i(n){const t=function(){try{return"true"===process.env._next_intl_trailing_slash}catch{return!1}}(),[e,...r]=n.split("#"),u=r.join("#");let i=e;if("/"!==i){const n=i.endsWith("/");t&&!n?i+="/":!t&&n&&(i=i.slice(0,-1))}return u&&(i+="#"+u),i}function c(n,t){const e=i(n),r=i(t);return s(e).test(r)}function o(n,t){return"never"!==t.mode&&t.prefixes?.[n]||f(n)}function f(n){return"/"+n}function s(n){const t=n.replace(/\/\[\[(\.\.\.[^\]]+)\]\]/g,"(?:/(.*))?").replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"(?:/(.*))?").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp(`^${t}$`)}function l(n){return n.includes("[[...")}function p(n){return n.includes("[...")}function a(n){return n.includes("[")}function h(n,t){const e=n.split("/"),r=t.split("/"),u=Math.max(e.length,r.length);for(let n=0;n<u;n++){const t=e[n],u=r[n];if(!t&&u)return-1;if(t&&!u)return 1;if(t||u){if(!a(t)&&a(u))return-1;if(a(t)&&!a(u))return 1;if(!p(t)&&p(u))return-1;if(p(t)&&!p(u))return 1;if(!l(t)&&l(u))return-1;if(l(t)&&!l(u))return 1}}return 0}function g(n){return n.sort(h)}function x(n){return"function"==typeof n.then}export{f as getLocaleAsPrefix,o as getLocalePrefix,u as getLocalizedTemplate,g as getSortedPathnames,r as hasPathnamePrefixed,n as isLocalizableHref,x as isPromise,c as matchesPathname,i as normalizeTrailingSlash,e as prefixPathname,s as templateToRegex,t as unprefixPathname};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ExtractorConfig } from './types.js';
|
|
2
|
+
export default class ExtractionCompiler implements Disposable {
|
|
3
|
+
private manager;
|
|
4
|
+
private isDevelopment;
|
|
5
|
+
private initialScanPromise;
|
|
6
|
+
constructor(config: ExtractorConfig, opts?: {
|
|
7
|
+
isDevelopment?: boolean;
|
|
8
|
+
projectRoot?: string;
|
|
9
|
+
});
|
|
10
|
+
compile(resourcePath: string, source: string): Promise<string>;
|
|
11
|
+
private performInitialScan;
|
|
12
|
+
extract(): Promise<void>;
|
|
13
|
+
[Symbol.dispose](): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Locale, MessagesConfig } from '../types.js';
|
|
2
|
+
type LocaleChangeCallback = (params: {
|
|
3
|
+
added: Array<Locale>;
|
|
4
|
+
removed: Array<Locale>;
|
|
5
|
+
}) => unknown;
|
|
6
|
+
type CatalogLocalesParams = {
|
|
7
|
+
messagesDir: string;
|
|
8
|
+
sourceLocale: Locale;
|
|
9
|
+
extension: string;
|
|
10
|
+
locales: MessagesConfig['locales'];
|
|
11
|
+
};
|
|
12
|
+
export default class CatalogLocales {
|
|
13
|
+
private messagesDir;
|
|
14
|
+
private extension;
|
|
15
|
+
private sourceLocale;
|
|
16
|
+
private locales;
|
|
17
|
+
private watcher?;
|
|
18
|
+
private cleanupHandlers;
|
|
19
|
+
private targetLocales?;
|
|
20
|
+
private onChangeCallbacks;
|
|
21
|
+
constructor(params: CatalogLocalesParams);
|
|
22
|
+
getTargetLocales(): Promise<Array<Locale>>;
|
|
23
|
+
private readTargetLocales;
|
|
24
|
+
subscribeLocalesChange(callback: LocaleChangeCallback): void;
|
|
25
|
+
unsubscribeLocalesChange(callback: LocaleChangeCallback): void;
|
|
26
|
+
private startWatcher;
|
|
27
|
+
private stopWatcher;
|
|
28
|
+
private onChange;
|
|
29
|
+
private setupCleanupHandlers;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ExtractedMessage, ExtractorConfig } from '../types.js';
|
|
2
|
+
export default class CatalogManager {
|
|
3
|
+
private config;
|
|
4
|
+
private messagesByFile;
|
|
5
|
+
private messagesById;
|
|
6
|
+
/**
|
|
7
|
+
* This potentially also includes outdated ones that were initially available,
|
|
8
|
+
* but are not used anymore. This allows to restore them if they are used again.
|
|
9
|
+
**/
|
|
10
|
+
private translationsByTargetLocale;
|
|
11
|
+
private lastWriteByLocale;
|
|
12
|
+
private saveScheduler;
|
|
13
|
+
private projectRoot;
|
|
14
|
+
private isDevelopment;
|
|
15
|
+
private persister?;
|
|
16
|
+
private formatter?;
|
|
17
|
+
private catalogLocales?;
|
|
18
|
+
private messageExtractor;
|
|
19
|
+
constructor(config: ExtractorConfig, opts?: {
|
|
20
|
+
projectRoot?: string;
|
|
21
|
+
isDevelopment?: boolean;
|
|
22
|
+
});
|
|
23
|
+
private getFormatter;
|
|
24
|
+
private getPersister;
|
|
25
|
+
private getCatalogLocales;
|
|
26
|
+
private getTargetLocales;
|
|
27
|
+
getSrcPaths(): Array<string>;
|
|
28
|
+
getFileMessages(absoluteFilePath: string): Map<string, ExtractedMessage> | undefined;
|
|
29
|
+
loadMessages(): Promise<void>;
|
|
30
|
+
private loadSourceMessages;
|
|
31
|
+
private loadLocaleMessages;
|
|
32
|
+
private loadTargetMessages;
|
|
33
|
+
extractFileMessages(absoluteFilePath: string, source: string): Promise<{
|
|
34
|
+
messages: Array<ExtractedMessage>;
|
|
35
|
+
source: string;
|
|
36
|
+
changed: boolean;
|
|
37
|
+
}>;
|
|
38
|
+
private haveMessagesChanged;
|
|
39
|
+
private areMessagesEqual;
|
|
40
|
+
private areReferencesEqual;
|
|
41
|
+
save(): Promise<number>;
|
|
42
|
+
private saveImpl;
|
|
43
|
+
private saveLocale;
|
|
44
|
+
private onLocalesChange;
|
|
45
|
+
destroy(): void;
|
|
46
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type Formatter from '../formatters/Formatter.js';
|
|
2
|
+
import type { ExtractedMessage, Locale } from '../types.js';
|
|
3
|
+
export default class CatalogPersister {
|
|
4
|
+
private messagesPath;
|
|
5
|
+
private formatter;
|
|
6
|
+
constructor(messagesPath: string, formatter: Formatter);
|
|
7
|
+
private getFilePath;
|
|
8
|
+
read(locale: Locale): Promise<Array<ExtractedMessage>>;
|
|
9
|
+
write(locale: Locale, messages: Array<ExtractedMessage>): Promise<void>;
|
|
10
|
+
getLastModified(locale: Locale): Promise<Date | undefined>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type SaveTask<T> = () => Promise<T>;
|
|
2
|
+
/**
|
|
3
|
+
* De-duplicates excessive save invocations,
|
|
4
|
+
* while keeping a single one instant.
|
|
5
|
+
*/
|
|
6
|
+
export default class SaveScheduler<Value> {
|
|
7
|
+
private saveTimeout?;
|
|
8
|
+
private isSaving;
|
|
9
|
+
private delayMs;
|
|
10
|
+
private pendingResolvers;
|
|
11
|
+
constructor(delayMs?: number);
|
|
12
|
+
schedule(saveTask: SaveTask<Value>): Promise<Value>;
|
|
13
|
+
private scheduleSave;
|
|
14
|
+
private executeSave;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type VarInfo = {
|
|
2
|
+
kind: string;
|
|
3
|
+
namespace?: string;
|
|
4
|
+
};
|
|
5
|
+
export default class ASTScope {
|
|
6
|
+
parent?: ASTScope;
|
|
7
|
+
vars: Map<string, VarInfo>;
|
|
8
|
+
constructor(parent?: ASTScope);
|
|
9
|
+
define(name: string, kind: string, namespace?: string): void;
|
|
10
|
+
lookup(name: string): VarInfo | undefined;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ExtractedMessage } from '../types.js';
|
|
2
|
+
type StrictExtractedMessage = ExtractedMessage & {
|
|
3
|
+
references: NonNullable<ExtractedMessage['references']>;
|
|
4
|
+
};
|
|
5
|
+
export default class MessageExtractor {
|
|
6
|
+
private static readonly NAMESPACE_SEPARATOR;
|
|
7
|
+
private isDevelopment;
|
|
8
|
+
private projectRoot;
|
|
9
|
+
private compileCache;
|
|
10
|
+
constructor(opts: {
|
|
11
|
+
isDevelopment: boolean;
|
|
12
|
+
projectRoot: string;
|
|
13
|
+
});
|
|
14
|
+
processFileContent(absoluteFilePath: string, source: string): Promise<{
|
|
15
|
+
messages: Array<StrictExtractedMessage>;
|
|
16
|
+
source: string;
|
|
17
|
+
}>;
|
|
18
|
+
private processAST;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ExtractedMessage, Locale } from '../types.js';
|
|
2
|
+
export type FormatterContext = {
|
|
3
|
+
locale: Locale;
|
|
4
|
+
};
|
|
5
|
+
export default abstract class Formatter {
|
|
6
|
+
abstract readonly EXTENSION: `.${string}`;
|
|
7
|
+
abstract parse(content: string, context: FormatterContext): Array<ExtractedMessage>;
|
|
8
|
+
abstract serialize(messages: Array<ExtractedMessage>, context: FormatterContext): string;
|
|
9
|
+
abstract toJSONString(source: string, context: FormatterContext): string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ExtractedMessage } from '../types.js';
|
|
2
|
+
import Formatter from './Formatter.js';
|
|
3
|
+
export default class JSONFormatter extends Formatter {
|
|
4
|
+
static readonly NAMESPACE_SEPARATOR = ".";
|
|
5
|
+
readonly EXTENSION = ".json";
|
|
6
|
+
parse(source: string): Array<ExtractedMessage>;
|
|
7
|
+
serialize(messages: Array<ExtractedMessage>): string;
|
|
8
|
+
toJSONString(source: string): string;
|
|
9
|
+
private traverseMessages;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ExtractedMessage } from '../types.js';
|
|
2
|
+
import Formatter, { type FormatterContext } from './Formatter.js';
|
|
3
|
+
export default class POFormatter extends Formatter {
|
|
4
|
+
private static readonly DEFAULT_METADATA;
|
|
5
|
+
readonly EXTENSION = ".po";
|
|
6
|
+
private metadataByLocale;
|
|
7
|
+
parse(content: string, context: FormatterContext): Array<ExtractedMessage>;
|
|
8
|
+
serialize(messages: Array<ExtractedMessage>, context: FormatterContext): string;
|
|
9
|
+
toJSONString(source: string, context: FormatterContext): string;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as unstable_extractMessages } from './extractMessages.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type MessagesFormat = 'json' | 'po';
|
|
2
|
+
export type Locale = string;
|
|
3
|
+
export type ExtractedMessage = {
|
|
4
|
+
id: string;
|
|
5
|
+
message: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
references?: Array<{
|
|
8
|
+
path: string;
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
11
|
+
export type MessagesConfig = {
|
|
12
|
+
path: string;
|
|
13
|
+
format: MessagesFormat;
|
|
14
|
+
locales: 'infer' | Array<Locale>;
|
|
15
|
+
};
|
|
16
|
+
export type ExtractorConfig = {
|
|
17
|
+
srcPath: string | Array<string>;
|
|
18
|
+
sourceLocale: string;
|
|
19
|
+
messages: MessagesConfig;
|
|
20
|
+
};
|
|
21
|
+
export type CatalogLoaderConfig = {
|
|
22
|
+
messages: MessagesConfig;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setNestedProperty(obj: Record<string, any>, keyPath: string, value: any): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ExtractedMessage } from '../types.js';
|
|
2
|
+
type Catalog = {
|
|
3
|
+
meta?: Record<string, string>;
|
|
4
|
+
messages?: Array<ExtractedMessage>;
|
|
5
|
+
};
|
|
6
|
+
export default class POParser {
|
|
7
|
+
private static readonly KEYWORDS;
|
|
8
|
+
private static readonly COMMENTS;
|
|
9
|
+
private static readonly NAMESPACE_SEPARATOR;
|
|
10
|
+
private static readonly QUOTE;
|
|
11
|
+
private static readonly NEWLINE;
|
|
12
|
+
private static readonly FILE_COLUMN_SEPARATOR;
|
|
13
|
+
private static readonly META_SEPARATOR;
|
|
14
|
+
static parse(content: string): Catalog;
|
|
15
|
+
private static isMetaEntry;
|
|
16
|
+
static serialize(catalog: Catalog): string;
|
|
17
|
+
private static lineStartsWithPrefix;
|
|
18
|
+
private static throwWithLine;
|
|
19
|
+
private static splitLines;
|
|
20
|
+
private static ensureEntry;
|
|
21
|
+
private static finishEntry;
|
|
22
|
+
private static extractQuotedString;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './extractor/index.js';
|