astro-intl 2.0.3 → 2.2.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.
@@ -9,6 +9,9 @@ export function getTranslations(namespace) {
9
9
  const str = typeof value === "string" ? value : key;
10
10
  return interpolateValues(str, values);
11
11
  }
12
+ function raw(key) {
13
+ return getNestedValue(messages, key);
14
+ }
12
15
  const markup = function (key, options) {
13
16
  const isOptionsObject = "tags" in options && typeof options.tags === "object";
14
17
  const tags = isOptionsObject
@@ -28,6 +31,6 @@ export function getTranslations(namespace) {
28
31
  str = sanitizeHtml(str);
29
32
  return str;
30
33
  };
31
- Object.assign(t, { markup });
34
+ Object.assign(t, { markup, raw });
32
35
  return t;
33
36
  }
@@ -7,6 +7,10 @@ export type GetRequestConfigFn = (locale: string) => Promise<RequestConfig> | Re
7
7
  export type MessagesConfig = Record<string, Record<string, unknown> | (() => Promise<{
8
8
  default: Record<string, unknown>;
9
9
  } | Record<string, unknown>>)>;
10
+ export type MessagesDirConfig = {
11
+ /** Directory path containing locale JSON files (e.g., "./src/i18n/messages") */
12
+ dir: string;
13
+ };
10
14
  export type RoutesMap = {
11
15
  [routeKey: string]: {
12
16
  [locale: string]: string;
@@ -14,8 +18,14 @@ export type RoutesMap = {
14
18
  };
15
19
  export type ExtractParams<T extends string> = T extends `${string}[${infer P}]${infer Rest}` ? P | ExtractParams<Rest> : never;
16
20
  export type ParamsForRoute<Template extends string> = [ExtractParams<Template>] extends [never] ? Record<string, never> : Record<ExtractParams<Template>, string>;
21
+ export type FallbackRouteInfo = {
22
+ pattern: string;
23
+ pathname?: string;
24
+ locale: string;
25
+ };
17
26
  export type IntlConfig = {
18
27
  defaultLocale: string;
19
28
  locales: string[];
20
29
  routes?: RoutesMap;
30
+ fallbackRoutes?: FallbackRouteInfo[];
21
31
  };
package/package.json CHANGED
@@ -1,99 +1,102 @@
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
- }
1
+ {
2
+ "name": "astro-intl",
3
+ "version": "2.2.0",
4
+ "type": "module",
5
+ "description": "Sistema de internacionalización simple y type-safe para 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
+ "./components": {
60
+ "import": "./dist/components/AutoRedirect.astro"
61
+ }
62
+ },
63
+ "peerDependencies": {
64
+ "astro": "^4 || ^5 || ^6"
65
+ },
66
+ "peerDependenciesMeta": {
67
+ "react": {
68
+ "optional": true
69
+ },
70
+ "svelte": {
71
+ "optional": true
72
+ }
73
+ },
74
+ "repository": {
75
+ "type": "git",
76
+ "url": "https://github.com/ErickCSS/astro-intl"
77
+ },
78
+ "bugs": {
79
+ "url": "https://github.com/ErickCSS/astro-intl/issues"
80
+ },
81
+ "homepage": "https://github.com/ErickCSS/astro-intl#readme",
82
+ "publishConfig": {
83
+ "access": "public"
84
+ },
85
+ "devDependencies": {
86
+ "@eslint/js": "^9.39.4",
87
+ "@testing-library/jest-dom": "^6.9.1",
88
+ "@testing-library/react": "^16.3.2",
89
+ "@types/react": "^18.3.28",
90
+ "@vitest/ui": "^4.1.2",
91
+ "astro": "^6.1.2",
92
+ "eslint": "^9.39.4",
93
+ "happy-dom": "^20.8.9",
94
+ "prettier": "^3.8.1",
95
+ "react": "^19.2.4",
96
+ "react-dom": "^19.2.4",
97
+ "svelte": "^5.55.1",
98
+ "typescript": "^5.9.3",
99
+ "typescript-eslint": "^8.58.0",
100
+ "vitest": "^4.1.2"
101
+ }
102
+ }