Skip to content

Commit 6e004b4

Browse files
cherkanovartclaude
andcommitted
feat(compiler): add useLocale hook and setLocale/getLocale functions
- Add useLocale() hook for reactive locale access in components - Add setLocale() function for changing locale from anywhere - Add getLocale() function for non-reactive locale access - Update README documentation with React Client API section Closes #1696 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 25b81bf commit 6e004b4

File tree

4 files changed

+16
-32
lines changed

4 files changed

+16
-32
lines changed

.changeset/locale-exports.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@lingo.dev/compiler": minor
3+
---
4+
5+
Add useLocale hook and setLocale/getLocale functions for easier locale management in React components.

packages/cli/src/cli/loaders/ensure-key-order.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ describe("ensure-key-order loader", () => {
9898
});
9999
});
100100

101-
it("should skip keys not in original input of source locale", async () => {
101+
it("should append new keys at the end", async () => {
102102
const originalInput = { a: 1, b: 2 };
103103
await loader.pull("en", originalInput);
104104
const data = { a: 11, b: 22, c: 33 };
105105
const result = await loader.push("en", data);
106-
expect(result).toEqual({ a: 11, b: 22 });
106+
expect(result).toEqual({ a: 11, b: 22, c: 33 });
107107
});
108108

109109
it("should skip keys not in the target locale data", async () => {

packages/cli/src/cli/loaders/ensure-key-order.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,9 @@ function reorderKeys(
4242
}
4343
}
4444

45+
for (const key of dataKeys) {
46+
orderedData[key] = data[key];
47+
}
48+
4549
return orderedData;
4650
}

packages/new-compiler/src/plugin/next.ts

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -135,33 +135,18 @@ function loaders({
135135
}
136136

137137
/**
138-
* Get Next.js major version
138+
* Check if Next.js supports stable turbopack config (Next.js 16+)
139139
*/
140-
function getNextMajorVersion(): number | null {
140+
function hasStableTurboConfig(): boolean {
141141
try {
142142
const nextPackage = require("next/package.json");
143-
return parseInt(nextPackage.version.split(".")[0], 10);
143+
const majorVersion = parseInt(nextPackage.version.split(".")[0], 10);
144+
return majorVersion >= 16;
144145
} catch {
145-
return null;
146+
return false;
146147
}
147148
}
148149

149-
/**
150-
* Check if Next.js supports stable turbopack config (Next.js 16+)
151-
*/
152-
function hasStableTurboConfig(): boolean {
153-
const majorVersion = getNextMajorVersion();
154-
return majorVersion !== null && majorVersion >= 16;
155-
}
156-
157-
/**
158-
* Check if Next.js version is supported (15+)
159-
*/
160-
function isNextVersionSupported(): boolean {
161-
const majorVersion = getNextMajorVersion();
162-
return majorVersion !== null && majorVersion >= 15;
163-
}
164-
165150
function getTurbopackConfig(userConfig: NextConfig): TurbopackOptions {
166151
return (
167152
(hasStableTurboConfig()
@@ -213,16 +198,6 @@ export async function withLingo(
213198
nextConfig: NextConfig = {},
214199
lingoOptions: LingoNextPluginOptions,
215200
): Promise<NextConfig> {
216-
// Check Next.js version compatibility
217-
if (!isNextVersionSupported()) {
218-
const majorVersion = getNextMajorVersion();
219-
logger.warn(
220-
`@lingo.dev/compiler requires Next.js 15 or later. ` +
221-
`Detected Next.js ${majorVersion ?? "unknown"}. ` +
222-
`Please upgrade Next.js to use the compiler.`,
223-
);
224-
}
225-
226201
const lingoConfig = createLingoConfig(lingoOptions);
227202
let metadataFilePath = getMetadataPath(lingoConfig);
228203
const isDev = lingoConfig.environment === "development";

0 commit comments

Comments
 (0)