@awsless/i18n 0.0.9 → 0.0.10
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 +5 -7
- package/dist/index.cjs +35 -38
- package/dist/index.d.cts +13 -9
- package/dist/index.d.ts +13 -9
- package/dist/index.js +35 -38
- package/dist/svelte.svelte.cjs +20 -3
- package/dist/svelte.svelte.d.cts +12 -0
- package/dist/svelte.svelte.d.ts +12 -0
- package/dist/svelte.svelte.js +20 -3
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
# AI-generated internationalization made easy
|
|
2
2
|
|
|
3
|
-
The `@awsless/i18n` package is a Vite plugin that automatically translates your text during build time using AI or any other tool you prefer. The plugin will inline the translations so you don't have to worry about loading the translations at the right time.
|
|
3
|
+
The `@awsless/i18n` package is a Vite plugin that automatically translates your text during build time using AI or any other tool you prefer. The plugin will inline the translations so you don't have to worry about loading the translations at the right time. This means, switching the locale will instantly switch all your translated text on the page.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- Automatic text translation
|
|
8
8
|
- Inlines translations
|
|
9
|
-
- Extremely lightweight (
|
|
9
|
+
- Extremely lightweight (431 bytes uncompressed 🔥)
|
|
10
|
+
- Instant locale switch
|
|
10
11
|
- Svelte 5 support
|
|
11
12
|
|
|
12
|
-
## Todo's
|
|
13
|
-
|
|
14
|
-
- Create a CLI command to find the text that needs to be translated & translate it, so that we can remove that part from the vite plugin.
|
|
15
|
-
|
|
16
13
|
## Setup
|
|
17
14
|
|
|
18
15
|
Install with (NPM):
|
|
@@ -25,6 +22,7 @@ npm i @awsless/i18n
|
|
|
25
22
|
|
|
26
23
|
```ts
|
|
27
24
|
import { i18n, ai } from '@awsless/i18n'
|
|
25
|
+
import { openai } from '@ai-sdk/openai'
|
|
28
26
|
|
|
29
27
|
export defineConfig({
|
|
30
28
|
plugins: [
|
|
@@ -65,7 +63,7 @@ lang.t.get(`${count} count`, {
|
|
|
65
63
|
})
|
|
66
64
|
```
|
|
67
65
|
|
|
68
|
-
To change the locale that is being rendered simply
|
|
66
|
+
To change the locale that is being rendered simply change the `lang.locale` property.
|
|
69
67
|
|
|
70
68
|
```ts
|
|
71
69
|
import { lang } from '@awsless/i18n/svelte'
|
package/dist/index.cjs
CHANGED
|
@@ -55,32 +55,32 @@ var Cache = class {
|
|
|
55
55
|
constructor(data = {}) {
|
|
56
56
|
this.data = data;
|
|
57
57
|
}
|
|
58
|
-
set(
|
|
59
|
-
if (!this.data[
|
|
60
|
-
this.data[
|
|
58
|
+
set(source, locale, translation) {
|
|
59
|
+
if (!this.data[source]) {
|
|
60
|
+
this.data[source] = {};
|
|
61
61
|
}
|
|
62
|
-
if (!this.data[
|
|
63
|
-
this.data[
|
|
62
|
+
if (!this.data[source][locale]) {
|
|
63
|
+
this.data[source][locale] = translation;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
get(
|
|
67
|
-
return this.data[
|
|
66
|
+
get(source, locale) {
|
|
67
|
+
return this.data[source]?.[locale];
|
|
68
68
|
}
|
|
69
|
-
has(
|
|
70
|
-
return typeof this.get(
|
|
69
|
+
has(source, locale) {
|
|
70
|
+
return typeof this.get(source, locale) === "string";
|
|
71
71
|
}
|
|
72
|
-
delete(
|
|
73
|
-
if (this.data[
|
|
74
|
-
delete this.data[
|
|
72
|
+
delete(source, locale) {
|
|
73
|
+
if (this.data[source]?.[locale]) {
|
|
74
|
+
delete this.data[source][locale];
|
|
75
75
|
}
|
|
76
|
-
if (this.data[
|
|
77
|
-
delete this.data[
|
|
76
|
+
if (this.data[source] && Object.keys(this.data[source]).length === 0) {
|
|
77
|
+
delete this.data[source];
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
*entries() {
|
|
81
|
-
for (const [
|
|
81
|
+
for (const [source, locales] of Object.entries(this.data)) {
|
|
82
82
|
for (const [locale, translation] of Object.entries(locales)) {
|
|
83
|
-
yield {
|
|
83
|
+
yield { source, locale, translation };
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -90,21 +90,21 @@ var Cache = class {
|
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
// src/diff.ts
|
|
93
|
-
var findNewTranslations = (cache,
|
|
93
|
+
var findNewTranslations = (cache, sources, locales) => {
|
|
94
94
|
const list = [];
|
|
95
|
-
for (const
|
|
95
|
+
for (const source of sources) {
|
|
96
96
|
for (const locale of locales) {
|
|
97
|
-
if (!cache.has(
|
|
98
|
-
list.push({
|
|
97
|
+
if (!cache.has(source, locale)) {
|
|
98
|
+
list.push({ source, locale });
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
return list;
|
|
103
103
|
};
|
|
104
|
-
var removeUnusedTranslations = (cache,
|
|
104
|
+
var removeUnusedTranslations = (cache, sources, locales) => {
|
|
105
105
|
for (const item of cache.entries()) {
|
|
106
|
-
if (!locales.includes(item.locale) || !
|
|
107
|
-
cache.delete(item.
|
|
106
|
+
if (!locales.includes(item.locale) || !sources.includes(item.source)) {
|
|
107
|
+
cache.delete(item.source, item.locale);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
};
|
|
@@ -125,10 +125,7 @@ var findSvelteTranslatable = (code) => {
|
|
|
125
125
|
css: false
|
|
126
126
|
});
|
|
127
127
|
const enter = (node) => {
|
|
128
|
-
if (
|
|
129
|
-
//
|
|
130
|
-
node.type === "TaggedTemplateExpression" && node.tag.type === "MemberExpression" && node.tag.object.type === "Identifier" && node.tag.object.name === "lang" && node.tag.property.type === "Identifier" && node.tag.property.name === "t" && node.quasi.type === "TemplateLiteral" && node.quasi.loc
|
|
131
|
-
) {
|
|
128
|
+
if (node.type === "TaggedTemplateExpression" && node.tag.type === "MemberExpression" && node.tag.object.type === "Identifier" && node.tag.object.name === "lang" && node.tag.property.type === "Identifier" && node.tag.property.name === "t" && node.quasi.type === "TemplateLiteral" && node.quasi.loc) {
|
|
132
129
|
const start = node.quasi.loc.start;
|
|
133
130
|
const end = node.quasi.loc.end;
|
|
134
131
|
const content = code.substring(
|
|
@@ -204,16 +201,16 @@ var createI18nPlugin = (props) => {
|
|
|
204
201
|
async buildStart() {
|
|
205
202
|
const cwd = process.cwd();
|
|
206
203
|
this.info("Finding all translatable text...");
|
|
207
|
-
const
|
|
204
|
+
const sourceTexts = await findTranslatable(cwd);
|
|
208
205
|
cache = await loadCache(cwd);
|
|
209
|
-
removeUnusedTranslations(cache,
|
|
210
|
-
const
|
|
211
|
-
if (
|
|
212
|
-
this.info(`Translating ${
|
|
213
|
-
const translations = await props.translate(props.default ?? "en",
|
|
206
|
+
removeUnusedTranslations(cache, sourceTexts, props.locales);
|
|
207
|
+
const newSourceTexts = findNewTranslations(cache, sourceTexts, props.locales);
|
|
208
|
+
if (newSourceTexts.length > 0) {
|
|
209
|
+
this.info(`Translating ${newSourceTexts.length} new texts.`);
|
|
210
|
+
const translations = await props.translate(props.default ?? "en", newSourceTexts);
|
|
214
211
|
this.info(`Translated ${translations.length} texts.`);
|
|
215
212
|
for (const item of translations) {
|
|
216
|
-
cache.set(item.
|
|
213
|
+
cache.set(item.source, item.locale, item.translation);
|
|
217
214
|
}
|
|
218
215
|
}
|
|
219
216
|
await saveCache(cwd, cache);
|
|
@@ -223,10 +220,10 @@ var createI18nPlugin = (props) => {
|
|
|
223
220
|
let replaced = false;
|
|
224
221
|
if (code.includes("lang.t`")) {
|
|
225
222
|
for (const item of cache.entries()) {
|
|
226
|
-
code = code.replaceAll(`lang.t\`${item.
|
|
223
|
+
code = code.replaceAll(`lang.t\`${item.source}\``, () => {
|
|
227
224
|
replaced = true;
|
|
228
|
-
return `lang.t.get(\`${item.
|
|
229
|
-
return `"${locale}":\`${cache.get(item.
|
|
225
|
+
return `lang.t.get(\`${item.source}\`, {${props.locales.map((locale) => {
|
|
226
|
+
return `"${locale}":\`${cache.get(item.source, locale)}\``;
|
|
230
227
|
}).join(",")}})`;
|
|
231
228
|
});
|
|
232
229
|
}
|
|
@@ -255,7 +252,7 @@ var ai = (props) => {
|
|
|
255
252
|
maxTokens: props.maxTokens,
|
|
256
253
|
schema: import_zod.z.object({
|
|
257
254
|
translations: import_zod.z.object({
|
|
258
|
-
|
|
255
|
+
source: import_zod.z.string(),
|
|
259
256
|
locale: import_zod.z.string(),
|
|
260
257
|
translation: import_zod.z.string()
|
|
261
258
|
}).array()
|
package/dist/index.d.cts
CHANGED
|
@@ -2,32 +2,36 @@ import { Plugin } from 'vite';
|
|
|
2
2
|
import { LanguageModel } from 'ai';
|
|
3
3
|
|
|
4
4
|
type Translator = (defaultLocale: string, list: {
|
|
5
|
-
|
|
5
|
+
source: string;
|
|
6
6
|
locale: string;
|
|
7
7
|
}[]) => TranslationResponse[] | Promise<TranslationResponse[]>;
|
|
8
8
|
type TranslationResponse = {
|
|
9
|
-
|
|
9
|
+
source: string;
|
|
10
10
|
locale: string;
|
|
11
11
|
translation: string;
|
|
12
12
|
};
|
|
13
13
|
type I18nPluginProps = {
|
|
14
|
-
/** The
|
|
14
|
+
/** The original language your source text is written in.
|
|
15
|
+
* @default "en"
|
|
16
|
+
*/
|
|
15
17
|
default?: string;
|
|
16
|
-
/**
|
|
18
|
+
/** The list of target locales to translate your text into. */
|
|
17
19
|
locales: string[];
|
|
18
|
-
/**
|
|
20
|
+
/** Function that performs the translation of a given text. */
|
|
19
21
|
translate: Translator;
|
|
20
22
|
};
|
|
21
23
|
declare const createI18nPlugin: (props: I18nPluginProps) => Plugin;
|
|
22
24
|
|
|
23
25
|
type AiTranslationProps = {
|
|
24
|
-
/** The maximum number of tokens
|
|
26
|
+
/** The maximum number of tokens allowed in the AI's response. */
|
|
25
27
|
maxTokens: number;
|
|
26
|
-
/**
|
|
28
|
+
/** The language model to use for translations (e.g., gpt-4, gpt-3.5-turbo). */
|
|
27
29
|
model: LanguageModel;
|
|
28
|
-
/**
|
|
30
|
+
/** Number of text entries to translate in a single batch.
|
|
31
|
+
* @default 1000
|
|
32
|
+
*/
|
|
29
33
|
batchSize?: number;
|
|
30
|
-
/**
|
|
34
|
+
/** Custom translation guidelines for the AI. These are injected into the prompt. */
|
|
31
35
|
rules?: string[];
|
|
32
36
|
};
|
|
33
37
|
declare const ai: (props: AiTranslationProps) => Translator;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,32 +2,36 @@ import { Plugin } from 'vite';
|
|
|
2
2
|
import { LanguageModel } from 'ai';
|
|
3
3
|
|
|
4
4
|
type Translator = (defaultLocale: string, list: {
|
|
5
|
-
|
|
5
|
+
source: string;
|
|
6
6
|
locale: string;
|
|
7
7
|
}[]) => TranslationResponse[] | Promise<TranslationResponse[]>;
|
|
8
8
|
type TranslationResponse = {
|
|
9
|
-
|
|
9
|
+
source: string;
|
|
10
10
|
locale: string;
|
|
11
11
|
translation: string;
|
|
12
12
|
};
|
|
13
13
|
type I18nPluginProps = {
|
|
14
|
-
/** The
|
|
14
|
+
/** The original language your source text is written in.
|
|
15
|
+
* @default "en"
|
|
16
|
+
*/
|
|
15
17
|
default?: string;
|
|
16
|
-
/**
|
|
18
|
+
/** The list of target locales to translate your text into. */
|
|
17
19
|
locales: string[];
|
|
18
|
-
/**
|
|
20
|
+
/** Function that performs the translation of a given text. */
|
|
19
21
|
translate: Translator;
|
|
20
22
|
};
|
|
21
23
|
declare const createI18nPlugin: (props: I18nPluginProps) => Plugin;
|
|
22
24
|
|
|
23
25
|
type AiTranslationProps = {
|
|
24
|
-
/** The maximum number of tokens
|
|
26
|
+
/** The maximum number of tokens allowed in the AI's response. */
|
|
25
27
|
maxTokens: number;
|
|
26
|
-
/**
|
|
28
|
+
/** The language model to use for translations (e.g., gpt-4, gpt-3.5-turbo). */
|
|
27
29
|
model: LanguageModel;
|
|
28
|
-
/**
|
|
30
|
+
/** Number of text entries to translate in a single batch.
|
|
31
|
+
* @default 1000
|
|
32
|
+
*/
|
|
29
33
|
batchSize?: number;
|
|
30
|
-
/**
|
|
34
|
+
/** Custom translation guidelines for the AI. These are injected into the prompt. */
|
|
31
35
|
rules?: string[];
|
|
32
36
|
};
|
|
33
37
|
declare const ai: (props: AiTranslationProps) => Translator;
|
package/dist/index.js
CHANGED
|
@@ -18,32 +18,32 @@ var Cache = class {
|
|
|
18
18
|
constructor(data = {}) {
|
|
19
19
|
this.data = data;
|
|
20
20
|
}
|
|
21
|
-
set(
|
|
22
|
-
if (!this.data[
|
|
23
|
-
this.data[
|
|
21
|
+
set(source, locale, translation) {
|
|
22
|
+
if (!this.data[source]) {
|
|
23
|
+
this.data[source] = {};
|
|
24
24
|
}
|
|
25
|
-
if (!this.data[
|
|
26
|
-
this.data[
|
|
25
|
+
if (!this.data[source][locale]) {
|
|
26
|
+
this.data[source][locale] = translation;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
get(
|
|
30
|
-
return this.data[
|
|
29
|
+
get(source, locale) {
|
|
30
|
+
return this.data[source]?.[locale];
|
|
31
31
|
}
|
|
32
|
-
has(
|
|
33
|
-
return typeof this.get(
|
|
32
|
+
has(source, locale) {
|
|
33
|
+
return typeof this.get(source, locale) === "string";
|
|
34
34
|
}
|
|
35
|
-
delete(
|
|
36
|
-
if (this.data[
|
|
37
|
-
delete this.data[
|
|
35
|
+
delete(source, locale) {
|
|
36
|
+
if (this.data[source]?.[locale]) {
|
|
37
|
+
delete this.data[source][locale];
|
|
38
38
|
}
|
|
39
|
-
if (this.data[
|
|
40
|
-
delete this.data[
|
|
39
|
+
if (this.data[source] && Object.keys(this.data[source]).length === 0) {
|
|
40
|
+
delete this.data[source];
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
*entries() {
|
|
44
|
-
for (const [
|
|
44
|
+
for (const [source, locales] of Object.entries(this.data)) {
|
|
45
45
|
for (const [locale, translation] of Object.entries(locales)) {
|
|
46
|
-
yield {
|
|
46
|
+
yield { source, locale, translation };
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -53,21 +53,21 @@ var Cache = class {
|
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
// src/diff.ts
|
|
56
|
-
var findNewTranslations = (cache,
|
|
56
|
+
var findNewTranslations = (cache, sources, locales) => {
|
|
57
57
|
const list = [];
|
|
58
|
-
for (const
|
|
58
|
+
for (const source of sources) {
|
|
59
59
|
for (const locale of locales) {
|
|
60
|
-
if (!cache.has(
|
|
61
|
-
list.push({
|
|
60
|
+
if (!cache.has(source, locale)) {
|
|
61
|
+
list.push({ source, locale });
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
return list;
|
|
66
66
|
};
|
|
67
|
-
var removeUnusedTranslations = (cache,
|
|
67
|
+
var removeUnusedTranslations = (cache, sources, locales) => {
|
|
68
68
|
for (const item of cache.entries()) {
|
|
69
|
-
if (!locales.includes(item.locale) || !
|
|
70
|
-
cache.delete(item.
|
|
69
|
+
if (!locales.includes(item.locale) || !sources.includes(item.source)) {
|
|
70
|
+
cache.delete(item.source, item.locale);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
};
|
|
@@ -88,10 +88,7 @@ var findSvelteTranslatable = (code) => {
|
|
|
88
88
|
css: false
|
|
89
89
|
});
|
|
90
90
|
const enter = (node) => {
|
|
91
|
-
if (
|
|
92
|
-
//
|
|
93
|
-
node.type === "TaggedTemplateExpression" && node.tag.type === "MemberExpression" && node.tag.object.type === "Identifier" && node.tag.object.name === "lang" && node.tag.property.type === "Identifier" && node.tag.property.name === "t" && node.quasi.type === "TemplateLiteral" && node.quasi.loc
|
|
94
|
-
) {
|
|
91
|
+
if (node.type === "TaggedTemplateExpression" && node.tag.type === "MemberExpression" && node.tag.object.type === "Identifier" && node.tag.object.name === "lang" && node.tag.property.type === "Identifier" && node.tag.property.name === "t" && node.quasi.type === "TemplateLiteral" && node.quasi.loc) {
|
|
95
92
|
const start = node.quasi.loc.start;
|
|
96
93
|
const end = node.quasi.loc.end;
|
|
97
94
|
const content = code.substring(
|
|
@@ -167,16 +164,16 @@ var createI18nPlugin = (props) => {
|
|
|
167
164
|
async buildStart() {
|
|
168
165
|
const cwd = process.cwd();
|
|
169
166
|
this.info("Finding all translatable text...");
|
|
170
|
-
const
|
|
167
|
+
const sourceTexts = await findTranslatable(cwd);
|
|
171
168
|
cache = await loadCache(cwd);
|
|
172
|
-
removeUnusedTranslations(cache,
|
|
173
|
-
const
|
|
174
|
-
if (
|
|
175
|
-
this.info(`Translating ${
|
|
176
|
-
const translations = await props.translate(props.default ?? "en",
|
|
169
|
+
removeUnusedTranslations(cache, sourceTexts, props.locales);
|
|
170
|
+
const newSourceTexts = findNewTranslations(cache, sourceTexts, props.locales);
|
|
171
|
+
if (newSourceTexts.length > 0) {
|
|
172
|
+
this.info(`Translating ${newSourceTexts.length} new texts.`);
|
|
173
|
+
const translations = await props.translate(props.default ?? "en", newSourceTexts);
|
|
177
174
|
this.info(`Translated ${translations.length} texts.`);
|
|
178
175
|
for (const item of translations) {
|
|
179
|
-
cache.set(item.
|
|
176
|
+
cache.set(item.source, item.locale, item.translation);
|
|
180
177
|
}
|
|
181
178
|
}
|
|
182
179
|
await saveCache(cwd, cache);
|
|
@@ -186,10 +183,10 @@ var createI18nPlugin = (props) => {
|
|
|
186
183
|
let replaced = false;
|
|
187
184
|
if (code.includes("lang.t`")) {
|
|
188
185
|
for (const item of cache.entries()) {
|
|
189
|
-
code = code.replaceAll(`lang.t\`${item.
|
|
186
|
+
code = code.replaceAll(`lang.t\`${item.source}\``, () => {
|
|
190
187
|
replaced = true;
|
|
191
|
-
return `lang.t.get(\`${item.
|
|
192
|
-
return `"${locale}":\`${cache.get(item.
|
|
188
|
+
return `lang.t.get(\`${item.source}\`, {${props.locales.map((locale) => {
|
|
189
|
+
return `"${locale}":\`${cache.get(item.source, locale)}\``;
|
|
193
190
|
}).join(",")}})`;
|
|
194
191
|
});
|
|
195
192
|
}
|
|
@@ -218,7 +215,7 @@ var ai = (props) => {
|
|
|
218
215
|
maxTokens: props.maxTokens,
|
|
219
216
|
schema: z.object({
|
|
220
217
|
translations: z.object({
|
|
221
|
-
|
|
218
|
+
source: z.string(),
|
|
222
219
|
locale: z.string(),
|
|
223
220
|
translation: z.string()
|
|
224
221
|
}).array()
|
package/dist/svelte.svelte.cjs
CHANGED
|
@@ -34,12 +34,29 @@ var t = $derived.by(() => {
|
|
|
34
34
|
return api;
|
|
35
35
|
});
|
|
36
36
|
var lang = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
/** Get the current locale.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* console.log(lang.locale)
|
|
41
|
+
*/
|
|
40
42
|
get locale() {
|
|
41
43
|
return locale;
|
|
42
44
|
},
|
|
45
|
+
/** To change the locale that is being rendered simply change this property.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* lang.locale = 'jp'
|
|
49
|
+
*/
|
|
50
|
+
set locale(v) {
|
|
51
|
+
locale = v;
|
|
52
|
+
},
|
|
53
|
+
/** Translate helper for translating template strings.
|
|
54
|
+
* The i18n Vite plugin will find all instances where you want text
|
|
55
|
+
* to be translated and automatically translate your text during build time.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* lang.t`Hello world!`
|
|
59
|
+
*/
|
|
43
60
|
get t() {
|
|
44
61
|
return t;
|
|
45
62
|
}
|
package/dist/svelte.svelte.d.cts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
declare const lang: {
|
|
2
|
+
/** Get the current locale.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* console.log(lang.locale)
|
|
6
|
+
*/
|
|
2
7
|
locale: string;
|
|
8
|
+
/** Translate helper for translating template strings.
|
|
9
|
+
* The i18n Vite plugin will find all instances where you want text
|
|
10
|
+
* to be translated and automatically translate your text during build time.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* lang.t`Hello world!`
|
|
14
|
+
*/
|
|
3
15
|
readonly t: (template: TemplateStringsArray, ...args: Array<string | number | {
|
|
4
16
|
toString(): string;
|
|
5
17
|
}>) => string;
|
package/dist/svelte.svelte.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
declare const lang: {
|
|
2
|
+
/** Get the current locale.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* console.log(lang.locale)
|
|
6
|
+
*/
|
|
2
7
|
locale: string;
|
|
8
|
+
/** Translate helper for translating template strings.
|
|
9
|
+
* The i18n Vite plugin will find all instances where you want text
|
|
10
|
+
* to be translated and automatically translate your text during build time.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* lang.t`Hello world!`
|
|
14
|
+
*/
|
|
3
15
|
readonly t: (template: TemplateStringsArray, ...args: Array<string | number | {
|
|
4
16
|
toString(): string;
|
|
5
17
|
}>) => string;
|
package/dist/svelte.svelte.js
CHANGED
|
@@ -10,12 +10,29 @@ var t = $derived.by(() => {
|
|
|
10
10
|
return api;
|
|
11
11
|
});
|
|
12
12
|
var lang = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
/** Get the current locale.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* console.log(lang.locale)
|
|
17
|
+
*/
|
|
16
18
|
get locale() {
|
|
17
19
|
return locale;
|
|
18
20
|
},
|
|
21
|
+
/** To change the locale that is being rendered simply change this property.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* lang.locale = 'jp'
|
|
25
|
+
*/
|
|
26
|
+
set locale(v) {
|
|
27
|
+
locale = v;
|
|
28
|
+
},
|
|
29
|
+
/** Translate helper for translating template strings.
|
|
30
|
+
* The i18n Vite plugin will find all instances where you want text
|
|
31
|
+
* to be translated and automatically translate your text during build time.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* lang.t`Hello world!`
|
|
35
|
+
*/
|
|
19
36
|
get t() {
|
|
20
37
|
return t;
|
|
21
38
|
}
|