Skip to content

Commit f3c4379

Browse files
docs: update readme (#11)
* feat: readme * feat(react): update the name of the locale cookie * feat: upd readme * chore: add license
1 parent 05f4ef0 commit f3c4379

File tree

5 files changed

+177
-19
lines changed

5 files changed

+177
-19
lines changed

.github/workflows/pr-check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ jobs:
4949
uses: dtinth/setup-github-actions-caching-for-turbo@v1
5050

5151
- name: Build
52-
run: pnpm turbo build
52+
run: pnpm turbo build --force
5353

5454
- name: Test
55-
run: pnpm turbo test
55+
run: pnpm turbo test --force
5656

5757
- name: Require changeset to be present in PR
5858
run: pnpm changeset status --since origin/main

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
run: pnpm turbo build --force
5454

5555
- name: Test
56-
run: pnpm turbo test
56+
run: pnpm turbo test --force
5757

5858
- name: Create Release Pull Request or Publish to npm
5959
id: changesets

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Supabase
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/react/src/next/loaders.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import { cookies } from 'next/headers';
44

55
export async function loadLocaleFromCookie() {
66
const cookieMgr = cookies();
7-
return cookieMgr.get('locale')?.value || 'en';
7+
return cookieMgr.get('REPLEXICA_LOCALE')?.value || 'en';
88
}

readme.md

Lines changed: 152 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,180 @@
55

66
# Replexica
77

8-
Replexica is an open-source i18n compiler plugin for React + an AI translation platform.
8+
Replexica is a free, open-source compiler plugin for React, paired with an AI translation platform. It's a toolset that enables React apps to speak many languages.
99

10-
Multi-language products get more users: 75% of the world doesn't speak English. But building such apps is a pain. *Extract* strings to JSON files, then *update* translations every time there is a change - it's a nightmare.
10+
![GitHub License](https://img.shields.io/github/license/replexica/replexica)
11+
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/replexica/replexica/release)
1112

12-
That's where Replexica comes in: it's a build system plugin, that translates React apps to multiple languages with AI, and doesn't require JSON files extraction / maintenance.
13+
Why does this matter? Because 75% of the world doesn't speak English. If the app is multilingual, it can serve many more users. But, let's be honest, making an app multilingual is a headache. You have to extract strings to JSON files and update translations every time something changes.
1314

14-
Replexica compiler is open-source, and the API is open so you can build your own translation engine. We're also building our own AI translation platform, to make it even easier to roll out your first multi-language app ;)
15+
That's where Replexica comes in: it's a build system plugin that translates React apps into multiple languages using AI. The best part? It doesn't require messing around with extracting or maintaining JSON files.
16+
17+
## The API
18+
19+
```js
20+
import compiler from '@replexica/compiler';
21+
22+
/** @type {import('next').NextConfig} */
23+
const nextConfig = {};
24+
25+
/** @type {import('@replexica/compiler').ReplexicaConfig} */
26+
const replexicaConfig = {
27+
locale: {
28+
source: 'en',
29+
targets: ['es'],
30+
},
31+
};
32+
33+
export default compiler.next(
34+
replexicaConfig,
35+
nextConfig,
36+
);
37+
38+
```
39+
40+
## The Roadmap
1541

1642
- [x] Replexica Compiler
17-
- [x] Next.js
43+
- [x] Next.js App Router
44+
- [ ] Next.js Pages Router
1845
- [ ] Remix
1946
- [ ] Create React App
2047
- [x] Replexica Framework
2148
- [x] JSX translation
2249
- [x] Custom context hints
23-
- [ ] Translation of string literals using a helper
50+
- [x] Skipper for non-translatable text
51+
- [x] Avoid fetching unused translations
52+
- [x] Translation of JSX attributes (title, alt, placeholder)
53+
- [ ] Translation of generic literals with helper functions
54+
- [ ] Translation of arbitrary attributes
2455
- [x] Replexica Platform
2556
- [x] AI Translation Engine
2657
- [x] Translation memory
2758
- [x] Context awareness aka **Brand voice**
28-
- [ ] i18n overrides
29-
- [ ] i18n quality checks
59+
- [ ] Supported locales (production-ready, state-of-the-art quality)
60+
- [x] English
61+
- [x] Spanish
62+
- [ ] French (April 2024)
63+
- [ ] German (April 2024)
64+
- [ ] (Create a GitHub issue )
65+
- [ ] Automated i18n quality checks (May 2024)
66+
- [ ] Documentation/examples on self-hosted translation engine
3067
- [x] Replexica CLI
3168
- [x] CLI for Replexica Platform
3269
- [x] Open-source API schema
3370
- [ ] GitHub Actions integration
3471

35-
## How it works
72+
The Replexica compiler is open-source, and the API is open, allowing you to build your own translation engine. We're also developing our own AI translation platform ([replexica.com](https://replexica.com)), to make it even easier to launch your first multi-language app!
73+
74+
## How it Works
3675

37-
Replexica is a compiler plugin. It hooks into your build system, and collects all the user-facing text in your app, getting it ready for translation with the Replexica platform. Here's how it works:
76+
Replexica is a compiler plugin that integrates with the build system, collecting all user-facing text in the app and preparing it for translation with the Replexica platform. Here's how it works:
3877

39-
1. **Infers** metadata from your app, like the text that needs to be translated and the context it's in. The metadata is then stored alongside your build artifacts.
40-
1. **Translates** the text using the CLI that connects to the Replexica platform. The platform uses AI to translate the text, and the more you use it, the better it gets. The API is open, so you can build your own translation engine if you want!
78+
1. **Infers** metadata from your app, such as the text that needs to be translated and its context. This metadata is then stored alongside the build artifacts.
79+
1. **Translates** the text using the CLI that connects to the Replexica platform. The platform uses AI to translate the text, and the more you use it, the better it gets. The API is open, so you can build your own translation engine if you wish!
4180
1. **Injects** the translations back into your app, so that the translated text is displayed to the user, based on their locale.
4281

43-
So, with Replexica, you can build multi-language apps without the hassle of JSON files, and with the power of AI translation.
82+
With Replexica, you can build multi-language apps without the hassle of managing JSON files, and with the power of AI translation.
83+
84+
## The Replexica Rule
85+
86+
At Replexica, we believe in the elegance of [Convention over configuration](https://en.wikipedia.org/wiki/Convention_over_configuration) principle.
87+
88+
Therefore, there's an important rule to remember when using Replexica:
89+
90+
> [!TIP]
91+
> Place translatable text inside `JSX`.
92+
93+
As long as you follow this rule, the Replexica Compiler can automatically infer the metadata from your app and prepare the text inside JSX for translation.
94+
95+
If you don't follow the rule and decide to store some of your translatable content in variables, that **can be translated too**, but you'll need to manually wrap that text in a helper function.
96+
97+
So, if you want a hassle-free i18n on autopilot, **follow The Replexica Rule** whenever possible.
98+
99+
## Getting Started
100+
101+
#### Step 1. Install Replexica
102+
103+
```bash
104+
pnpm add replexica @replexica/compiler @replexica/react
105+
```
106+
107+
#### Step 2. Configure NextJS
108+
109+
```js
110+
// next.config.mjs
111+
112+
import compiler from '@replexica/compiler';
113+
114+
/** @type {import('next').NextConfig} */
115+
const nextConfig = {};
116+
117+
/** @type {import('@replexica/compiler').ReplexicaConfig} */
118+
const replexicaConfig = {
119+
locale: {
120+
source: 'en', // Language the app's content is in
121+
targets: ['es'], // Target language(s)
122+
},
123+
};
124+
125+
export default compiler.next(
126+
replexicaConfig,
127+
nextConfig,
128+
);
129+
130+
```
131+
132+
#### Step 3. Configure React App
133+
134+
> [!NOTE]
135+
> This guide is for Next.js App Router apps only. Guides for other setups are coming soon (ETA April 2024).
136+
137+
If you plan on having `'use client'` components in your app (you probably do), you'll need to also wrap your entire component tree in `<ReplexicaProvider />`:
138+
139+
```jsx
140+
import { ReplexicaIntlProvider } from '@replexica/react/client';
141+
import { loadLocaleFromCookie } from '@replexica/react/next';
142+
143+
// ... rest of the code
144+
145+
export default async function RootLayout({
146+
children,
147+
}: Readonly<{
148+
children: React.ReactNode;
149+
}>) {
150+
const locale = await loadLocaleFromCookie();
151+
// Note the .client.json suffix of the i18n file below.
152+
// It means that only the values *actually used* get passed to the client, not the entire i18n dictionary.
153+
const localeData = await import(`@replexica/translations/${locale}.client.json`).then((m) => m.default);
154+
return (
155+
<ReplexicaIntlProvider data={localeData}>
156+
<html lang={locale}>
157+
<body className={inter.className}>{children}</body>
158+
</html>
159+
</ReplexicaIntlProvider>
160+
);
161+
}
162+
163+
```
164+
165+
## How to Switch Between Languages
166+
167+
Different apps use different strategies for switching between supported languages. Here are a few approaches we've seen:
168+
169+
- Cookie value (get/set cookie value)
170+
- Subdomain (`en.myapp.com` / `es.myapp.com`)
171+
- TLD domain (`myapp.com` / `myapp.es`)
172+
- Pathname segments (`myapp.com/en` / `myapp.com/es`)
173+
174+
... and so on.
175+
176+
To support every possible strategy, now and in the future, Replexica does the following:
177+
178+
*Replexica reads the value of the `REPLEXICA_LOCALE` cookie to determine the currently selected locale*
179+
180+
So, whatever approach you choose for switching between locales, just be sure to update the value of the `REPLEXICA_LOCALE` cookie, and Replexica will handle the rest.
44181

45-
## Getting started
182+
## Questions?
46183

47-
## License
184+
If you have any questions, feel free to create a GitHub issue!

0 commit comments

Comments
 (0)