@korioinc/next-core 1.0.2 → 1.0.3

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.
@@ -0,0 +1,41 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,53 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ export { getFallbackLocalesFromConfig, getLocalesFromConfig, getLinguiConfig, initializeLinguiConfig, } from './lingui-config';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,2 @@
1
+ // Export all configuration related functions
2
+ export { getFallbackLocalesFromConfig, getLocalesFromConfig, getLinguiConfig, initializeLinguiConfig, } from './lingui-config';
@@ -0,0 +1,23 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,38 @@
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
+ }
@@ -0,0 +1,24 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,24 @@
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
+ }
@@ -0,0 +1,32 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,74 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@korioinc/next-core",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./ads": {
@@ -88,7 +88,6 @@
88
88
  "clsx": "^2.1.1",
89
89
  "cookies-next": "^6.1.0",
90
90
  "cosmiconfig": "^9.0.0",
91
- "jiti": "^1.21.7",
92
91
  "jose": "^6.1.0",
93
92
  "localforage": "^1.10.0",
94
93
  "negotiator": "^1.0.0",