Skip to content

Commit 60232b1

Browse files
committed
chore: rename translation provider to lingo provider
1 parent b256569 commit 60232b1

14 files changed

Lines changed: 119 additions & 133 deletions

File tree

cmp/compiler/src/plugin/transform/TRANSFORMATION_PIPELINE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ const t = useTranslation();
262262

263263
**How it works**:
264264

265-
1. Gets locale from `TranslationProvider` context
265+
1. Gets locale from `LingoProvider` context
266266
2. Loads translations from API endpoint or preloaded bundle
267267
3. Returns `t()` function that looks up translations by hash
268268
4. Falls back to source text if translation missing

cmp/compiler/src/react/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This folder contains React components and hooks for the Lingo.dev translation ru
44

55
## Components
66

7-
### `<TranslationProvider>`
7+
### `<LingoProvider>`
88

99
Context provider that manages translations and locale switching for your entire app.
1010

@@ -19,13 +19,13 @@ Context provider that manages translations and locale switching for your entire
1919

2020
```tsx
2121
// app/layout.tsx
22-
import { TranslationProvider } from "@lingo.dev/compiler-beta/react";
22+
import { LingoProvider } from "@lingo.dev/compiler-beta/react";
2323

2424
export default function RootLayout({ children }) {
2525
return (
2626
<html>
2727
<body>
28-
<TranslationProvider initialLocale="en">{children}</TranslationProvider>
28+
<LingoProvider initialLocale="en">{children}</LingoProvider>
2929
</body>
3030
</html>
3131
);
@@ -157,7 +157,7 @@ For Server Components, use the separate `getServerTranslations()` function (not
157157

158158
```
159159
┌─────────────────────────────────────┐
160-
TranslationProvider
160+
LingoProvider
161161
│ (Context + State Management) │
162162
└────────────┬────────────────────────┘
163163
@@ -180,7 +180,7 @@ For Server Components, use the separate `getServerTranslations()` function (not
180180

181181
## Best Practices
182182

183-
1. **Wrap your entire app** with `<TranslationProvider>` in the root layout
183+
1. **Wrap your entire app** with `<LingoProvider>` in the root layout
184184
2. **Pass the router** to `<LocaleSwitcher>` for seamless Server Component updates
185185
3. **Pre-load common translations** using `initialTranslations` prop
186186
4. **Use custom fetch function** if you have a custom translation API
@@ -191,7 +191,7 @@ All components and hooks are fully typed with TypeScript. Import types as needed
191191

192192
```tsx
193193
import type {
194-
TranslationProviderProps,
194+
LingoProviderProps,
195195
LocaleSwitcherProps,
196196
LocaleConfig,
197197
TranslationFunction,
@@ -204,16 +204,16 @@ import type {
204204
When testing components that use translations:
205205

206206
```tsx
207-
import { TranslationProvider } from "@lingo.dev/compiler-beta/react";
207+
import { LingoProvider } from "@lingo.dev/compiler-beta/react";
208208

209209
test("my component", () => {
210210
render(
211-
<TranslationProvider
211+
<LingoProvider
212212
initialLocale="en"
213213
fetchTranslations={async () => ({ hash_abc: "Hello" })}
214214
>
215215
<MyComponent />
216-
</TranslationProvider>,
216+
</LingoProvider>,
217217
);
218218
});
219219
```

cmp/compiler/src/react/client/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
* @module @lingo.dev/compiler/react (client)
88
*/
99
export {
10-
TranslationProvider,
11-
useTranslationContext,
12-
type TranslationContextType,
13-
type TranslationProviderProps,
14-
} from "../shared/TranslationContext";
10+
LingoProvider,
11+
type LingoProviderProps,
12+
} from "../shared/LingoProvider";
13+
14+
export { useLingoContext } from "../shared/LingoContext";
1515

1616
export { useTranslation } from "./useTranslation";
1717

cmp/compiler/src/react/client/useTranslation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"use client";
22

33
import { type ReactNode, useCallback, useEffect } from "react";
4-
import { useTranslationContext } from "../shared/TranslationContext";
54
import { logger } from "../../utils/logger";
65
import {
76
renderRichText,
87
type RichTextParams,
98
} from "../shared/render-rich-text";
109
import type { TranslationHook } from "../types";
10+
import { useLingoContext } from "../shared/LingoContext";
1111

1212
/**
1313
* useTranslation Hook
@@ -45,7 +45,7 @@ import type { TranslationHook } from "../types";
4545
*/
4646
export const useTranslation: TranslationHook = (hashes: string[]) => {
4747
const { translations, registerHashes, locale, sourceLocale } =
48-
useTranslationContext();
48+
useLingoContext();
4949

5050
useEffect(() => {
5151
logger.debug(`Registering ${hashes.length} hashes for component`);
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"use client";
22
import {
3-
TranslationProvider as BaseTranslationProvider,
4-
type TranslationProviderProps,
5-
} from "../shared/TranslationContext";
3+
LingoProvider as BaseLingoProvider,
4+
type LingoProviderProps,
5+
} from "../shared/LingoProvider";
66
import { useRouter } from "next/navigation";
77
import { logger } from "../../utils/logger";
88

9-
export type { TranslationProviderProps };
9+
export type { LingoProviderProps };
1010

1111
export const createNextCookieLocaleResolver = () => {
1212
return (locale: string) => {
@@ -15,7 +15,7 @@ export const createNextCookieLocaleResolver = () => {
1515
};
1616
};
1717

18-
export const TranslationProvider = (props: TranslationProviderProps) => {
18+
export const LingoProvider = (props: LingoProviderProps) => {
1919
// So far we are just injecting the router to reload server components when the locale changes.
20-
return <BaseTranslationProvider {...props} router={useRouter()} />;
20+
return <BaseLingoProvider {...props} router={useRouter()} />;
2121
};

cmp/compiler/src/react/next/server.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import {
2-
TranslationProvider as BaseTranslationProvider,
3-
type TranslationProviderProps,
2+
LingoProvider as BaseLingoProvider,
3+
type LingoProviderProps,
44
} from "./client";
55
import { getServerTranslations } from "../server-only";
66
import { logger } from "../../utils/logger";
77
import { createNextCookieLocaleResolver } from "./cookie-locale-resolver";
88

99
export { createNextCookieLocaleResolver };
1010

11-
export async function TranslationProvider({
11+
export async function LingoProvider({
1212
initialLocale,
1313
initialTranslations = {},
1414
...rest
15-
}: TranslationProviderProps) {
15+
}: LingoProviderProps) {
1616
const { locale, translations } = await getServerTranslations({
1717
locale: initialLocale,
1818
});
1919

2020
logger.debug(
21-
`Server. TranslationProvider. Initial locale: ${initialLocale}. Resolved locale: ${locale}. Translations: ${JSON.stringify(translations)}`,
21+
`Server. LingoProvider. Initial locale: ${initialLocale}. Resolved locale: ${locale}. Translations: ${JSON.stringify(translations)}`,
2222
);
2323

2424
return (
25-
<BaseTranslationProvider
25+
<BaseLingoProvider
2626
initialLocale={locale}
2727
initialTranslations={translations}
2828
{...rest}

cmp/compiler/src/react/server/ServerTranslationProvider.tsx renamed to cmp/compiler/src/react/server/ServerLingoProvider.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import {
2-
TranslationProvider as BaseTranslationProvider,
3-
type TranslationProviderProps,
4-
} from "../shared/TranslationContext";
2+
LingoProvider as BaseLingoProvider,
3+
type LingoProviderProps,
4+
} from "../shared/LingoProvider";
55
import { getServerTranslations } from "../server-only";
66
import { logger } from "../../utils/logger";
77

8-
export async function TranslationProvider({
8+
export async function LingoProvider({
99
initialLocale,
1010
initialTranslations = {},
1111
...rest
12-
}: TranslationProviderProps) {
12+
}: LingoProviderProps) {
1313
const { locale, translations } = await getServerTranslations({
1414
locale: initialLocale,
1515
});
1616

17-
logger.debug(`Server. TranslationProvider. Resolved locale: ${locale}`);
17+
logger.debug(`Server. LingoProvider. Resolved locale: ${locale}`);
1818

1919
return (
20-
<BaseTranslationProvider
20+
<BaseLingoProvider
2121
initialLocale={locale}
2222
initialTranslations={translations}
2323
{...rest}

cmp/compiler/src/react/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
*
1313
* @module @lingo.dev/compiler/react (server)
1414
*/
15-
export { TranslationProvider } from "./ServerTranslationProvider";
15+
export { LingoProvider } from "./ServerLingoProvider";
1616
export { LocaleSwitcher } from "../shared/LocaleSwitcher";
1717
export { useTranslation } from "./useTranslation";
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { createContext, useContext } from "react";
2+
3+
interface LingoContextType {
4+
/**
5+
* Current locale (e.g., 'en', 'de', 'fr')
6+
*/
7+
locale: string;
8+
9+
/**
10+
* Change the current locale and dynamically load translations
11+
*/
12+
setLocale: (locale: string) => Promise<void>;
13+
14+
/**
15+
* Translation dictionary: hash -> translated text
16+
*/
17+
translations: Record<string, string>;
18+
19+
/**
20+
* Register a hash as being used in a component
21+
* The provider will automatically request missing translations
22+
*/
23+
registerHashes: (hashes: string[]) => void;
24+
25+
/**
26+
* Whether translations are currently being loaded
27+
*/
28+
isLoading: boolean;
29+
30+
/**
31+
* Source locale (default language)
32+
*/
33+
sourceLocale: string;
34+
35+
/**
36+
* Development statistics (only in dev mode)
37+
*/
38+
_devStats?: {
39+
pendingCount: number;
40+
totalRegisteredCount: number;
41+
};
42+
}
43+
44+
export const LingoContext = createContext<LingoContextType | null>(null);
45+
46+
export function useLingoContext(): LingoContextType {
47+
const context = useContext(LingoContext);
48+
49+
if (!context) {
50+
// TODO (AleksandrSl 14/12/2025): Shouldn't throw in production
51+
throw new Error("useTranslationContext must be used within LingoProvider");
52+
}
53+
54+
return context;
55+
}

0 commit comments

Comments
 (0)