@gravito/cosmos 1.0.0-alpha.5 → 1.0.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 +2 -2
- package/dist/index.js +4 -2
- package/package.json +4 -4
- package/src/I18nService.ts +1 -1
- package/src/index.ts +12 -4
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Lightweight Internationalization (i18n) Orbit for Gravito.
|
|
4
4
|
|
|
5
|
-
Provides simple JSON-based localization support for your Gravito application, with seamless integration into
|
|
5
|
+
Provides simple JSON-based localization support for your Gravito application, with seamless integration into Photon context.
|
|
6
6
|
|
|
7
7
|
## 📦 Installation
|
|
8
8
|
|
|
@@ -50,7 +50,7 @@ bun add @gravito/cosmos
|
|
|
50
50
|
|
|
51
51
|
## ✨ Features
|
|
52
52
|
|
|
53
|
-
- **Context Injection**: Automatically injects `t()` helper into
|
|
53
|
+
- **Context Injection**: Automatically injects `t()` helper into Photon context.
|
|
54
54
|
- **Parameter Replacement**: Supports `{key}` style parameter replacement.
|
|
55
55
|
- **Locale Detection**: Automatically detects locale from `Accept-Language` header or query parameter `?lang=`.
|
|
56
56
|
- **Fallback**: gracefully falls back to default locale if key is missing.
|
package/dist/index.js
CHANGED
|
@@ -146,7 +146,7 @@ async function loadTranslations(directory) {
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
// src/index.ts
|
|
149
|
-
class
|
|
149
|
+
class OrbitCosmos {
|
|
150
150
|
config;
|
|
151
151
|
constructor(config) {
|
|
152
152
|
this.config = config;
|
|
@@ -154,12 +154,14 @@ class I18nOrbit {
|
|
|
154
154
|
install(core) {
|
|
155
155
|
const i18nManager = new I18nManager(this.config);
|
|
156
156
|
core.adapter.use("*", localeMiddleware(i18nManager));
|
|
157
|
-
core.logger.info(`I18n
|
|
157
|
+
core.logger.info(`[OrbitCosmos] I18n initialized with locale: ${this.config.defaultLocale}`);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
+
var I18nOrbit = OrbitCosmos;
|
|
160
161
|
export {
|
|
161
162
|
localeMiddleware,
|
|
162
163
|
loadTranslations,
|
|
164
|
+
OrbitCosmos,
|
|
163
165
|
I18nOrbit,
|
|
164
166
|
I18nManager,
|
|
165
167
|
I18nInstance
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravito/cosmos",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"description": "Internationalization orbit for Gravito framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "bun build ./src/index.ts --outdir ./dist --target node --external @gravito/core --external
|
|
8
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target node --external @gravito/core --external @gravito/photon",
|
|
9
9
|
"test": "bun test"
|
|
10
10
|
},
|
|
11
11
|
"keywords": [
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"author": "Carl Lee <carllee0520@gmail.com>",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"gravito-core": "1.0.0-beta.
|
|
21
|
-
"
|
|
20
|
+
"gravito-core": "1.0.0-beta.6",
|
|
21
|
+
"@gravito/photon": "1.0.0-beta.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"bun-types": "latest"
|
package/src/I18nService.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GravitoOrbit, PlanetCore } from 'gravito-core'
|
|
1
|
+
import type { GravitoMiddleware, GravitoOrbit, PlanetCore } from 'gravito-core'
|
|
2
2
|
import { type I18nConfig, I18nManager, type I18nService, localeMiddleware } from './I18nService'
|
|
3
3
|
|
|
4
4
|
declare module 'gravito-core' {
|
|
@@ -7,7 +7,12 @@ declare module 'gravito-core' {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* OrbitCosmos - Internationalization Orbit
|
|
12
|
+
*
|
|
13
|
+
* Provides i18n functionality for Gravito applications.
|
|
14
|
+
*/
|
|
15
|
+
export class OrbitCosmos implements GravitoOrbit {
|
|
11
16
|
constructor(private config: I18nConfig) {}
|
|
12
17
|
|
|
13
18
|
install(core: PlanetCore): void {
|
|
@@ -18,11 +23,14 @@ export class I18nOrbit implements GravitoOrbit {
|
|
|
18
23
|
|
|
19
24
|
// Inject locale middleware into every request
|
|
20
25
|
// This middleware handles cloning the i18n instance per request
|
|
21
|
-
core.adapter.use('*', localeMiddleware(i18nManager) as
|
|
26
|
+
core.adapter.use('*', localeMiddleware(i18nManager) as GravitoMiddleware)
|
|
22
27
|
|
|
23
|
-
core.logger.info(`I18n
|
|
28
|
+
core.logger.info(`[OrbitCosmos] I18n initialized with locale: ${this.config.defaultLocale}`)
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
31
|
|
|
32
|
+
/** @deprecated Use OrbitCosmos instead */
|
|
33
|
+
export const I18nOrbit = OrbitCosmos
|
|
34
|
+
|
|
27
35
|
export * from './I18nService'
|
|
28
36
|
export * from './loader'
|