Skip to content

Commit 6db156c

Browse files
committed
fix: normalize locale persistence config
1 parent 67a10cd commit 6db156c

File tree

6 files changed

+18
-47
lines changed

6 files changed

+18
-47
lines changed

cmp/compiler/src/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
export type {
2-
PartialLingoConfig,
3-
MetadataConfig,
4-
TranslationConfig,
5-
PathConfig,
6-
TranslationEntry,
7-
MetadataSchema,
8-
CookieConfig,
9-
} from "./types";
1+
export type { PartialLingoConfig } from "./types";

cmp/compiler/src/plugin/next.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type LingoNextPluginOptions = PartialLingoConfig;
1717

1818
type RuleKey = "compiler" | "devConfig" | "localeServer" | "localeClient";
1919

20-
export function loaders({
20+
function loaders({
2121
lingoConfig,
2222
metadataFilePath,
2323
translationServerUrl,
@@ -56,15 +56,15 @@ export function loaders({
5656
loader: "@lingo.dev/compiler/next-locale-server-loader",
5757
options: {
5858
...common,
59-
cookieConfig: lingoConfig.cookieConfig,
59+
localePersistence: lingoConfig.localePersistence,
6060
},
6161
};
6262

6363
const localeClientLoader = {
6464
loader: "@lingo.dev/compiler/next-locale-client-loader",
6565
options: {
6666
...common,
67-
cookieConfig: lingoConfig.cookieConfig,
67+
localePersistence: lingoConfig.localePersistence,
6868
},
6969
};
7070

@@ -345,6 +345,3 @@ export async function withLingo(
345345
webpack,
346346
};
347347
}
348-
349-
// Also export TypeScript types
350-
export type { NextConfig };

cmp/compiler/src/react/next/cookie-locale-resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { LocaleCode } from "lingo.dev/spec";
1313
/**
1414
* Configuration for Next.js locale resolver
1515
*/
16-
export interface NextLocaleResolverConfig {
16+
interface NextLocaleResolverConfig {
1717
/**
1818
* Cookie configuration (name and maxAge)
1919
* @default { name: 'locale', maxAge: 31536000 }

cmp/compiler/src/types.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface CookieConfig {
2626
* Locale persistence configuration
2727
* Currently only supports cookie-based persistence
2828
*/
29-
export type LocalePersistenceConfig = { type: "cookie"; cookieName?: string };
29+
export type LocalePersistenceConfig = { type: "cookie"; config: CookieConfig };
3030

3131
/**
3232
* Field that we require users to fill in the config. The rest could be taken from defaults.
@@ -163,17 +163,11 @@ export type LingoConfig = {
163163
translationServerUrl?: string;
164164
};
165165

166-
/**
167-
* Cookie configuration for locale persistence
168-
* Used by both client-side LocaleSwitcher and server-side locale resolver
169-
*/
170-
cookieConfig: CookieConfig;
171-
172166
/**
173167
* Locale persistence configuration
174168
* Defines how locale changes should be persisted
175169
*
176-
* @default { type: 'cookie', cookieName: 'locale' }
170+
* @default { type: 'cookie', config: { name: 'locale' } }
177171
*/
178172
localePersistence: LocalePersistenceConfig;
179173

@@ -189,21 +183,6 @@ export type LingoConfig = {
189183
buildMode: "translate" | "cache-only";
190184
};
191185

192-
/**
193-
* Minimal config needed for metadata operations
194-
* Used by metadata manager functions
195-
*/
196-
export type MetadataConfig = Pick<LingoConfig, "sourceRoot" | "lingoDir">;
197-
198-
/**
199-
* Config needed for translation operations
200-
* Includes translator configuration
201-
*/
202-
export type TranslationConfig = Pick<
203-
LingoConfig,
204-
"sourceRoot" | "lingoDir" | "sourceLocale" | "models" | "prompt"
205-
>;
206-
207186
/**
208187
* Config needed for translation middleware and server
209188
* Extends TranslationConfig with optional fields

cmp/compiler/src/utils/config-factory.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ export const DEFAULT_CONFIG = {
1818
dev: {
1919
translationServerStartPort: 60000,
2020
},
21-
cookieConfig: {
22-
name: "locale",
23-
maxAge: 31536000,
24-
},
2521
localePersistence: {
2622
type: "cookie" as const,
27-
cookieName: "locale",
23+
config: {
24+
name: "locale",
25+
maxAge: 31536000,
26+
},
2827
},
2928
models: "lingo.dev",
3029
pluralization: {
@@ -66,6 +65,10 @@ export function createLingoConfig(
6665
localePersistence: {
6766
...DEFAULT_CONFIG.localePersistence,
6867
...options.localePersistence,
68+
config: {
69+
...DEFAULT_CONFIG.localePersistence.config,
70+
...options.localePersistence?.config,
71+
},
6972
},
7073
};
7174
}

cmp/compiler/src/virtual/code-generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const sourceLocale = ${JSON.stringify(config.sourceLocale)};
3030
export function generateServerLocaleModule(config: LingoConfig): string {
3131
return `
3232
import { createNextCookieLocaleResolver } from '@lingo.dev/compiler/react/next';
33-
export const getServerLocale = createNextCookieLocaleResolver({ cookieConfig: ${JSON.stringify(config.cookieConfig)}, defaultLocale: ${JSON.stringify(config.sourceLocale)} });
33+
export const getServerLocale = createNextCookieLocaleResolver({ cookieConfig: ${JSON.stringify(config.localePersistence.config)}, defaultLocale: ${JSON.stringify(config.sourceLocale)} });
3434
`;
3535
}
3636

@@ -39,8 +39,8 @@ export const getServerLocale = createNextCookieLocaleResolver({ cookieConfig: ${
3939
* Exports getClientLocale() and persistLocale() functions
4040
*/
4141
export function generateClientLocaleModule(config: LingoConfig): string {
42-
const cookieName = config.cookieConfig.name;
43-
const maxAge = config.cookieConfig.maxAge;
42+
const cookieName = config.localePersistence.config.name;
43+
const maxAge = config.localePersistence.config.maxAge;
4444

4545
return `
4646
export function getClientLocale() {

0 commit comments

Comments
 (0)