astro-intl 2.0.2 → 2.0.3
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 +701 -701
- package/package.json +99 -99
- package/dist/react.d.ts +0 -5
- package/dist/react.js +0 -42
package/package.json
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "astro-intl",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "
|
|
6
|
-
"keywords": [
|
|
7
|
-
"astro",
|
|
8
|
-
"astro-integration",
|
|
9
|
-
"astro-component",
|
|
10
|
-
"withastro",
|
|
11
|
-
"i18n",
|
|
12
|
-
"internationalization",
|
|
13
|
-
"intl",
|
|
14
|
-
"translations",
|
|
15
|
-
"typescript",
|
|
16
|
-
"accessibility",
|
|
17
|
-
"a11y"
|
|
18
|
-
],
|
|
19
|
-
"author": "Erick Cruz <erickj.cruzs@gmail.com>",
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"scripts": {
|
|
22
|
-
"test": "vitest run",
|
|
23
|
-
"test:watch": "vitest",
|
|
24
|
-
"test:ui": "vitest --ui",
|
|
25
|
-
"test:coverage": "vitest run --coverage",
|
|
26
|
-
"build": "tsc -p tsconfig.json",
|
|
27
|
-
"dev": "tsc -p tsconfig.json --watch",
|
|
28
|
-
"lint": "eslint . --max-warnings 0",
|
|
29
|
-
"lint:fix": "eslint . --fix",
|
|
30
|
-
"format": "prettier --write .",
|
|
31
|
-
"format:check": "prettier --check ."
|
|
32
|
-
},
|
|
33
|
-
"files": [
|
|
34
|
-
"dist"
|
|
35
|
-
],
|
|
36
|
-
"main": "./dist/index.js",
|
|
37
|
-
"types": "./dist/index.d.ts",
|
|
38
|
-
"exports": {
|
|
39
|
-
".": {
|
|
40
|
-
"types": "./dist/index.d.ts",
|
|
41
|
-
"import": "./dist/index.js"
|
|
42
|
-
},
|
|
43
|
-
"./middleware": {
|
|
44
|
-
"types": "./dist/middleware.d.ts",
|
|
45
|
-
"import": "./dist/middleware.js"
|
|
46
|
-
},
|
|
47
|
-
"./react": {
|
|
48
|
-
"types": "./dist/adapters/react.d.ts",
|
|
49
|
-
"import": "./dist/adapters/react.js"
|
|
50
|
-
},
|
|
51
|
-
"./svelte": {
|
|
52
|
-
"types": "./dist/adapters/svelte.d.ts",
|
|
53
|
-
"import": "./dist/adapters/svelte.js"
|
|
54
|
-
},
|
|
55
|
-
"./routing": {
|
|
56
|
-
"types": "./dist/routing.d.ts",
|
|
57
|
-
"import": "./dist/routing.js"
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
"peerDependencies": {
|
|
61
|
-
"astro": "^4 || ^5"
|
|
62
|
-
},
|
|
63
|
-
"peerDependenciesMeta": {
|
|
64
|
-
"react": {
|
|
65
|
-
"optional": true
|
|
66
|
-
},
|
|
67
|
-
"svelte": {
|
|
68
|
-
"optional": true
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
"repository": {
|
|
72
|
-
"type": "git",
|
|
73
|
-
"url": "https://github.com/ErickCSS/astro-intl"
|
|
74
|
-
},
|
|
75
|
-
"bugs": {
|
|
76
|
-
"url": "https://github.com/ErickCSS/astro-intl/issues"
|
|
77
|
-
},
|
|
78
|
-
"homepage": "https://github.com/ErickCSS/astro-intl#readme",
|
|
79
|
-
"publishConfig": {
|
|
80
|
-
"access": "public"
|
|
81
|
-
},
|
|
82
|
-
"devDependencies": {
|
|
83
|
-
"@eslint/js": "^9.17.0",
|
|
84
|
-
"@testing-library/jest-dom": "^6.9.1",
|
|
85
|
-
"@testing-library/react": "^16.3.2",
|
|
86
|
-
"@types/react": "^18.3.18",
|
|
87
|
-
"@vitest/ui": "^4.0.18",
|
|
88
|
-
"astro": "^5.17.3",
|
|
89
|
-
"eslint": "^9.17.0",
|
|
90
|
-
"happy-dom": "^20.7.0",
|
|
91
|
-
"prettier": "^3.4.2",
|
|
92
|
-
"react": "^19.2.4",
|
|
93
|
-
"react-dom": "^19.2.4",
|
|
94
|
-
"typescript": "^5.9.3",
|
|
95
|
-
"typescript-eslint": "^8.19.1",
|
|
96
|
-
"svelte": "^5.0.0",
|
|
97
|
-
"vitest": "^4.0.18"
|
|
98
|
-
}
|
|
99
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "astro-intl",
|
|
3
|
+
"version": "2.0.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Simple and type-safe internationalization system for Astro.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"astro",
|
|
8
|
+
"astro-integration",
|
|
9
|
+
"astro-component",
|
|
10
|
+
"withastro",
|
|
11
|
+
"i18n",
|
|
12
|
+
"internationalization",
|
|
13
|
+
"intl",
|
|
14
|
+
"translations",
|
|
15
|
+
"typescript",
|
|
16
|
+
"accessibility",
|
|
17
|
+
"a11y"
|
|
18
|
+
],
|
|
19
|
+
"author": "Erick Cruz <erickj.cruzs@gmail.com>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest",
|
|
24
|
+
"test:ui": "vitest --ui",
|
|
25
|
+
"test:coverage": "vitest run --coverage",
|
|
26
|
+
"build": "tsc -p tsconfig.json",
|
|
27
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
28
|
+
"lint": "eslint . --max-warnings 0",
|
|
29
|
+
"lint:fix": "eslint . --fix",
|
|
30
|
+
"format": "prettier --write .",
|
|
31
|
+
"format:check": "prettier --check ."
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"main": "./dist/index.js",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"import": "./dist/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./middleware": {
|
|
44
|
+
"types": "./dist/middleware.d.ts",
|
|
45
|
+
"import": "./dist/middleware.js"
|
|
46
|
+
},
|
|
47
|
+
"./react": {
|
|
48
|
+
"types": "./dist/adapters/react.d.ts",
|
|
49
|
+
"import": "./dist/adapters/react.js"
|
|
50
|
+
},
|
|
51
|
+
"./svelte": {
|
|
52
|
+
"types": "./dist/adapters/svelte.d.ts",
|
|
53
|
+
"import": "./dist/adapters/svelte.js"
|
|
54
|
+
},
|
|
55
|
+
"./routing": {
|
|
56
|
+
"types": "./dist/routing.d.ts",
|
|
57
|
+
"import": "./dist/routing.js"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"astro": "^4 || ^5"
|
|
62
|
+
},
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"react": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"svelte": {
|
|
68
|
+
"optional": true
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"repository": {
|
|
72
|
+
"type": "git",
|
|
73
|
+
"url": "https://github.com/ErickCSS/astro-intl"
|
|
74
|
+
},
|
|
75
|
+
"bugs": {
|
|
76
|
+
"url": "https://github.com/ErickCSS/astro-intl/issues"
|
|
77
|
+
},
|
|
78
|
+
"homepage": "https://github.com/ErickCSS/astro-intl#readme",
|
|
79
|
+
"publishConfig": {
|
|
80
|
+
"access": "public"
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@eslint/js": "^9.17.0",
|
|
84
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
85
|
+
"@testing-library/react": "^16.3.2",
|
|
86
|
+
"@types/react": "^18.3.18",
|
|
87
|
+
"@vitest/ui": "^4.0.18",
|
|
88
|
+
"astro": "^5.17.3",
|
|
89
|
+
"eslint": "^9.17.0",
|
|
90
|
+
"happy-dom": "^20.7.0",
|
|
91
|
+
"prettier": "^3.4.2",
|
|
92
|
+
"react": "^19.2.4",
|
|
93
|
+
"react-dom": "^19.2.4",
|
|
94
|
+
"typescript": "^5.9.3",
|
|
95
|
+
"typescript-eslint": "^8.19.1",
|
|
96
|
+
"svelte": "^5.0.0",
|
|
97
|
+
"vitest": "^4.0.18"
|
|
98
|
+
}
|
|
99
|
+
}
|
package/dist/react.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from "react";
|
|
2
|
-
import { type DotPaths } from "./interpolation.js";
|
|
3
|
-
export declare function createGetTranslationsReact<UI extends Record<string, Record<string, unknown>>, DefaultLocale extends keyof UI>(ui: UI, defaultLocale: DefaultLocale): <N extends keyof UI[DefaultLocale]>(lang: string | undefined, namespace: N) => ((key: DotPaths<UI[DefaultLocale][N]>) => string) & {
|
|
4
|
-
rich: (key: DotPaths<UI[DefaultLocale][N]>, tags: Record<string, (chunks: string) => ReactNode>) => ReactNode[];
|
|
5
|
-
};
|
package/dist/react.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { getNestedValue } from "./interpolation.js";
|
|
2
|
-
import { escapeRegExp } from "./sanitize.js";
|
|
3
|
-
export function createGetTranslationsReact(ui, defaultLocale) {
|
|
4
|
-
return function getTranslationsReact(lang, namespace) {
|
|
5
|
-
const resolvedLang = lang && lang in ui ? lang : defaultLocale;
|
|
6
|
-
const messages = ui[resolvedLang][namespace];
|
|
7
|
-
function t(key) {
|
|
8
|
-
const value = getNestedValue(messages, key);
|
|
9
|
-
return typeof value === "string" ? value : key;
|
|
10
|
-
}
|
|
11
|
-
const rich = function (key, tags) {
|
|
12
|
-
const str = t(key);
|
|
13
|
-
// Función recursiva para procesar tags anidados
|
|
14
|
-
function processString(input) {
|
|
15
|
-
const tagNames = Object.keys(tags).map(escapeRegExp);
|
|
16
|
-
const regex = new RegExp(`<(${tagNames.join("|")})>(.*?)<\\/(\\1)>`, "g");
|
|
17
|
-
const result = [];
|
|
18
|
-
let lastIndex = 0;
|
|
19
|
-
let match;
|
|
20
|
-
while ((match = regex.exec(input)) !== null) {
|
|
21
|
-
if (match.index > lastIndex) {
|
|
22
|
-
result.push(input.slice(lastIndex, match.index));
|
|
23
|
-
}
|
|
24
|
-
const [, tag, chunks] = match;
|
|
25
|
-
// Procesar recursivamente el contenido del tag
|
|
26
|
-
const processedChunks = processString(chunks);
|
|
27
|
-
const chunksAsString = processedChunks
|
|
28
|
-
.map((chunk) => (typeof chunk === "string" ? chunk : ""))
|
|
29
|
-
.join("");
|
|
30
|
-
result.push(tags[tag](chunksAsString));
|
|
31
|
-
lastIndex = match.index + match[0].length;
|
|
32
|
-
}
|
|
33
|
-
if (lastIndex < input.length)
|
|
34
|
-
result.push(input.slice(lastIndex));
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
return processString(str);
|
|
38
|
-
};
|
|
39
|
-
Object.assign(t, { rich });
|
|
40
|
-
return t;
|
|
41
|
-
};
|
|
42
|
-
}
|