Skip to content

Commit 629dcc6

Browse files
authored
Merge pull request #2 from lingodotdev/dev
chore: docs and demos cleanup
2 parents fa18a28 + 10a5583 commit 629dcc6

File tree

23 files changed

+345
-427
lines changed

23 files changed

+345
-427
lines changed

cmp/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ dist/
77
.turbo/
88
.next/
99
CLAUDE.md
10+
**/routeTree.gen.ts

cmp/README.md

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,103 @@
11
# Lingo.dev compiler
22

3-
### Development
3+
Lingo.dev compiler with automatic translation support for React applications.
4+
5+
This package provides plugins for multiple bundlers (Vite, Webpack) and Next.js that
6+
automatically transforms React components to inject translation calls.
7+
8+
## Features
9+
10+
- **Automatic JSX text transformation** - Automatically detects and transforms translatable text in JSX
11+
- **Opt-in or automatic** - Configure whether to require `'use i18n'` directive or transform all files
12+
- **Multi-bundler support** - Works with Vite, Webpack and Next.js (both Webpack and Turbopack builds)
13+
- **Translation server** - On-demand translation generation during development
14+
- **AI-powered translations** - Support for multiple LLM providers and Lingo.dev Engine
15+
16+
## Getting started
17+
18+
Install the package - `pnpm install @lingo.dev/compiler`
19+
20+
### Vite
21+
22+
- Configure the plugin in your vite config.
23+
24+
```ts
25+
import { defineConfig } from "vite";
26+
import { lingoCompilerPlugin } from "@lingo.dev/compiler/vite";
27+
28+
export default defineConfig({
29+
plugins: [
30+
lingoCompilerPlugin({
31+
sourceRoot: "src",
32+
sourceLocale: "en",
33+
targetLocales: ["es", "de", "fr"],
34+
models: "lingo.dev",
35+
dev: {
36+
usePseudotranslator: true,
37+
},
38+
}), // ...other plugins
39+
],
40+
});
41+
```
42+
43+
- Wrap your app with `LingoProvider`. It should be used as early as possible in your app.
44+
e.g. in vite example with tanstack-router `LingoProvider` should be above `RouterProvider`, otherwise code-splitting breaks contexts.
45+
```tsx
46+
// Imports and other tanstack router setup
47+
if (rootElement && !rootElement.innerHTML) {
48+
const root = ReactDOM.createRoot(rootElement);
49+
root.render(
50+
<StrictMode>
51+
<LingoProvider>
52+
<RouterProvider router={router} />
53+
</LingoProvider>
54+
</StrictMode>,
55+
);
56+
}
57+
```
58+
59+
See `demo/vite-react-spa` for the working example
60+
61+
### Next.js
62+
63+
- Use `withLingo` function to wrap your existing next config. You will have to make your config async.
64+
65+
```ts
66+
import type { NextConfig } from "next";
67+
import { withLingo } from "@lingo.dev/compiler/next";
68+
69+
const nextConfig: NextConfig = {};
70+
71+
export default async function (): Promise<NextConfig> {
72+
return await withLingo(nextConfig, {
73+
sourceRoot: "./app",
74+
sourceLocale: "en",
75+
targetLocales: ["es", "de", "ru"],
76+
models: "lingo.dev",
77+
dev: {
78+
usePseudotranslator: true,
79+
},
80+
buildMode: "cache-only",
81+
});
82+
}
83+
```
84+
85+
- Wrap your app with `LingoProvider`. It should be used as early as possible in your app, root `Layout` is a good place.
86+
```tsx
87+
export default function RootLayout({
88+
children,
89+
}: Readonly<{ children: React.ReactNode }>) {
90+
return (
91+
<LingoProvider>
92+
<html>
93+
<body className="antialiased">{children}</body>
94+
</html>
95+
</LingoProvider>
96+
);
97+
}
98+
```
99+
100+
## Development
4101

5102
`pnpm install` from project root
6103
`pnpm turbo dev --filter=@lingo.dev/compile` to compile and watch for compiler changes

