@linguanahq/next 0.0.0-stage → 0.1.0
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/dist/client.js +24083 -0
- package/dist/compiler-runtime.client.js +8 -0
- package/dist/compiler-runtime.server.js +23 -0
- package/dist/index.client.js +7 -0
- package/dist/index.server.js +23925 -0
- package/dist/loader-impl.cjs +91179 -0
- package/dist/loader.cjs +1 -0
- package/dist/plugin.cjs +91573 -0
- package/dist/plugin.js +91573 -0
- package/dist/react-runtime.js +25059 -0
- package/dist/request.js +24653 -0
- package/dist/server.js +25 -0
- package/dist/styles.css +1 -0
- package/dist/types/client.d.ts +26 -0
- package/dist/types/compiler-runtime.client.d.ts +1 -0
- package/dist/types/compiler-runtime.server.d.ts +14 -0
- package/dist/types/diagnostics.d.ts +3 -0
- package/dist/types/files.d.ts +4 -0
- package/dist/types/index.client.d.ts +1 -0
- package/dist/types/index.server.d.ts +4 -0
- package/dist/types/loader.d.ts +10 -0
- package/dist/types/plugin.d.ts +59 -0
- package/dist/types/react-runtime.d.ts +2 -0
- package/dist/types/request-core.d.ts +16 -0
- package/dist/types/request.d.ts +8 -0
- package/dist/types/server.d.ts +11 -0
- package/dist/types/types.d.ts +39 -0
- package/package.json +71 -5
- package/README.md +0 -3
package/dist/server.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/server.tsx
|
|
2
|
+
import"server-only";
|
|
3
|
+
import { ClientProvider } from "./client.js";
|
|
4
|
+
import { getRequestRuntime } from "./request.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
async function getLocale() {
|
|
7
|
+
return (await getRequestRuntime()).locale;
|
|
8
|
+
}
|
|
9
|
+
async function getTranslations() {
|
|
10
|
+
const { locale, t, translate } = await getRequestRuntime();
|
|
11
|
+
return { locale, t, translate };
|
|
12
|
+
}
|
|
13
|
+
async function LinguanaProvider({ children }) {
|
|
14
|
+
const { config, snapshot } = await getRequestRuntime();
|
|
15
|
+
return /* @__PURE__ */ jsx(ClientProvider, {
|
|
16
|
+
config,
|
|
17
|
+
snapshot,
|
|
18
|
+
children
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
getTranslations,
|
|
23
|
+
getLocale,
|
|
24
|
+
LinguanaProvider
|
|
25
|
+
};
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@linguanahq/core/styles.css";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DiagnosticEvent } from "@linguanahq/react";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import type { RequestSnapshot } from "./request-core.js";
|
|
4
|
+
import type { RuntimeConfig } from "./types.js";
|
|
5
|
+
export declare function ClientProvider({ config, snapshot, children, }: {
|
|
6
|
+
config: RuntimeConfig;
|
|
7
|
+
snapshot: RequestSnapshot;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
export declare function useTranslation(): {
|
|
11
|
+
setLocale: (locale: string) => Promise<void>;
|
|
12
|
+
ready: boolean;
|
|
13
|
+
diagnostics: DiagnosticEvent[];
|
|
14
|
+
formatters: import("@linguanahq/core").LocaleFormatters;
|
|
15
|
+
lang: string;
|
|
16
|
+
dir: "ltr" | "rtl";
|
|
17
|
+
locale: string;
|
|
18
|
+
sourceLocale: string;
|
|
19
|
+
t: (source: string, values?: import("@linguanahq/react").MessageValues, options?: import("@linguanahq/react").TranslationOptions) => ReactNode;
|
|
20
|
+
translate: (id: string, source: string, values?: import("@linguanahq/react").MessageValues, components?: import("@linguanahq/react").MessageComponents) => ReactNode;
|
|
21
|
+
availableLocales: readonly import("@linguanahq/react").LocaleOption[];
|
|
22
|
+
};
|
|
23
|
+
export declare function LanguageSelector({ label, className, }: {
|
|
24
|
+
label?: string;
|
|
25
|
+
className?: string;
|
|
26
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LinguanaAttributes, LinguanaMessage } from "./react-runtime.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
export declare function LinguanaMessage({ id, defaultMessage, }: {
|
|
4
|
+
id: string;
|
|
5
|
+
defaultMessage: string;
|
|
6
|
+
}): Promise<import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | (string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined)>;
|
|
7
|
+
export declare function LinguanaAttributes({ descriptors, children, }: {
|
|
8
|
+
descriptors: Array<{
|
|
9
|
+
name: string;
|
|
10
|
+
id: string;
|
|
11
|
+
defaultMessage: string;
|
|
12
|
+
}>;
|
|
13
|
+
children: (values: Record<string, string>) => ReactNode;
|
|
14
|
+
}): Promise<import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | (string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined)>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LoaderOptions } from "./types.js";
|
|
2
|
+
export declare const patterns: (value: string | string[] | undefined) => string[];
|
|
3
|
+
export declare function sourceFilter(options: LoaderOptions): (filename: string) => boolean;
|
|
4
|
+
export declare function sourceFiles(options: LoaderOptions): Promise<string[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { T } from "./react-runtime.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import type { T as ReactT } from "@linguanahq/react";
|
|
3
|
+
import type { ComponentProps } from "react";
|
|
4
|
+
export declare function T({ id, defaultMessage, values, components, context, }: ComponentProps<typeof ReactT>): Promise<import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | (string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined)>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import remapping from "@jridgewell/remapping";
|
|
2
|
+
import type { LoaderOptions } from "./types.js";
|
|
3
|
+
type InputMap = Parameters<typeof remapping>[0];
|
|
4
|
+
type Context = {
|
|
5
|
+
resourcePath: string;
|
|
6
|
+
getOptions(): LoaderOptions;
|
|
7
|
+
callback(error: Error | null, code?: string, map?: unknown): void;
|
|
8
|
+
};
|
|
9
|
+
export default function loader(this: Context, source: string, inputMap?: InputMap): void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { NextConfig } from "next";
|
|
2
|
+
import type { LinguanaNextOptions, LoaderOptions, RuntimeConfig } from "./types.js";
|
|
3
|
+
export type { LinguanaNextOptions } from "./types.js";
|
|
4
|
+
export type NextConfigInput = NextConfig | ((phase: string, context: {
|
|
5
|
+
defaultConfig: NextConfig;
|
|
6
|
+
}) => NextConfig | Promise<NextConfig>);
|
|
7
|
+
export declare function validateOptions(options: LinguanaNextOptions): void;
|
|
8
|
+
export declare function publicRuntimeConfig(options: LinguanaNextOptions): RuntimeConfig;
|
|
9
|
+
export declare function collectManifest(options: LinguanaNextOptions, loaderOptions: LoaderOptions, nextVersion: string): Promise<{
|
|
10
|
+
schemaVersion: "1.0" | "2.0";
|
|
11
|
+
compilerVersion: string;
|
|
12
|
+
projectId: string;
|
|
13
|
+
environment: string;
|
|
14
|
+
sourceLocale: string;
|
|
15
|
+
messages: {
|
|
16
|
+
id: string;
|
|
17
|
+
source: string;
|
|
18
|
+
normalized: string;
|
|
19
|
+
contentHash: string;
|
|
20
|
+
context: {
|
|
21
|
+
kind: "text" | "attribute" | "explicit";
|
|
22
|
+
element?: string | undefined;
|
|
23
|
+
attribute?: string | undefined;
|
|
24
|
+
developer?: string | undefined;
|
|
25
|
+
};
|
|
26
|
+
placeholders: {
|
|
27
|
+
name: string;
|
|
28
|
+
kind: "number" | "date" | "time" | "value" | "component" | "plural" | "select";
|
|
29
|
+
}[];
|
|
30
|
+
confidence: "explicit" | "high";
|
|
31
|
+
locations: {
|
|
32
|
+
file: string;
|
|
33
|
+
line: number;
|
|
34
|
+
column: number;
|
|
35
|
+
}[];
|
|
36
|
+
}[];
|
|
37
|
+
diagnostics: {
|
|
38
|
+
code: string;
|
|
39
|
+
severity: "error" | "info" | "warning";
|
|
40
|
+
message: string;
|
|
41
|
+
location?: {
|
|
42
|
+
file: string;
|
|
43
|
+
line: number;
|
|
44
|
+
column: number;
|
|
45
|
+
} | undefined;
|
|
46
|
+
remediation?: string | undefined;
|
|
47
|
+
}[];
|
|
48
|
+
sourceRevision?: string | undefined;
|
|
49
|
+
integration?: {
|
|
50
|
+
tool: "vite" | "next";
|
|
51
|
+
toolVersion: string;
|
|
52
|
+
framework: "react" | "vue" | "svelte" | "solid";
|
|
53
|
+
adapterVersion: string;
|
|
54
|
+
ssr: boolean;
|
|
55
|
+
} | undefined;
|
|
56
|
+
}>;
|
|
57
|
+
export declare function withLinguana(options: LinguanaNextOptions): (input?: NextConfigInput) => (phase: string, context: {
|
|
58
|
+
defaultConfig: NextConfig;
|
|
59
|
+
}) => Promise<NextConfig>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Catalog } from "@linguanahq/catalog";
|
|
2
|
+
import { type LocaleOption } from "@linguanahq/core";
|
|
3
|
+
import type { DiagnosticEvent, MessageComponents, MessageValues, TranslationOptions } from "@linguanahq/react";
|
|
4
|
+
import type { RuntimeConfig } from "./types.js";
|
|
5
|
+
export type RequestSnapshot = {
|
|
6
|
+
locale: string;
|
|
7
|
+
catalogs: Catalog[];
|
|
8
|
+
availableLocales: LocaleOption[];
|
|
9
|
+
diagnostics: DiagnosticEvent[];
|
|
10
|
+
};
|
|
11
|
+
export declare function resolveSnapshot(config: RuntimeConfig, cookie: string | undefined, acceptLanguage: string | null, fetcher?: typeof fetch): Promise<RequestSnapshot>;
|
|
12
|
+
export declare function createTranslator(config: RuntimeConfig, snapshot: RequestSnapshot, onDiagnostic?: (event: DiagnosticEvent) => void): {
|
|
13
|
+
locale: string;
|
|
14
|
+
t: (source: string, values?: MessageValues, options?: TranslationOptions) => import("react").ReactNode;
|
|
15
|
+
translate: (id: string, source: string, values?: MessageValues, components?: MessageComponents) => import("react").ReactNode;
|
|
16
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
export declare const getRequestRuntime: () => Promise<{
|
|
3
|
+
locale: string;
|
|
4
|
+
t: (source: string, values?: import("@linguanahq/react").MessageValues, options?: import("@linguanahq/react").TranslationOptions) => import("react").ReactNode;
|
|
5
|
+
translate: (id: string, source: string, values?: import("@linguanahq/react").MessageValues, components?: import("@linguanahq/react").MessageComponents) => import("react").ReactNode;
|
|
6
|
+
config: import("./types.js").RuntimeConfig;
|
|
7
|
+
snapshot: import("./request-core.js").RequestSnapshot;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
export declare function getLocale(): Promise<string>;
|
|
4
|
+
export declare function getTranslations(): Promise<{
|
|
5
|
+
locale: string;
|
|
6
|
+
t: (source: string, values?: import("@linguanahq/react").MessageValues, options?: import("@linguanahq/react").TranslationOptions) => ReactNode;
|
|
7
|
+
translate: (id: string, source: string, values?: import("@linguanahq/react").MessageValues, components?: import("@linguanahq/react").MessageComponents) => ReactNode;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function LinguanaProvider({ children }: {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}): Promise<import("react").JSX.Element>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { RemoteBuildOptions, StrictPolicy } from "@linguanahq/build-core";
|
|
2
|
+
import type { Catalog } from "@linguanahq/catalog";
|
|
3
|
+
import type { LocaleOption } from "@linguanahq/core";
|
|
4
|
+
export type RuntimeOptions = {
|
|
5
|
+
publishableKey?: string;
|
|
6
|
+
catalogEndpoint?: string;
|
|
7
|
+
configEndpoint?: string;
|
|
8
|
+
defaultLocale?: string;
|
|
9
|
+
availableLocales?: LocaleOption[];
|
|
10
|
+
catalogs?: Catalog[];
|
|
11
|
+
cookieName?: string;
|
|
12
|
+
};
|
|
13
|
+
export type RuntimeConfig = RuntimeOptions & {
|
|
14
|
+
projectId: string;
|
|
15
|
+
environment: string;
|
|
16
|
+
sourceLocale: string;
|
|
17
|
+
};
|
|
18
|
+
export type LinguanaNextOptions = {
|
|
19
|
+
projectId: string;
|
|
20
|
+
root?: string;
|
|
21
|
+
sourceLocale?: string;
|
|
22
|
+
environment?: string;
|
|
23
|
+
include?: string | string[];
|
|
24
|
+
exclude?: string | string[];
|
|
25
|
+
output?: string;
|
|
26
|
+
strict?: StrictPolicy;
|
|
27
|
+
upload?: boolean;
|
|
28
|
+
apiUrl?: string;
|
|
29
|
+
token?: string;
|
|
30
|
+
translation?: RemoteBuildOptions["translation"];
|
|
31
|
+
runtime?: RuntimeOptions;
|
|
32
|
+
};
|
|
33
|
+
export type LoaderOptions = {
|
|
34
|
+
root: string;
|
|
35
|
+
sourceLocale: string;
|
|
36
|
+
include?: string | string[];
|
|
37
|
+
exclude?: string | string[];
|
|
38
|
+
distDir: string;
|
|
39
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,72 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@linguanahq/next",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/types/index.server.d.ts",
|
|
14
|
+
"react-server": "./dist/index.server.js",
|
|
15
|
+
"default": "./dist/index.client.js"
|
|
16
|
+
},
|
|
17
|
+
"./plugin": {
|
|
18
|
+
"types": "./dist/types/plugin.d.ts",
|
|
19
|
+
"import": "./dist/plugin.js",
|
|
20
|
+
"require": "./dist/plugin.cjs"
|
|
21
|
+
},
|
|
22
|
+
"./server": {
|
|
23
|
+
"types": "./dist/types/server.d.ts",
|
|
24
|
+
"default": "./dist/server.js"
|
|
25
|
+
},
|
|
26
|
+
"./client": {
|
|
27
|
+
"types": "./dist/types/client.d.ts",
|
|
28
|
+
"default": "./dist/client.js"
|
|
29
|
+
},
|
|
30
|
+
"./compiler-runtime": {
|
|
31
|
+
"types": "./dist/types/compiler-runtime.server.d.ts",
|
|
32
|
+
"react-server": "./dist/compiler-runtime.server.js",
|
|
33
|
+
"default": "./dist/compiler-runtime.client.js"
|
|
34
|
+
},
|
|
35
|
+
"./loader": "./dist/loader.cjs",
|
|
36
|
+
"./styles.css": "./dist/styles.css"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "NODE_ENV=production bun build.ts",
|
|
40
|
+
"prepack": "bun run build",
|
|
41
|
+
"check-types": "tsc --noEmit",
|
|
42
|
+
"test": "bun test src"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"next": ">=16 <17",
|
|
46
|
+
"react": ">=19 <20",
|
|
47
|
+
"react-dom": ">=19 <20"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@linguana/config": "0.0.0",
|
|
51
|
+
"@linguanahq/compiler": "0.1.2",
|
|
52
|
+
"@jridgewell/remapping": "^2.3.5",
|
|
53
|
+
"tinyglobby": "^0.2.15",
|
|
54
|
+
"picomatch": "^4.0.3",
|
|
55
|
+
"@types/picomatch": "^4.0.3",
|
|
56
|
+
"@types/react": "^19.2.17",
|
|
57
|
+
"@types/react-dom": "^19.2.3",
|
|
58
|
+
"@types/bun": "^1.3.14",
|
|
59
|
+
"typescript": "^6",
|
|
60
|
+
"next": "^16.3.8",
|
|
61
|
+
"react": "^19.2.7",
|
|
62
|
+
"react-dom": "^19.2.7",
|
|
63
|
+
"server-only": "^0.0.1"
|
|
64
|
+
},
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"server-only": "^0.0.1",
|
|
67
|
+
"@linguanahq/catalog": "0.1.2",
|
|
68
|
+
"@linguanahq/core": "0.1.2",
|
|
69
|
+
"@linguanahq/react": "0.1.2",
|
|
70
|
+
"@linguanahq/build-core": "0.1.2"
|
|
71
|
+
}
|
|
72
|
+
}
|
package/README.md
DELETED