react-autolocale 0.2.0 → 0.3.0-beta.1
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 +169 -32
- package/dist/cli.js +879 -51
- package/dist/config-U-SpTtCW.js +24 -0
- package/dist/config.d.ts +66 -0
- package/dist/config.js +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +8 -7
- package/dist/project-BazDFtnp.js +1400 -0
- package/dist/{suggestion-UZQ8ngd0.js → redirect-pDFblLdm.js} +1 -24
- package/dist/suggestion-CkZQqMvZ.js +24 -0
- package/dist/translate-COrJX1KS.d.ts +22 -0
- package/dist/vite.d.ts +9 -28
- package/dist/vite.js +79 -475
- package/package.json +20 -6
- package/dist/overrides-ZQ6meLck.js +0 -557
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/core/config.ts
|
|
2
|
+
/** Typed helper for auto-locale.config.ts. */
|
|
3
|
+
function defineConfig(config) {
|
|
4
|
+
return config;
|
|
5
|
+
}
|
|
6
|
+
const PROVIDER_NAMES = [
|
|
7
|
+
"local",
|
|
8
|
+
"ollama",
|
|
9
|
+
"openai",
|
|
10
|
+
"anthropic",
|
|
11
|
+
"gemini"
|
|
12
|
+
];
|
|
13
|
+
const DEFAULT_MODELS = {
|
|
14
|
+
openai: "gpt-6-astra",
|
|
15
|
+
anthropic: "claude-opus-5-5",
|
|
16
|
+
gemini: "gemini-2.5-flash"
|
|
17
|
+
};
|
|
18
|
+
const DEFAULT_KEY_ENV = {
|
|
19
|
+
openai: "OPENAI_API_KEY",
|
|
20
|
+
anthropic: "ANTHROPIC_API_KEY",
|
|
21
|
+
gemini: "GEMINI_API_KEY"
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { defineConfig as i, DEFAULT_MODELS as n, PROVIDER_NAMES as r, DEFAULT_KEY_ENV as t };
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { n as Translator, t as TranslateFn } from "./translate-COrJX1KS.js";
|
|
2
|
+
//#region src/core/config.d.ts
|
|
3
|
+
/** The free local models (OPUS-MT / NLLB-200 through Transformers.js). Downloads happen only on `translate`. */
|
|
4
|
+
interface LocalProvider {
|
|
5
|
+
name: "local";
|
|
6
|
+
}
|
|
7
|
+
/** A local LLM served by Ollama. */
|
|
8
|
+
interface OllamaProvider {
|
|
9
|
+
name: "ollama";
|
|
10
|
+
model: string;
|
|
11
|
+
url?: string;
|
|
12
|
+
}
|
|
13
|
+
/** OpenAI through the official `openai` package (install it in your project). */
|
|
14
|
+
interface OpenAIProvider {
|
|
15
|
+
name: "openai";
|
|
16
|
+
/** Defaults to "gpt-6-astra". */
|
|
17
|
+
model?: string;
|
|
18
|
+
/** Environment variable holding the key. Defaults to OPENAI_API_KEY. */
|
|
19
|
+
apiKeyEnv?: string;
|
|
20
|
+
/** Custom endpoint, e.g. an Azure or self-hosted OpenAI-compatible gateway. */
|
|
21
|
+
baseURL?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Anthropic Claude through the official `@anthropic-ai/sdk` package (install it in your project). */
|
|
24
|
+
interface AnthropicProvider {
|
|
25
|
+
name: "anthropic";
|
|
26
|
+
/** Defaults to "claude-opus-5-5". */
|
|
27
|
+
model?: string;
|
|
28
|
+
/** Environment variable holding the key. Defaults to ANTHROPIC_API_KEY. */
|
|
29
|
+
apiKeyEnv?: string;
|
|
30
|
+
/** How much the model thinks per request. Short UI strings rarely need more than "low" (the default). */
|
|
31
|
+
effort?: "low" | "medium" | "high" | "xhigh" | "max";
|
|
32
|
+
}
|
|
33
|
+
/** Google Gemini through its REST API. No SDK needed. Get a key at https://aistudio.google.com/apikey. */
|
|
34
|
+
interface GeminiProvider {
|
|
35
|
+
name: "gemini";
|
|
36
|
+
/** Defaults to "gemini-2.5-flash". Use any model id listed in Google AI Studio. */
|
|
37
|
+
model?: string;
|
|
38
|
+
/** Environment variable holding the key. Defaults to GEMINI_API_KEY. */
|
|
39
|
+
apiKeyEnv?: string;
|
|
40
|
+
/** Custom endpoint, e.g. a proxy. Defaults to https://generativelanguage.googleapis.com/v1beta. */
|
|
41
|
+
baseURL?: string;
|
|
42
|
+
}
|
|
43
|
+
type ProviderConfig = LocalProvider | OllamaProvider | OpenAIProvider | AnthropicProvider | GeminiProvider;
|
|
44
|
+
interface AutoLocaleConfig {
|
|
45
|
+
/** Language the source code is written in, e.g. "en". */
|
|
46
|
+
sourceLocale?: string;
|
|
47
|
+
/** Every language the site ships in. The source language may be listed too. */
|
|
48
|
+
locales?: string[];
|
|
49
|
+
/**
|
|
50
|
+
* Where catalogs are written, relative to the project root. Defaults to `src/generated/auto-locale` when the
|
|
51
|
+
* project has a root-level `src/`, otherwise `generated/auto-locale`.
|
|
52
|
+
*/
|
|
53
|
+
output?: string;
|
|
54
|
+
/** Folders scanned for JSX. Defaults to "src" (or the project root when there is no src/). */
|
|
55
|
+
include?: string[];
|
|
56
|
+
/** Phrases never translated (brand and product names). Adds to `<AutoScale exclude>`. */
|
|
57
|
+
exclude?: string[];
|
|
58
|
+
/** Terms that must always translate a given way: { fr: { Roadmap: "Feuille de route" } }. */
|
|
59
|
+
glossary?: Record<string, Record<string, string>>;
|
|
60
|
+
/** Translation engine used by `react-autolocale translate`. Defaults to the local models. */
|
|
61
|
+
provider?: ProviderConfig | Translator | TranslateFn;
|
|
62
|
+
}
|
|
63
|
+
/** Typed helper for auto-locale.config.ts. */
|
|
64
|
+
export declare function defineConfig(config: AutoLocaleConfig): AutoLocaleConfig;
|
|
65
|
+
//#endregion
|
|
66
|
+
export type { AnthropicProvider, AutoLocaleConfig, GeminiProvider, LocalProvider, OllamaProvider, OpenAIProvider, ProviderConfig, TranslateFn, Translator };
|
package/dist/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { i as defineConfig } from "./config-U-SpTtCW.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -31,14 +31,16 @@ export interface AutoScaleProps {
|
|
|
31
31
|
* The props are read at build time by the Vite plugin.
|
|
32
32
|
*/
|
|
33
33
|
export declare function AutoScale({ children }: AutoScaleProps): ReactElement;
|
|
34
|
-
/** @internal Inserted by the Vite plugin in place of static JSX text. */
|
|
35
|
-
export declare function __T({ s }: {
|
|
34
|
+
/** @internal Inserted by the Vite plugin in place of static JSX text: message id and source text (the fallback). */
|
|
35
|
+
export declare function __T({ i, s }: {
|
|
36
|
+
i: string;
|
|
36
37
|
s: string;
|
|
37
38
|
}): ReactElement;
|
|
38
39
|
/** @internal Inserted by the Vite plugin for translated attributes (placeholder, alt, ...). */
|
|
39
|
-
export declare function __useT(): (s: string) => string;
|
|
40
|
+
export declare function __useT(): (i: string, s: string) => string;
|
|
40
41
|
/** @internal Inserted by the Vite plugin for text with variables, e.g. `Hello {name}`. */
|
|
41
|
-
export declare function __TD({ s, v }: {
|
|
42
|
+
export declare function __TD({ i, s, v }: {
|
|
43
|
+
i: string;
|
|
42
44
|
s: string;
|
|
43
45
|
v: Record<string, unknown>;
|
|
44
46
|
}): ReactElement;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as redirectTarget, t as STORAGE_KEY } from "./redirect-pDFblLdm.js";
|
|
2
|
+
import { n as DISMISSED_KEY, r as suggestLanguage, t as BANNER_EN } from "./suggestion-CkZQqMvZ.js";
|
|
2
3
|
import { Fragment, createContext, createElement, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
3
4
|
import { banner, languages, loaders, original, originalNative, seo } from "virtual:react-autolocale";
|
|
4
5
|
//#region src/runtime/index.ts
|
|
@@ -99,20 +100,20 @@ function AutoScale({ children }) {
|
|
|
99
100
|
}), [state, setLanguage]);
|
|
100
101
|
return createElement(Context.Provider, { value }, children);
|
|
101
102
|
}
|
|
102
|
-
/** @internal Inserted by the Vite plugin in place of static JSX text. */
|
|
103
|
-
function __T({ s }) {
|
|
103
|
+
/** @internal Inserted by the Vite plugin in place of static JSX text: message id and source text (the fallback). */
|
|
104
|
+
function __T({ i, s }) {
|
|
104
105
|
const { dict } = useContext(Context);
|
|
105
|
-
return createElement(Fragment, null, dict[
|
|
106
|
+
return createElement(Fragment, null, dict[i] || s);
|
|
106
107
|
}
|
|
107
108
|
/** @internal Inserted by the Vite plugin for translated attributes (placeholder, alt, ...). */
|
|
108
109
|
function __useT() {
|
|
109
110
|
const { dict } = useContext(Context);
|
|
110
|
-
return useCallback((s) => dict[
|
|
111
|
+
return useCallback((i, s) => dict[i] || s, [dict]);
|
|
111
112
|
}
|
|
112
113
|
/** @internal Inserted by the Vite plugin for text with variables, e.g. `Hello {name}`. */
|
|
113
|
-
function __TD({ s, v }) {
|
|
114
|
+
function __TD({ i, s, v }) {
|
|
114
115
|
const { dict } = useContext(Context);
|
|
115
|
-
const parts = (dict[
|
|
116
|
+
const parts = (dict[i] || s).split(/\{(\w+)\}/g).map((part, i) => i % 2 ? v[part] : part);
|
|
116
117
|
return createElement(Fragment, null, ...parts.map((p, i) => createElement(Fragment, { key: i }, p)));
|
|
117
118
|
}
|
|
118
119
|
/**
|