@korioinc/next-core 1.0.5 → 1.0.8
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/i18n/lingui.setup.d.ts +2 -2
- package/dist/i18n/lingui.setup.d.ts.map +1 -1
- package/dist/i18n/lingui.setup.js +9 -9
- package/dist/i18n/types.d.ts +5 -0
- package/dist/i18n/types.d.ts.map +1 -0
- package/dist/i18n/types.js +1 -0
- package/dist/types/ambient.d.ts +4 -0
- package/package.json +14 -14
- package/dist/app-init.d.ts +0 -41
- package/dist/app-init.d.ts.map +0 -1
- package/dist/app-init.js +0 -53
- package/dist/config/index.d.ts +0 -2
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -2
- package/dist/config/lingui-config.d.ts +0 -23
- package/dist/config/lingui-config.d.ts.map +0 -1
- package/dist/config/lingui-config.js +0 -38
- package/dist/i18n/init.d.ts +0 -24
- package/dist/i18n/init.d.ts.map +0 -1
- package/dist/i18n/init.js +0 -24
- package/dist/i18n/lingui-server.d.ts +0 -32
- package/dist/i18n/lingui-server.d.ts.map +0 -1
- package/dist/i18n/lingui-server.js +0 -74
- package/dist/i18n/lingui.loader.d.ts +0 -37
- package/dist/i18n/lingui.loader.d.ts.map +0 -1
- package/dist/i18n/lingui.loader.js +0 -49
- package/dist/types/lingui-locales.d.ts +0 -4
|
@@ -5,11 +5,11 @@ type SupportedLocales = string;
|
|
|
5
5
|
type AllMessagesType = {
|
|
6
6
|
[key: string]: Messages;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
declare const allMessages: AllMessagesType;
|
|
9
|
+
export { allMessages };
|
|
9
10
|
type AllI18nInstances = {
|
|
10
11
|
[K in SupportedLocales]: I18n;
|
|
11
12
|
};
|
|
12
13
|
export declare const allI18nInstances: AllI18nInstances;
|
|
13
14
|
export declare const getI18nInstance: (locale: SupportedLocales) => I18n;
|
|
14
|
-
export {};
|
|
15
15
|
//# sourceMappingURL=lingui.setup.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lingui.setup.d.ts","sourceRoot":"","sources":["../../src/i18n/lingui.setup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAa,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"lingui.setup.d.ts","sourceRoot":"","sources":["../../src/i18n/lingui.setup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAa,MAAM,cAAc,CAAC;AAK/C,OAAO,aAAa,CAAC;AAIrB,KAAK,gBAAgB,GAAG,MAAM,CAAC;AAG/B,KAAK,eAAe,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAC;AAWnD,QAAA,MAAM,WAAW,EAAE,eAAgE,CAAC;AAEpF,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB,KAAK,gBAAgB,GAAG;KAAG,CAAC,IAAI,gBAAgB,GAAG,IAAI;CAAE,CAAC;AAE1D,eAAO,MAAM,gBAAgB,EAAE,gBAQL,CAAC;AAE3B,eAAO,MAAM,eAAe,GAAI,QAAQ,gBAAgB,KAAG,IAM1D,CAAC"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { setupI18n } from '@lingui/core';
|
|
2
2
|
import linguiConfig from 'lingui.config';
|
|
3
|
-
import
|
|
3
|
+
import * as appLoader from 'lingui.loader';
|
|
4
4
|
import 'server-only';
|
|
5
5
|
const { locales } = linguiConfig;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
// Load catalogs via app-provided loader
|
|
7
|
+
const loader = appLoader;
|
|
8
|
+
const entries = await Promise.all(locales.map(async (l) => {
|
|
9
|
+
const messages = await loader.load(l);
|
|
10
|
+
return [l, messages];
|
|
11
|
+
}));
|
|
12
|
+
const allMessages = Object.fromEntries(entries);
|
|
13
|
+
export { allMessages };
|
|
14
14
|
export const allI18nInstances = locales.reduce((acc, locale) => {
|
|
15
15
|
const messages = allMessages[locale] ?? {};
|
|
16
16
|
const i18n = setupI18n({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/i18n/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@korioinc/next-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./ads": {
|
|
@@ -62,27 +62,26 @@
|
|
|
62
62
|
"LICENSE"
|
|
63
63
|
],
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@headlessui/react": "^2.2.
|
|
66
|
-
"@lingui/conf": "
|
|
67
|
-
"@lingui/core": "
|
|
68
|
-
"@lingui/react": "
|
|
65
|
+
"@headlessui/react": "^2.2.8",
|
|
66
|
+
"@lingui/conf": "5.5.0",
|
|
67
|
+
"@lingui/core": "5.5.0",
|
|
68
|
+
"@lingui/react": "5.5.0",
|
|
69
69
|
"@tailwindcss/typography": "^0.5.16",
|
|
70
70
|
"@types/negotiator": "^0.6.4",
|
|
71
|
-
"@types/node": "^22.18.
|
|
71
|
+
"@types/node": "^22.18.3",
|
|
72
72
|
"@types/react": "^19.1.12",
|
|
73
73
|
"@types/react-dom": "^19.1.9",
|
|
74
74
|
"eslint": "^9.35.0",
|
|
75
75
|
"next-themes": "^0.4.6",
|
|
76
|
+
"react": "19.1.1",
|
|
77
|
+
"react-dom": "19.1.1",
|
|
76
78
|
"tailwindcss": "^4.1.13",
|
|
77
79
|
"tsc-alias": "^1.8.16",
|
|
78
80
|
"tw-animate-css": "^1.3.8",
|
|
79
81
|
"typescript": "^5.9.2",
|
|
80
|
-
"react": "^19.1.0",
|
|
81
|
-
"react-dom": "^19.1.0",
|
|
82
82
|
"@korioinc/next-configs": "1.0.0"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"schema-dts": "^1.1.5",
|
|
86
85
|
"@floating-ui/react": "^0.27.16",
|
|
87
86
|
"@formatjs/intl-localematcher": "^0.6.1",
|
|
88
87
|
"clsx": "^2.1.1",
|
|
@@ -92,9 +91,10 @@
|
|
|
92
91
|
"localforage": "^1.10.0",
|
|
93
92
|
"negotiator": "^1.0.0",
|
|
94
93
|
"pretendard": "^1.3.9",
|
|
94
|
+
"schema-dts": "^1.1.5",
|
|
95
95
|
"tailwind-merge": "^3.3.1",
|
|
96
|
-
"valtio": "^2.
|
|
97
|
-
"@korioinc/next-conf": "1.0.
|
|
96
|
+
"valtio": "^2.1.7",
|
|
97
|
+
"@korioinc/next-conf": "1.0.6"
|
|
98
98
|
},
|
|
99
99
|
"publishConfig": {
|
|
100
100
|
"access": "public",
|
|
@@ -107,14 +107,14 @@
|
|
|
107
107
|
},
|
|
108
108
|
"author": "Korio Inc.",
|
|
109
109
|
"peerDependencies": {
|
|
110
|
+
"@headlessui/react": ">=2.2.0",
|
|
110
111
|
"@lingui/core": ">=5.0.0",
|
|
111
112
|
"@lingui/react": ">=5.0.0",
|
|
112
|
-
"@headlessui/react": ">=2.2.0",
|
|
113
113
|
"next": ">=15",
|
|
114
114
|
"next-themes": ">=0.4.5",
|
|
115
|
-
"tailwindcss": ">=4.0.0",
|
|
116
115
|
"react": ">=19",
|
|
117
|
-
"react-dom": ">=19"
|
|
116
|
+
"react-dom": ">=19",
|
|
117
|
+
"tailwindcss": ">=4.0.0"
|
|
118
118
|
},
|
|
119
119
|
"scripts": {
|
|
120
120
|
"build": "tsc -p tsconfig.json && tsc-alias -p tsconfig.json && cp -r src/styles dist/ && cp -r src/types dist/",
|
package/dist/app-init.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* App initialization helper for Korio Next Core
|
|
3
|
-
* This file should be imported at the root of your Next.js application
|
|
4
|
-
*
|
|
5
|
-
* @example Create a file `app/init.ts`:
|
|
6
|
-
* ```typescript
|
|
7
|
-
* import linguiConfig from '../lingui.config';
|
|
8
|
-
* import { createAppInitializer } from '@korioinc/next-core/app-init';
|
|
9
|
-
*
|
|
10
|
-
* export const initializeApp = createAppInitializer({
|
|
11
|
-
* linguiConfig,
|
|
12
|
-
* loadCatalog: async (locale) => {
|
|
13
|
-
* const { messages } = await import(`../lang/${locale}.po`);
|
|
14
|
-
* return { messages };
|
|
15
|
-
* },
|
|
16
|
-
* });
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* Then in your root layout or _app.tsx:
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { initializeApp } from './init';
|
|
22
|
-
*
|
|
23
|
-
* // Call this before using any i18n features
|
|
24
|
-
* await initializeApp();
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
import type { LinguiConfig } from '@lingui/conf';
|
|
28
|
-
import { type LoadCatalogFunction } from './i18n/lingui-server';
|
|
29
|
-
export interface AppInitOptions {
|
|
30
|
-
linguiConfig: LinguiConfig;
|
|
31
|
-
loadCatalog: LoadCatalogFunction;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Create an app initializer function
|
|
35
|
-
*/
|
|
36
|
-
export declare function createAppInitializer(options: AppInitOptions): () => Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Direct initialization function
|
|
39
|
-
*/
|
|
40
|
-
export declare function initializeKorioApp(options: AppInitOptions): Promise<void>;
|
|
41
|
-
//# sourceMappingURL=app-init.d.ts.map
|
package/dist/app-init.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app-init.d.ts","sourceRoot":"","sources":["../src/app-init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGjD,OAAO,EAA0B,KAAK,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAExF,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,WAAW,EAAE,mBAAmB,CAAC;CAClC;AAID;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,cAAc,uBAU3D;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,cAAc,iBAQ/D"}
|
package/dist/app-init.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* App initialization helper for Korio Next Core
|
|
3
|
-
* This file should be imported at the root of your Next.js application
|
|
4
|
-
*
|
|
5
|
-
* @example Create a file `app/init.ts`:
|
|
6
|
-
* ```typescript
|
|
7
|
-
* import linguiConfig from '../lingui.config';
|
|
8
|
-
* import { createAppInitializer } from '@korioinc/next-core/app-init';
|
|
9
|
-
*
|
|
10
|
-
* export const initializeApp = createAppInitializer({
|
|
11
|
-
* linguiConfig,
|
|
12
|
-
* loadCatalog: async (locale) => {
|
|
13
|
-
* const { messages } = await import(`../lang/${locale}.po`);
|
|
14
|
-
* return { messages };
|
|
15
|
-
* },
|
|
16
|
-
* });
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* Then in your root layout or _app.tsx:
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { initializeApp } from './init';
|
|
22
|
-
*
|
|
23
|
-
* // Call this before using any i18n features
|
|
24
|
-
* await initializeApp();
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
import { initializeLinguiConfig } from './config/lingui-config';
|
|
28
|
-
import { initializeLinguiServer } from './i18n/lingui-server';
|
|
29
|
-
let initialized = false;
|
|
30
|
-
/**
|
|
31
|
-
* Create an app initializer function
|
|
32
|
-
*/
|
|
33
|
-
export function createAppInitializer(options) {
|
|
34
|
-
return async function initializeApp() {
|
|
35
|
-
if (initialized) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
initializeLinguiConfig(options.linguiConfig);
|
|
39
|
-
initializeLinguiServer(options.loadCatalog);
|
|
40
|
-
initialized = true;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Direct initialization function
|
|
45
|
-
*/
|
|
46
|
-
export async function initializeKorioApp(options) {
|
|
47
|
-
if (initialized) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
initializeLinguiConfig(options.linguiConfig);
|
|
51
|
-
initializeLinguiServer(options.loadCatalog);
|
|
52
|
-
initialized = true;
|
|
53
|
-
}
|
package/dist/config/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,4BAA4B,EAC5B,oBAAoB,EACpB,eAAe,EACf,sBAAsB,GACvB,MAAM,iBAAiB,CAAC"}
|
package/dist/config/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { LinguiConfig } from '@lingui/conf';
|
|
2
|
-
/**
|
|
3
|
-
* Initialize the lingui configuration with user's config
|
|
4
|
-
* This should be called once at the application startup
|
|
5
|
-
*/
|
|
6
|
-
export declare function initializeLinguiConfig(config: LinguiConfig): void;
|
|
7
|
-
/**
|
|
8
|
-
* Get the current lingui configuration
|
|
9
|
-
* Returns user's config if initialized, otherwise returns default config
|
|
10
|
-
*/
|
|
11
|
-
export declare function getLinguiConfig(): LinguiConfig;
|
|
12
|
-
/**
|
|
13
|
-
* Get the locales from the configuration
|
|
14
|
-
*/
|
|
15
|
-
export declare function getLocalesFromConfig(): string[];
|
|
16
|
-
/**
|
|
17
|
-
* Get the fallback locales from the configuration
|
|
18
|
-
*/
|
|
19
|
-
export declare function getFallbackLocalesFromConfig(): false | {
|
|
20
|
-
[locale: string]: string | string[];
|
|
21
|
-
default?: string;
|
|
22
|
-
} | undefined;
|
|
23
|
-
//# sourceMappingURL=lingui-config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lingui-config.d.ts","sourceRoot":"","sources":["../../src/config/lingui-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAcjD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,QAE1D;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAE9C;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAG/C;AAED;;GAEG;AACH,wBAAgB,4BAA4B;;;cAG3C"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// Default configuration
|
|
2
|
-
const defaultLinguiConfig = {
|
|
3
|
-
locales: ['en', 'ko'],
|
|
4
|
-
sourceLocale: 'en',
|
|
5
|
-
fallbackLocales: {
|
|
6
|
-
default: 'en',
|
|
7
|
-
},
|
|
8
|
-
};
|
|
9
|
-
// This will be set by the initialization function
|
|
10
|
-
let userLinguiConfig = null;
|
|
11
|
-
/**
|
|
12
|
-
* Initialize the lingui configuration with user's config
|
|
13
|
-
* This should be called once at the application startup
|
|
14
|
-
*/
|
|
15
|
-
export function initializeLinguiConfig(config) {
|
|
16
|
-
userLinguiConfig = config;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Get the current lingui configuration
|
|
20
|
-
* Returns user's config if initialized, otherwise returns default config
|
|
21
|
-
*/
|
|
22
|
-
export function getLinguiConfig() {
|
|
23
|
-
return userLinguiConfig || defaultLinguiConfig;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Get the locales from the configuration
|
|
27
|
-
*/
|
|
28
|
-
export function getLocalesFromConfig() {
|
|
29
|
-
const config = getLinguiConfig();
|
|
30
|
-
return config.locales || ['en'];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Get the fallback locales from the configuration
|
|
34
|
-
*/
|
|
35
|
-
export function getFallbackLocalesFromConfig() {
|
|
36
|
-
const config = getLinguiConfig();
|
|
37
|
-
return config.fallbackLocales;
|
|
38
|
-
}
|
package/dist/i18n/init.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { LinguiConfig } from '@lingui/conf';
|
|
2
|
-
import { type LoadCatalogFunction } from './lingui-server';
|
|
3
|
-
/**
|
|
4
|
-
* Initialize the Korio Next Core i18n system
|
|
5
|
-
* This should be called once at application startup
|
|
6
|
-
*
|
|
7
|
-
* @param config - Your Lingui configuration
|
|
8
|
-
* @param loadCatalog - Function to load message catalogs
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import linguiConfig from './lingui.config';
|
|
13
|
-
* import { initializeI18n } from '@korioinc/next-core/i18n/init';
|
|
14
|
-
*
|
|
15
|
-
* initializeI18n(linguiConfig, async (locale) => {
|
|
16
|
-
* const { messages } = await import(`./lang/${locale}.po`);
|
|
17
|
-
* return { messages };
|
|
18
|
-
* });
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export declare function initializeI18n(config: LinguiConfig, loadCatalog: LoadCatalogFunction): void;
|
|
22
|
-
export type { LoadCatalogFunction } from './lingui-server';
|
|
23
|
-
export type { LinguiConfig } from '@lingui/conf';
|
|
24
|
-
//# sourceMappingURL=init.d.ts.map
|
package/dist/i18n/init.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/i18n/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAIjD,OAAO,EAA0B,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEnF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,mBAAmB,QAGpF;AAGD,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/i18n/init.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { initializeLinguiConfig } from '../config/lingui-config';
|
|
2
|
-
import { initializeLinguiServer } from './lingui-server';
|
|
3
|
-
/**
|
|
4
|
-
* Initialize the Korio Next Core i18n system
|
|
5
|
-
* This should be called once at application startup
|
|
6
|
-
*
|
|
7
|
-
* @param config - Your Lingui configuration
|
|
8
|
-
* @param loadCatalog - Function to load message catalogs
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import linguiConfig from './lingui.config';
|
|
13
|
-
* import { initializeI18n } from '@korioinc/next-core/i18n/init';
|
|
14
|
-
*
|
|
15
|
-
* initializeI18n(linguiConfig, async (locale) => {
|
|
16
|
-
* const { messages } = await import(`./lang/${locale}.po`);
|
|
17
|
-
* return { messages };
|
|
18
|
-
* });
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export function initializeI18n(config, loadCatalog) {
|
|
22
|
-
initializeLinguiConfig(config);
|
|
23
|
-
initializeLinguiServer(loadCatalog);
|
|
24
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { Messages } from '@lingui/core';
|
|
2
|
-
import { I18n } from '@lingui/core';
|
|
3
|
-
import 'server-only';
|
|
4
|
-
/**
|
|
5
|
-
* Load message catalog for a specific locale
|
|
6
|
-
* This function should be implemented by the consumer application
|
|
7
|
-
*/
|
|
8
|
-
export type LoadCatalogFunction = (locale: string) => Promise<{
|
|
9
|
-
messages: Messages;
|
|
10
|
-
}>;
|
|
11
|
-
/**
|
|
12
|
-
* Initialize the lingui server with a catalog loader function
|
|
13
|
-
* This should be called once at application startup
|
|
14
|
-
*/
|
|
15
|
-
export declare function initializeLinguiServer(loadCatalog: LoadCatalogFunction): void;
|
|
16
|
-
/**
|
|
17
|
-
* Get all message catalogs
|
|
18
|
-
*/
|
|
19
|
-
export declare function getAllMessages(): Promise<{
|
|
20
|
-
[key: string]: Messages;
|
|
21
|
-
}>;
|
|
22
|
-
/**
|
|
23
|
-
* Get all i18n instances
|
|
24
|
-
*/
|
|
25
|
-
export declare function getAllI18nInstances(): Promise<{
|
|
26
|
-
[key: string]: I18n;
|
|
27
|
-
}>;
|
|
28
|
-
/**
|
|
29
|
-
* Get i18n instance for a specific locale
|
|
30
|
-
*/
|
|
31
|
-
export declare function getI18nInstance(locale: string): Promise<I18n>;
|
|
32
|
-
//# sourceMappingURL=lingui-server.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lingui-server.d.ts","sourceRoot":"","sources":["../../src/i18n/lingui-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAa,MAAM,cAAc,CAAC;AAI/C,OAAO,aAAa,CAAC;AAMrB;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC;AAItF;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,mBAAmB,QAKtE;AAED;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAC,CAyB3E;AAED;;GAEG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAmB5E;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAWnE"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { setupI18n } from '@lingui/core';
|
|
2
|
-
import { getLocalesFromConfig } from '../config/lingui-config';
|
|
3
|
-
import 'server-only';
|
|
4
|
-
// Cache for loaded catalogs and i18n instances
|
|
5
|
-
let catalogsCache = null;
|
|
6
|
-
let i18nInstancesCache = null;
|
|
7
|
-
let loadCatalogFunction = null;
|
|
8
|
-
/**
|
|
9
|
-
* Initialize the lingui server with a catalog loader function
|
|
10
|
-
* This should be called once at application startup
|
|
11
|
-
*/
|
|
12
|
-
export function initializeLinguiServer(loadCatalog) {
|
|
13
|
-
loadCatalogFunction = loadCatalog;
|
|
14
|
-
// Reset caches when re-initializing
|
|
15
|
-
catalogsCache = null;
|
|
16
|
-
i18nInstancesCache = null;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Get all message catalogs
|
|
20
|
-
*/
|
|
21
|
-
export async function getAllMessages() {
|
|
22
|
-
if (catalogsCache) {
|
|
23
|
-
return catalogsCache;
|
|
24
|
-
}
|
|
25
|
-
if (!loadCatalogFunction) {
|
|
26
|
-
console.warn('Lingui server not initialized. Using empty catalogs.');
|
|
27
|
-
return {};
|
|
28
|
-
}
|
|
29
|
-
const locales = getLocalesFromConfig();
|
|
30
|
-
const catalogs = await Promise.all(locales.map(async (locale) => {
|
|
31
|
-
try {
|
|
32
|
-
const { messages } = await loadCatalogFunction(locale);
|
|
33
|
-
return { [locale]: messages };
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
console.warn(`Failed to load catalog for locale "${locale}":`, error);
|
|
37
|
-
return { [locale]: {} };
|
|
38
|
-
}
|
|
39
|
-
}));
|
|
40
|
-
catalogsCache = catalogs.reduce((acc, catalog) => ({ ...acc, ...catalog }), {});
|
|
41
|
-
return catalogsCache;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Get all i18n instances
|
|
45
|
-
*/
|
|
46
|
-
export async function getAllI18nInstances() {
|
|
47
|
-
if (i18nInstancesCache) {
|
|
48
|
-
return i18nInstancesCache;
|
|
49
|
-
}
|
|
50
|
-
const allMessages = await getAllMessages();
|
|
51
|
-
const locales = getLocalesFromConfig();
|
|
52
|
-
i18nInstancesCache = locales.reduce((acc, locale) => {
|
|
53
|
-
const messages = allMessages[locale] ?? {};
|
|
54
|
-
const i18n = setupI18n({
|
|
55
|
-
locale,
|
|
56
|
-
messages: { [locale]: messages },
|
|
57
|
-
});
|
|
58
|
-
return { ...acc, [locale]: i18n };
|
|
59
|
-
}, {});
|
|
60
|
-
return i18nInstancesCache;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Get i18n instance for a specific locale
|
|
64
|
-
*/
|
|
65
|
-
export async function getI18nInstance(locale) {
|
|
66
|
-
const instances = await getAllI18nInstances();
|
|
67
|
-
if (!instances[locale]) {
|
|
68
|
-
console.warn(`No i18n instance found for locale "${locale}"`);
|
|
69
|
-
// Fallback to 'en' or first available locale
|
|
70
|
-
const fallbackLocale = instances['en'] ? 'en' : Object.keys(instances)[0];
|
|
71
|
-
return instances[fallbackLocale];
|
|
72
|
-
}
|
|
73
|
-
return instances[locale];
|
|
74
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { Messages } from '@lingui/core';
|
|
2
|
-
/**
|
|
3
|
-
* Load lingui catalogs and initialize the i18n setup
|
|
4
|
-
* This function should be called by the app at startup
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* // In your app's initialization (e.g., next.config.ts or app layout)
|
|
9
|
-
* import { loadLinguiCatalogs } from '@korioinc/next-core/i18n/lingui.loader';
|
|
10
|
-
*
|
|
11
|
-
* // Load all catalogs
|
|
12
|
-
* await loadLinguiCatalogs(async (locale) => {
|
|
13
|
-
* const { messages } = await import(`./lang/${locale}.po`);
|
|
14
|
-
* return messages;
|
|
15
|
-
* }, ['en', 'ko', 'pseudo']);
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare function loadLinguiCatalogs(loader: (locale: string) => Promise<Messages>, locales: string[]): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* Alternative: Load catalogs with a static import map
|
|
21
|
-
* This is useful when you know all locales at build time
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* import enMessages from './lang/en.po';
|
|
26
|
-
* import koMessages from './lang/ko.po';
|
|
27
|
-
*
|
|
28
|
-
* loadLinguiCatalogsStatic({
|
|
29
|
-
* en: enMessages.messages,
|
|
30
|
-
* ko: koMessages.messages,
|
|
31
|
-
* });
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export declare function loadLinguiCatalogsStatic(messages: {
|
|
35
|
-
[locale: string]: Messages;
|
|
36
|
-
}): void;
|
|
37
|
-
//# sourceMappingURL=lingui.loader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lingui.loader.d.ts","sourceRoot":"","sources":["../../src/i18n/lingui.loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,EAC7C,OAAO,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,IAAI,CAAC,CAcf;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE;IAAE,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,GAAG,IAAI,CAEvF"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { setAllMessages } from './lingui.setup';
|
|
2
|
-
/**
|
|
3
|
-
* Load lingui catalogs and initialize the i18n setup
|
|
4
|
-
* This function should be called by the app at startup
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* // In your app's initialization (e.g., next.config.ts or app layout)
|
|
9
|
-
* import { loadLinguiCatalogs } from '@korioinc/next-core/i18n/lingui.loader';
|
|
10
|
-
*
|
|
11
|
-
* // Load all catalogs
|
|
12
|
-
* await loadLinguiCatalogs(async (locale) => {
|
|
13
|
-
* const { messages } = await import(`./lang/${locale}.po`);
|
|
14
|
-
* return messages;
|
|
15
|
-
* }, ['en', 'ko', 'pseudo']);
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export async function loadLinguiCatalogs(loader, locales) {
|
|
19
|
-
const allMessages = {};
|
|
20
|
-
for (const locale of locales) {
|
|
21
|
-
try {
|
|
22
|
-
const messages = await loader(locale);
|
|
23
|
-
allMessages[locale] = messages;
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
console.error(`Failed to load messages for locale "${locale}":`, error);
|
|
27
|
-
// Continue loading other locales
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
setAllMessages(allMessages);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Alternative: Load catalogs with a static import map
|
|
34
|
-
* This is useful when you know all locales at build time
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* import enMessages from './lang/en.po';
|
|
39
|
-
* import koMessages from './lang/ko.po';
|
|
40
|
-
*
|
|
41
|
-
* loadLinguiCatalogsStatic({
|
|
42
|
-
* en: enMessages.messages,
|
|
43
|
-
* ko: koMessages.messages,
|
|
44
|
-
* });
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export function loadLinguiCatalogsStatic(messages) {
|
|
48
|
-
setAllMessages(messages);
|
|
49
|
-
}
|