cmp/compiler/README.md

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,6 @@
11
# @lingo.dev/compiler
22

3-
Official Lingo.dev compiler with automatic translation support for React applications.
4-
5-
This package provides plugins for multiple bundlers (Vite, Webpack, Rollup, esbuild) and a Next.js loader that
6-
automatically transforms React components to inject translation calls. It uses a hash-based metadata system to track
7-
translatable text across your application.
8-
9-
## Features
10-
11-
- **Automatic JSX text transformation** - Automatically detects and transforms translatable text in JSX
12-
- **Hash-based metadata** - Generates unique hashes for each translatable text based on content, component name, and
13-
file path
14-
- **Opt-in or automatic** - Configure whether to require `'use i18n'` directive or transform all files
15-
- **Multi-bundler support** - Works with Vite, Webpack, Rollup, esbuild, and Next.js
16-
- **Built on unplugin** - Unified plugin API across all bundlers
17-
- **Metadata tracking** - Maintains `.lingo/metadata.json` with all translatable content
18-
- **Translation server** - On-demand translation generation during development
19-
- **AI-powered translations** - Support for multiple LLM providers and Lingo.dev Engine
20-
21-
## Installation
22-
23-
```bash
24-
npm install @lingo.dev/compiler
25-
# or
26-
pnpm add @lingo.dev/compiler
27-
# or
28-
yarn add @lingo.dev/compiler
29-
```
3+
See the main [README](../README.md) for general information.
304

315
## Structure
326

cmp/compiler/src/translation-server/translation-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class TranslationServer {
179179
);
180180

181181
// Send initial connected event
182-
this.sendToClient(ws, createEvent("connected"));
182+
this.sendToClient(ws, createEvent("connected", { serverUrl: this.url! }));
183183

