@inlang/paraglide-js 1.3.5 → 1.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -70
- package/dist/cli/commands/{init.d.ts → init/command.d.ts} +10 -6
- package/dist/cli/commands/init/defaults.d.ts +14 -0
- package/dist/cli/commands/init/utils.d.ts +8 -0
- package/dist/index.js +1091 -171
- package/package.json +6 -6
- /package/dist/cli/commands/{compile.d.ts → compile/command.d.ts} +0 -0
- /package/dist/cli/commands/{compile.test.d.ts → compile/command.test.d.ts} +0 -0
- /package/dist/cli/commands/{init.test.d.ts → init/command.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,33 +1,44 @@
|
|
|
1
|
-
[<img src="https://cdn.
|
|
1
|
+
[<img src="https://cdn.jsdelivr.net/gh/opral/monorepo@latest/inlang/source-code/paraglide/paraglide-js/assets/header.png" alt="Dead Simple i18n. Typesafe, Small Footprint, Treeshsakeable Messages, IDE Integration, Framework Agnostic" width="10000000px" />](https://www.youtube.com/watch?v=-YES3CCAG90)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# Why Paraglide?
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<doc-features>
|
|
6
|
+
<doc-feature title="Tiny Runtime" image="https://cdn.jsdelivr.net/gh/opral/monorepo@latest/inlang/source-code/paraglide/paraglide-js/assets/bundlesize-feature.png"></doc-feature>
|
|
7
|
+
<doc-feature title="Fully Typesafe" image="https://cdn.jsdelivr.net/gh/opral/monorepo@latest/inlang/source-code/paraglide/paraglide-js/assets/typesafety-feature.png"></doc-feature>
|
|
8
|
+
<doc-feature title="Only Ship Used Messages" image="https://cdn.jsdelivr.net/gh/opral/monorepo@latest/inlang/source-code/paraglide/paraglide-js/assets/unused-translations.png"></doc-feature>
|
|
9
|
+
<doc-feature title="Sherlock VsCode Extension" image="https://cdn.jsdelivr.net/gh/opral/monorepo@latest/inlang/source-code/paraglide/paraglide-js/assets/sherlock-preview.png"></doc-feature>
|
|
10
|
+
</doc-features>
|
|
6
11
|
|
|
7
|
-
```bash
|
|
8
|
-
npx @inlang/paraglide-js@latest init
|
|
9
|
-
```
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
With Paraglide's Treeshsakeable messages, each page only loads the messages it actually uses. Incremental loading like this would usually take forever to get right, with Paraglide you get it for free.
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
<doc-feature title="Only used translations are shipped" image="https://cdn.jsdelivr.net/gh/opral/monorepo@latest/inlang/source-code/paraglide/paraglide-js/assets/unused-translations.png"></doc-feature>
|
|
15
|
-
<doc-feature title="Tiny Bundle-Size" image="https://cdn.jsdelivr.net/gh/opral/monorepo@latest/inlang/source-code/paraglide/paraglide-js/assets/reduced-payload.png"></doc-feature>
|
|
16
|
-
<doc-feature title="Typesafe" image="https://cdn.jsdelivr.net/gh/opral/monorepo@latest/inlang/source-code/paraglide/paraglide-js/assets/typesafe.png"></doc-feature>
|
|
17
|
-
</doc-features>
|
|
15
|
+
# Use it with your Favorite Framework
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
Paraglide is framework agnostic, but it's even better if you pair it with a framework specific library. If you are using one of these frameworks you will want to follow the framework specific documentation instead. If you aren't, that's fine too! You can read on.
|
|
20
18
|
|
|
21
|
-
<doc-
|
|
22
|
-
|
|
19
|
+
<doc-links>
|
|
20
|
+
<doc-link title="Adapter for NextJS" icon="tabler:brand-nextjs" href="/m/osslbuzt/paraglide-next-i18n" description="Go to Library"></doc-link>
|
|
21
|
+
<doc-link title="Adapter for SvelteKit" icon="simple-icons:svelte" href="/m/dxnzrydw/paraglide-sveltekit-i18n" description="Go to Library"></doc-link>
|
|
22
|
+
<doc-link title="Adapter for Astro" icon="devicon-plain:astro" href="/m/iljlwzfs/paraglide-astro-i18n" description="Go to Library"></doc-link>
|
|
23
|
+
<doc-link title="Adapter for SolidJS" icon="tabler:brand-solidjs" href="/m/n860p17j/paraglide-solidstart-i18n" description="Go to Library"></doc-link>
|
|
24
|
+
<doc-link title="Adapter for Remix" icon="simple-icons:remix" href="/m/fnhuwzrx/paraglide-remix-i18n" description="Go to Library"></doc-link>
|
|
25
|
+
<doc-link title="Or write your own" icon="ph:sparkle-fill" href="#writing-an-adapter" description="Learn How"></doc-link>
|
|
26
|
+
</doc-links>
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
# People Love It
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
Here are a few comments we've received recently.
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
<doc-comments>
|
|
33
|
+
<doc-comment text="Just tried Paraglide JS from @inlangHQ. This is how i18n should be done! Totally new level of DX for both implementation and managing translations! Superb support for SvelteKit as well ⭐" author="Patrik Engborg" icon="mdi:twitter" data-source="https://twitter.com/patrikengborg/status/1747260930873053674"></doc-comment>
|
|
34
|
+
<doc-comment text="I was messing with various i18n frameworks and tools in combination with Astro, and i must say that Paraglide was the smoothest experience. I have migrated my website from i18next and it was a breeze. SSG and SSR worked out of the box (which was the first one for me), and overall DX is great. Thanks for your work!" author="Dalibor Hon" icon="mdi:discord" data-source="https://discord.com/channels/897438559458430986/1096039983116202034/1220796380772307004"></doc-comment>
|
|
35
|
+
<doc-comment text="The lib is great guys!" author="ktarmyshov" icon="mdi:github"></doc-comment>
|
|
36
|
+
<doc-comment text="Thank you for that huge work you have done and still doing!" author="ZerdoX-x" icon="mdi:github"></doc-comment>
|
|
37
|
+
</doc-comments>
|
|
38
|
+
|
|
39
|
+
# Getting started
|
|
29
40
|
|
|
30
|
-
|
|
41
|
+
To use Paraglide stanadlone without a framework, run the following command:
|
|
31
42
|
|
|
32
43
|
```bash
|
|
33
44
|
npx @inlang/paraglide-js@latest init
|
|
@@ -35,41 +46,36 @@ npx @inlang/paraglide-js@latest init
|
|
|
35
46
|
|
|
36
47
|
This will:
|
|
37
48
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
### 2. Set up an adapter (optional)
|
|
43
|
-
|
|
44
|
-
Adapters are framework-integrations for Paraglide. If you are using a framework, using an adapter is recommended , but not required.
|
|
45
|
-
|
|
46
|
-
<doc-links>
|
|
47
|
-
<doc-link title="Adapter for NextJS" icon="tabler:brand-nextjs" href="/m/osslbuzt/library-inlang-paraglideJsAdapterNextJs" description="Go to Library"></doc-link>
|
|
48
|
-
<doc-link title="Adapter for SvelteKit" icon="simple-icons:svelte" href="/m/dxnzrydw/library-inlang-paraglideJsAdapterSvelteKit" description="Go to Library"></doc-link>
|
|
49
|
-
<doc-link title="Adapter for Astro" icon="devicon-plain:astro" href="/m/iljlwzfs/library-inlang-paraglideJsAdapterAstro" description="Go to Library"></doc-link>
|
|
50
|
-
<doc-link title="Adapter for SolidJS" icon="tabler:brand-solidjs" href="/m/n860p17j/library-inlang-paraglideJsAdapterSolidStart" description="Go to Library"></doc-link>
|
|
51
|
-
</doc-links>
|
|
52
|
-
|
|
53
|
-
#### Alternatively, [you can write your own adapter](#writing-an-adapter)
|
|
54
|
-
|
|
55
|
-
# Usage
|
|
49
|
+
- Install necessary dependencies
|
|
50
|
+
- Generate a `messages/` folder where your translation files live
|
|
51
|
+
- Add the Paraglide compiler to your `build` script
|
|
52
|
+
- Create necessary configuration files
|
|
56
53
|
|
|
57
|
-
Running
|
|
54
|
+
Running the paraglide compiler will generate a `src/paraglide` folder. This folder contains all the code that you need to use paraglide-js.
|
|
58
55
|
|
|
59
|
-
## Adding Messages
|
|
56
|
+
## Adding and Editing Messages
|
|
60
57
|
|
|
61
|
-
|
|
58
|
+
Messages are stored in `messages/{lang}.json`. To add a message simply add a key-value pair. You can add parameters with curly braces.
|
|
62
59
|
|
|
63
|
-
```
|
|
60
|
+
```diff
|
|
61
|
+
// messages/en.json
|
|
64
62
|
{
|
|
65
|
-
"
|
|
66
|
-
|
|
63
|
+
"$schema": "https://inlang.com/schema/inlang-message-format",
|
|
64
|
+
+ "greeting": "Hello {name}!"
|
|
67
65
|
}
|
|
68
66
|
```
|
|
69
67
|
|
|
70
|
-
|
|
68
|
+
Make sure to re-run the paraglide compiler after editing your messages.
|
|
71
69
|
|
|
72
|
-
|
|
70
|
+
```
|
|
71
|
+
npx @inlang/paraglide-js compile --project ./project.inlang
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
If you are using Vite, you can instead use the [paraglide vite-plugin](https://github.com/opral/monorepo/tree/main/inlang/source-code/paraglide/paraglide-js-adapter-vite) to do this automatically.
|
|
75
|
+
|
|
76
|
+
## Using Messages in Code
|
|
77
|
+
|
|
78
|
+
After running the compiler, you can import messages with `import * as m from "./paraglide/messages"`.
|
|
73
79
|
|
|
74
80
|
```js
|
|
75
81
|
import * as m from "./paraglide/messages.js"
|
|
@@ -79,7 +85,7 @@ m.hello() // Hello world!
|
|
|
79
85
|
m.loginHeader({ name: "Samuel" }) // Hello Samuel, please login to continue.
|
|
80
86
|
```
|
|
81
87
|
|
|
82
|
-
|
|
88
|
+
To choose between messages at runtime create a map of messages and index into it.
|
|
83
89
|
|
|
84
90
|
```ts
|
|
85
91
|
import * as m from "./paraglide/messages.js"
|
|
@@ -94,15 +100,14 @@ const season = {
|
|
|
94
100
|
const msg = season["spring"]() // Hello spring!
|
|
95
101
|
```
|
|
96
102
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
[Sherlock](https://inlang.com/m/r7kp499g/app-inlang-ideExtension) integrates with paraglide to give you the optimal dev-experience.
|
|
103
|
+
## Configuration
|
|
100
104
|
|
|
101
|
-
|
|
105
|
+
You can configure the languages you intend to support
|
|
102
106
|
|
|
103
|
-
|
|
107
|
+
### Languages
|
|
104
108
|
|
|
105
109
|
You can declare which languages you support in `./project.inlang/settings.json`.
|
|
110
|
+
|
|
106
111
|
```json
|
|
107
112
|
// project.inlang/settings.json
|
|
108
113
|
{
|
|
@@ -268,21 +273,25 @@ An "Adapter" is a library that integrates with a framework's liefcycle and does
|
|
|
268
273
|
This example adapts Paraglide to a fictitious fullstack framework.
|
|
269
274
|
|
|
270
275
|
```tsx
|
|
271
|
-
import {
|
|
276
|
+
import {
|
|
277
|
+
setLanguageTag,
|
|
278
|
+
onSetLanguageTag,
|
|
279
|
+
type AvailableLanguageTag,
|
|
280
|
+
} from "../paraglide/runtime.js"
|
|
272
281
|
import { isServer, isClient, request, render } from "@example/framework"
|
|
273
282
|
import { detectLanguage } from "./utils.js"
|
|
274
283
|
|
|
275
284
|
if (isServer) {
|
|
276
|
-
// On the server the language tag needs to be resolved on a per-request basis.
|
|
285
|
+
// On the server the language tag needs to be resolved on a per-request basis.
|
|
277
286
|
// Pass a getter function that resolves the language from the correct request
|
|
278
287
|
|
|
279
|
-
const detectLanguage = (request: Request)
|
|
288
|
+
const detectLanguage = (request: Request): AvailableLanguageTag => {
|
|
280
289
|
//your logic ...
|
|
281
290
|
}
|
|
282
291
|
setLanguageTag(() => detectLanguage(request))
|
|
283
292
|
}
|
|
284
293
|
|
|
285
|
-
if(isClient) {
|
|
294
|
+
if (isClient) {
|
|
286
295
|
// On the client, the language tag can be resolved from
|
|
287
296
|
// the document's html lang tag.
|
|
288
297
|
setLanguageTag(() => document.documentElement.lang)
|
|
@@ -304,20 +313,6 @@ render((page) => (
|
|
|
304
313
|
))
|
|
305
314
|
```
|
|
306
315
|
|
|
307
|
-
# Community
|
|
308
|
-
|
|
309
|
-
We are grateful for all the support we get from the community. Here are a few comments we've received recently.
|
|
310
|
-
|
|
311
|
-
If you have any feedback / problems, please let us know on [GitHub](https://github.com/opral/inlang-paraglide-js/issues/new)
|
|
312
|
-
|
|
313
|
-
<doc-comments>
|
|
314
|
-
<doc-comment text="Just tried Paraglide JS from @inlangHQ. This is how i18n should be done! Totally new level of DX for both implementation and managing translations! Superb support for SvelteKit as well ⭐" author="Patrik Engborg" icon="mdi:twitter" data-source="https://twitter.com/patrikengborg/status/1747260930873053674"></doc-comment>
|
|
315
|
-
<doc-comment text="I was messing with various i18n frameworks and tools in combination with Astro, and i must say that Paraglide was the smoothest experience. I have migrated my website from i18next and it was a breeze. SSG and SSR worked out of the box (which was the first one for me), and overall DX is great. Thanks for your work!" author="Dally H" icon="mdi:discord" data-source="https://discord.com/channels/897438559458430986/1096039983116202034/1220796380772307004"></doc-comment>
|
|
316
|
-
<doc-comment text="The lib is great guys!" author="ktarmyshov" icon="mdi:github"></doc-comment>
|
|
317
|
-
<doc-comment text="Thank you for that huge work you have done and still doing!" author="ZerdoX-x" icon="mdi:github"></doc-comment>
|
|
318
|
-
<doc-comment text="Thanks for all the great work @Samuel Stroschein" author="Willem" icon="mdi:discord"></doc-comment>
|
|
319
|
-
</doc-comments>
|
|
320
|
-
|
|
321
316
|
# Roadmap
|
|
322
317
|
|
|
323
318
|
Of course, we're not done yet! We plan on adding the following features to Paraglide JS soon:
|
|
@@ -325,6 +320,7 @@ Of course, we're not done yet! We plan on adding the following features to Parag
|
|
|
325
320
|
- [ ] Pluralization ([Join the Discussion](https://github.com/opral/monorepo/discussions/2025))
|
|
326
321
|
- [ ] Formatting of numbers and dates ([Join the Discussion](https://github.com/opral/monorepo/discussions/992))
|
|
327
322
|
- [ ] Markup Placeholders ([Join the Discussion](https://github.com/opral/monorepo/discussions/913))
|
|
323
|
+
- [ ] Even Smaller Output
|
|
328
324
|
|
|
329
325
|
# Talks
|
|
330
326
|
|
|
@@ -337,7 +333,7 @@ Of course, we're not done yet! We plan on adding the following features to Parag
|
|
|
337
333
|
|
|
338
334
|
Paraglide JS is part of the Inlang ecosystem and integrates nicely with all the other Inlang compatible tools.
|
|
339
335
|
|
|
340
|
-
As a developer, you will love the [Sherlock
|
|
336
|
+
As a developer, you will love the [Sherlock VsCode extension](https://inlang.com/m/r7kp499g/app-inlang-ideExtension).
|
|
341
337
|
|
|
342
338
|
If you are working with translators or designers you will find these tools useful:
|
|
343
339
|
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
import { type
|
|
3
|
-
import { Logger } from "
|
|
2
|
+
import { type InlangProject } from "@inlang/sdk";
|
|
3
|
+
import { Logger } from "../../../services/logger/index.js";
|
|
4
4
|
import { type Repository } from "@lix-js/client";
|
|
5
5
|
type Context = {
|
|
6
6
|
logger: Logger;
|
|
7
7
|
repo: Repository;
|
|
8
8
|
};
|
|
9
9
|
export declare const initCommand: Command;
|
|
10
|
-
export declare const initializeInlangProject: (ctx: Context) => Promise<
|
|
10
|
+
export declare const initializeInlangProject: (ctx: Context) => Promise<{
|
|
11
|
+
project: InlangProject;
|
|
12
|
+
/** Relative path to the project */
|
|
13
|
+
projectPath: string;
|
|
14
|
+
}>;
|
|
11
15
|
export declare const maybeAddVsCodeExtension: (args: {
|
|
12
16
|
projectPath: string;
|
|
13
17
|
}, ctx: Context) => Promise<void>;
|
|
@@ -15,13 +19,13 @@ export declare const addParaglideJsToDevDependencies: (ctx: Context) => Promise<
|
|
|
15
19
|
export declare const findExistingInlangProjectPath: (ctx: Context) => Promise<string | undefined>;
|
|
16
20
|
export declare const existingProjectFlow: (args: {
|
|
17
21
|
existingProjectPath: string;
|
|
18
|
-
}, ctx: Context) => Promise<
|
|
19
|
-
export declare const createNewProjectFlow: (ctx: Context) => Promise<
|
|
20
|
-
export declare const newProjectTemplate: ProjectSettings;
|
|
22
|
+
}, ctx: Context) => Promise<InlangProject>;
|
|
23
|
+
export declare const createNewProjectFlow: (ctx: Context) => Promise<InlangProject>;
|
|
21
24
|
export declare const checkIfPackageJsonExists: (ctx: Context) => Promise<undefined>;
|
|
22
25
|
export declare const checkIfUncommittedChanges: (ctx: Context) => Promise<void>;
|
|
23
26
|
export declare const addCompileStepToPackageJSON: (args: {
|
|
24
27
|
projectPath: string;
|
|
28
|
+
outdir: string;
|
|
25
29
|
}, ctx: Context) => Promise<undefined>;
|
|
26
30
|
/**
|
|
27
31
|
* Ensures that the moduleResolution compiler option is set to "bundler" or similar in the tsconfig.json.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @returns A new copy of the default project template that is safe to mutate.
|
|
3
|
+
*/
|
|
4
|
+
export declare function getNewProjectTemplate(): {
|
|
5
|
+
$schema: "https://inlang.com/schema/project-settings";
|
|
6
|
+
sourceLanguageTag: string;
|
|
7
|
+
languageTags: string[];
|
|
8
|
+
modules: string[];
|
|
9
|
+
"plugin.inlang.messageFormat": {
|
|
10
|
+
pathPattern: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare const DEFAULT_PROJECT_PATH = "./project.inlang";
|
|
14
|
+
export declare const DEFAULT_OUTDIR = "./src/paraglide";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes a command asynchronously in a separate process.
|
|
3
|
+
* It will not print the output to the console.
|
|
4
|
+
*
|
|
5
|
+
* @param command The command to execute.
|
|
6
|
+
* @returns The stdout of the command.
|
|
7
|
+
*/
|
|
8
|
+
export declare function execAsync(command: string): Promise<string>;
|