184184
ws.on("close", () => {
185185
this.wsClients.delete(ws);

cmp/compiler/src/translation-server/ws-events.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ interface BaseEvent {
1919
export interface ConnectedEvent extends BaseEvent {
2020
type: "connected";
2121
serverUrl: string;
22-
version: string;
2322
}
2423

2524
/**
@@ -144,7 +143,7 @@ type TranslationServerEventByType = {
144143
*/
145144
export function createEvent<T extends keyof TranslationServerEventByType>(
146145
type: T,
147-
event?: Omit<TranslationServerEventByType[T], "timestamp" | "type">,
146+
event: Omit<TranslationServerEventByType[T], "timestamp" | "type">,
148147
): TranslationServerEventByType[T] {
149148
return {
150149
...event,

cmp/demo/vite-react-spa/biome.json

Lines changed: 0 additions & 35 deletions
This file was deleted.

cmp/demo/vite-react-spa/package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
"scripts": {
66
"dev": "vite --port 3000",
77
"build": "vite build && tsc",
8-
"serve": "vite preview",
9-
"format": "biome format",
10-
"lint": "biome lint",
11-
"check": "biome check"
8+
"serve": "vite preview"
129
},
1310
"dependencies": {
1411
"@lingo.dev/compiler": "workspace:*",
@@ -23,7 +20,6 @@
2320
"tailwindcss": "^4.0.6"
2421
},
2522
"devDependencies": {
26-
"@biomejs/biome": "2.2.4",
2723
"@tanstack/devtools-vite": "^0.3.11",
2824
"@testing-library/dom": "^10.4.0",
2925
"@testing-library/react": "^16.2.0",

cmp/demo/vite-react-spa/public/translations/de.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
"version": 0.1,
33
"locale": "de",
44
"entries": {
5+
"8492c53cfbaf": "Über Lingo.dev",
6+
"8aa4fe3f0590": "Dies ist eine Demo-Anwendung, die den Lingo.dev-Compiler für automatische Übersetzungen in React-Anwendungen präsentiert.",
7+
"af76f667703b": "Hauptfunktionen",
8+
"999a96fc5866": "Automatische Extraktion übersetzbarer Texte aus JSX",
9+
"b285bf7876d3": "Build-Zeit-Transformation ohne Laufzeit-Overhead",
10+
"ab0450919701": "Unterstützung für mehrere Bundler (Vite, Webpack, Next.js)",
11+
"2d626508fb8f": "Hash-basiertes Übersetzungssystem für stabile Kennungen",
12+
"aca12d550fe2": "Unterstützung für Server- und Client-Komponenten",
13+
"44a3311c3a4a": "Wie es funktioniert",
14+
"0add30e37450": "Der Compiler analysiert Ihre React-Komponenten zur Build-Zeit und extrahiert automatisch alle übersetzbaren Strings. Anschließend generiert er Übersetzungen mit Ihrem konfigurierten Übersetzungsanbieter.",
15+
"07d84d34dd3a": "Fügen Sie einfach die Direktive \"use i18n\" am Anfang Ihrer Komponentendateien hinzu, und der Compiler erledigt den Rest!",
516
"daa4d8839395": "{counter} mal geklickt",
617
"52ed9ee761d8": "Hallo Welt",
718
"f11fc78c3ac0": "<b0>Gemischter</b0> Inhalt <i0>Fragment</i0>",

cmp/demo/vite-react-spa/public/translations/en.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
"version": 0.1,
33
"locale": "en",
44
"entries": {
5+
"8492c53cfbaf": "About Lingo.dev",
6+
"8aa4fe3f0590": "This is a demo application showcasing the Lingo.dev compiler for automatic translations in React applications.",
7+
"af76f667703b": "Key Features",
8+
"999a96fc5866": "Automatic extraction of translatable text from JSX",
9+
"b285bf7876d3": "Build-time transformation with zero runtime overhead",
10+
"ab0450919701": "Support for multiple bundlers (Vite, Webpack, Next.js)",
11+
"2d626508fb8f": "Hash-based translation system for stable identifiers",
12+
"aca12d550fe2": "Server and client component support",
13+
"44a3311c3a4a": "How It Works",
14+
"0add30e37450": "The compiler analyzes your React components at build time and automatically extracts all translatable strings. It then generates translations using your configured translation provider.",
15+
"07d84d34dd3a": "Simply add the \"use i18n\" directive at the top of your component files, and the compiler handles the rest!",
516
"daa4d8839395": "Clicked {counter} times",
617
"52ed9ee761d8": "Hello World",
718
"f11fc78c3ac0": "<b0>Mixed</b0> content <i0>fragment</i0>",

cmp/demo/vite-react-spa/public/translations/es.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
"version": 0.1,
33
"locale": "es",
44
"entries": {
5+
"8492c53cfbaf": "Acerca de Lingo.dev",
6+
"8aa4fe3f0590": "Esta es una aplicación de demostración que muestra el compilador Lingo.dev para traducciones automáticas en aplicaciones React.",
7+
"af76f667703b": "Características principales",
8+
"999a96fc5866": "Extracción automática de texto traducible desde JSX",
9+
"b285bf7876d3": "Transformación en tiempo de compilación sin sobrecarga en tiempo de ejecución",
10+
"ab0450919701": "Soporte para múltiples empaquetadores (Vite, Webpack, Next.js)",
11+
"2d626508fb8f": "Sistema de traducción basado en hash para identificadores estables",
12+
"aca12d550fe2": "Soporte para componentes de servidor y cliente",
13+
"44a3311c3a4a": "Cómo funciona",
14+
"0add30e37450": "El compilador analiza tus componentes de React en tiempo de compilación y extrae automáticamente todas las cadenas traducibles. Luego genera traducciones utilizando tu proveedor de traducción configurado.",
15+
"07d84d34dd3a": "¡Simplemente agrega la directiva \"use i18n\" en la parte superior de tus archivos de componentes, y el compilador se encarga del resto!",
516
"daa4d8839395": "Clicado {counter} veces",
617
"52ed9ee761d8": "Hola Mundo",
718
"f11fc78c3ac0": "Contenido <b0>mixto</b0> <i0>fragmento</i0>",

0 commit comments

Comments
 (0)