@rivinia/i18n 0.0.0-stage → 0.1.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.
- package/README.md +95 -2
- package/fesm2022/rivinia-i18n-http-loader.impl-DVlKmSDL.mjs +15 -0
- package/fesm2022/rivinia-i18n-http-loader.impl-DVlKmSDL.mjs.map +1 -0
- package/fesm2022/rivinia-i18n-json-loader.impl-CGzkWfF_.mjs +16 -0
- package/fesm2022/rivinia-i18n-json-loader.impl-CGzkWfF_.mjs.map +1 -0
- package/fesm2022/rivinia-i18n-remote-loader.impl-XKqdLHoJ.mjs +15 -0
- package/fesm2022/rivinia-i18n-remote-loader.impl-XKqdLHoJ.mjs.map +1 -0
- package/fesm2022/rivinia-i18n.mjs +543 -0
- package/fesm2022/rivinia-i18n.mjs.map +1 -0
- package/package.json +31 -3
- package/schematics/collection.json +10 -0
- package/schematics/ng-add/index.cjs +112 -0
- package/schematics/ng-add/schema.json +30 -0
- package/types/rivinia-i18n.d.ts +234 -0
package/README.md
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @rivinia/i18n
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@rivinia/i18n)
|
|
4
|
+
[](https://www.npmjs.com/package/@rivinia/i18n)
|
|
5
|
+
|
|
6
|
+
Headless language manager for Angular 22+. Signals, RTL/LTR, lazy loaders,
|
|
7
|
+
ICU plurals (all six Arabic forms), browser detection, Intl formatting —
|
|
8
|
+
zero DOM opinions beyond `<html dir/lang>`, zero styling.
|
|
9
|
+
|
|
10
|
+
- Version: **0.1.0**
|
|
11
|
+
- Requires: **Angular `^22.0.0`**, `tslib`
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @rivinia/i18n
|
|
17
|
+
ng add @rivinia/i18n # asks default language + browser detection, wires an ar/en starter
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Dictionaries by convention (no config needed)
|
|
21
|
+
|
|
22
|
+
Key-based `translate('booking.seats')` works out of the box with the conventional
|
|
23
|
+
layout — the default loader fetches `assets/i18n/{language}.json`
|
|
24
|
+
(`assets/i18n/ar.json`, `assets/i18n/en.json`, …). Override only when you differ:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
// src/assets/i18n/ar.json
|
|
28
|
+
{ "booking": { "seats": "{count, plural, zero {لا مقاعد} one {مقعد واحد} other {# مقاعد}}" } }
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
// custom path / HTTP endpoint / in-memory (first truth wins):
|
|
33
|
+
provideRiviniaI18n({ loader: jsonLoader({ path: '/my-i18n' }), ... });
|
|
34
|
+
provideRiviniaI18n({ loader: httpLoader({ endpoint: 'https://api.example.com/i18n' }), ... });
|
|
35
|
+
// inline-only apps (zero network): loader: customLoader(async () => ({}))
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Loaders code-split: fetch implementations load on first use only.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
// app.config.ts
|
|
42
|
+
import { provideRiviniaI18n } from '@rivinia/i18n';
|
|
43
|
+
|
|
44
|
+
providers: [
|
|
45
|
+
provideRiviniaI18n({
|
|
46
|
+
defaultLanguage: 'ar',
|
|
47
|
+
languages: [
|
|
48
|
+
{ id: 'ar', nativeName: 'العربية', dir: 'rtl' },
|
|
49
|
+
{ id: 'en', nativeName: 'English', dir: 'ltr' },
|
|
50
|
+
],
|
|
51
|
+
}),
|
|
52
|
+
];
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quick start
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
export class Header {
|
|
59
|
+
i18n = injectRiviniaI18n();
|
|
60
|
+
save = () => this.i18n.translate({ ar: 'حفظ', en: 'Save' });
|
|
61
|
+
seats = (n: number) => this.i18n.translate('booking.seats', { count: n });
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
// assets/i18n/en.json
|
|
67
|
+
{ "booking": { "seats": "{count, plural, one {# seat} other {# seats}}" } }
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```html
|
|
71
|
+
<p>{{ i18n.translate({ ar: 'مرحبا', en: 'Hello' }) }}</p>
|
|
72
|
+
<p>{{ 'booking.seats' | rTranslate:{ count: seats() } }}</p>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## API
|
|
76
|
+
|
|
77
|
+
| Export | Kind | Purpose |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| `provideRiviniaI18n(config)` | provider | languages, default, storage, loader, `detectBrowser?` (off), `switchStrategy?` |
|
|
80
|
+
| `RiviniaI18n` | `@Service()` | signals + `translate/setLanguage(toggle/next/previous)/loadTranslations/formatNumber/formatDate` |
|
|
81
|
+
| `injectRiviniaI18n()` | function | shorthand for `inject(RiviniaI18n)` |
|
|
82
|
+
| `jsonLoader/httpLoader/remoteLoader/customLoader` | loaders | lazy code-split dictionaries (fetch, no HttpClient) |
|
|
83
|
+
| `formatIcu(template, params, locale)` | util | ICU subset: plural/select/`#`/nesting via native `Intl.PluralRules` |
|
|
84
|
+
| `detectBrowserLanguage(ids, langs)` | util | priority match + base-tag fallback (`ar-EG` → `ar`), pure/testable |
|
|
85
|
+
| `RTranslatePipe` | pipe | `rTranslate` (impure by necessity — prefer `translate()` in code for lists) |
|
|
86
|
+
| types | types | `RiviniaI18nConfig`, `Language`, `Translation`, `LoaderDescriptor`, … |
|
|
87
|
+
|
|
88
|
+
ICU subset is deliberately small (`plural`/`select` only) — full ICU belongs to
|
|
89
|
+
FormatJS, not to a 10 kB core. Malformed templates render raw, never throw.
|
|
90
|
+
Stored preference always beats browser detection; detection runs only when
|
|
91
|
+
nothing is stored. `switchStrategy: 'preload-first'` (or `setLanguageAsync`)
|
|
92
|
+
avoids raw-key flashes on route switches.
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var HttpLoader = class {
|
|
2
|
+
_options;
|
|
3
|
+
constructor(_options) {
|
|
4
|
+
this._options = _options;
|
|
5
|
+
}
|
|
6
|
+
async load(language) {
|
|
7
|
+
const url = this._options.buildUrl?.(language) ?? `${this._options.endpoint}/${language}`;
|
|
8
|
+
const response = await fetch(url, { method: this._options.method ?? "GET" });
|
|
9
|
+
if (!response.ok) throw new Error(`[rivinia/i18n] Failed to load "${url}": ${response.statusText}`);
|
|
10
|
+
return response.json();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export { HttpLoader };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=rivinia-i18n-http-loader.impl-DVlKmSDL.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rivinia-i18n-http-loader.impl-DVlKmSDL.mjs","names":[],"sources":["../../../projects/i18n/src/lib/http-loader.impl.ts"],"sourcesContent":["import type { HttpLoaderOptions, TranslationLoader } from './loaders';\n\nexport class HttpLoader<L extends string = string> implements TranslationLoader<L> {\n constructor(private readonly _options: HttpLoaderOptions) {}\n\n async load(language: L): Promise<Record<string, unknown>> {\n const url = this._options.buildUrl?.(language) ?? `${this._options.endpoint}/${language}`;\n const response = await fetch(url, { method: this._options.method ?? 'GET' });\n if (!response.ok) {\n throw new Error(`[rivinia/i18n] Failed to load \"${url}\": ${response.statusText}`);\n }\n return response.json();\n }\n}\n"],"mappings":"AAEA,IAAa,aAAb,MAAuB;CACQ;CAA7B,YAA6B,UAA2B;EAA3B,KAAA,WAAA;CAA8B;CAE3D,MAAM,KAAK,UAAW;EACpB,MAAM,MAAM,KAAK,SAAS,WAAW,QAAQ,KAAK,GAAG,KAAK,SAAS,SAAQ,GAAI;EAC/E,MAAM,WAAW,MAAM,MAAM,KAAK,EAAE,QAAQ,KAAK,SAAS,UAAU,MAAK,CAAE;EAC3E,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,MAAM,kCAAkC,IAAG,KAAM,SAAS,YAAY;EAElF,OAAO,SAAS,KAAI;CACtB;AACD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const DEFAULT_BASE_PATH = "assets/i18n";
|
|
2
|
+
var JsonLoader = class {
|
|
3
|
+
_options;
|
|
4
|
+
constructor(_options) {
|
|
5
|
+
this._options = _options;
|
|
6
|
+
}
|
|
7
|
+
async load(language) {
|
|
8
|
+
const url = `${this._options?.path ?? DEFAULT_BASE_PATH}/${language}.json`;
|
|
9
|
+
const response = await fetch(url);
|
|
10
|
+
if (!response.ok) throw new Error(`[rivinia/i18n] Failed to load "${url}": ${response.statusText}`);
|
|
11
|
+
return response.json();
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export { JsonLoader };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=rivinia-i18n-json-loader.impl-CGzkWfF_.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rivinia-i18n-json-loader.impl-CGzkWfF_.mjs","names":[],"sources":["../../../projects/i18n/src/lib/json-loader.impl.ts"],"sourcesContent":["import type { TranslationLoader } from './loaders';\n\nconst DEFAULT_BASE_PATH = 'assets/i18n';\n\nexport class JsonLoader<L extends string = string> implements TranslationLoader<L> {\n constructor(private readonly _options?: { path?: string }) {}\n\n async load(language: L): Promise<Record<string, unknown>> {\n const basePath = this._options?.path ?? DEFAULT_BASE_PATH;\n const url = `${basePath}/${language}.json`;\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`[rivinia/i18n] Failed to load \"${url}\": ${response.statusText}`);\n }\n return response.json();\n }\n}\n"],"mappings":"AAEA,MAAM,oBAAoB;AAE1B,IAAa,aAAb,MAAuB;CACQ;CAA7B,YAA6B,UAA4B;EAA5B,KAAA,WAAA;CAA+B;CAE5D,MAAM,KAAK,UAAW;EAEpB,MAAM,MAAM,GADK,KAAK,UAAU,QAAQ,kBACjB,GAAI,SAAQ;EACnC,MAAM,WAAW,MAAM,MAAM,GAAG;EAChC,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,MAAM,kCAAkC,IAAG,KAAM,SAAS,YAAY;EAElF,OAAO,SAAS,KAAI;CACtB;AACD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var RemoteLoader = class {
|
|
2
|
+
_options;
|
|
3
|
+
constructor(_options) {
|
|
4
|
+
this._options = _options;
|
|
5
|
+
}
|
|
6
|
+
async load(language) {
|
|
7
|
+
const url = this._options.url(language);
|
|
8
|
+
const response = await fetch(url, { headers: this._options.headers });
|
|
9
|
+
if (!response.ok) throw new Error(`[rivinia/i18n] Failed to load "${url}": ${response.statusText}`);
|
|
10
|
+
return response.json();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export { RemoteLoader };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=rivinia-i18n-remote-loader.impl-XKqdLHoJ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rivinia-i18n-remote-loader.impl-XKqdLHoJ.mjs","names":[],"sources":["../../../projects/i18n/src/lib/remote-loader.impl.ts"],"sourcesContent":["import type { RemoteLoaderOptions, TranslationLoader } from './loaders';\n\nexport class RemoteLoader<L extends string = string> implements TranslationLoader<L> {\n constructor(private readonly _options: RemoteLoaderOptions) {}\n\n async load(language: L): Promise<Record<string, unknown>> {\n const url = this._options.url(language);\n const response = await fetch(url, { headers: this._options.headers });\n if (!response.ok) {\n throw new Error(`[rivinia/i18n] Failed to load \"${url}\": ${response.statusText}`);\n }\n return response.json();\n }\n}\n"],"mappings":"AAEA,IAAa,eAAb,MAAyB;CACM;CAA7B,YAA6B,UAA6B;EAA7B,KAAA,WAAA;CAAgC;CAE7D,MAAM,KAAK,UAAW;EACpB,MAAM,MAAM,KAAK,SAAS,IAAI,QAAQ;EACtC,MAAM,WAAW,MAAM,MAAM,KAAK,EAAE,SAAS,KAAK,SAAS,QAAO,CAAE;EACpE,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,MAAM,kCAAkC,IAAG,KAAM,SAAS,YAAY;EAElF,OAAO,SAAS,KAAI;CACtB;AACD"}
|
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { InjectionToken, Pipe, Service, computed, effect, inject, makeEnvironmentProviders, signal } from "@angular/core";
|
|
3
|
+
function jsonLoader(options) {
|
|
4
|
+
return { async resolve() {
|
|
5
|
+
const { JsonLoader } = await import("./rivinia-i18n-json-loader.impl-CGzkWfF_.mjs");
|
|
6
|
+
return new JsonLoader(options);
|
|
7
|
+
} };
|
|
8
|
+
}
|
|
9
|
+
function httpLoader(options) {
|
|
10
|
+
return { async resolve() {
|
|
11
|
+
const { HttpLoader } = await import("./rivinia-i18n-http-loader.impl-DVlKmSDL.mjs");
|
|
12
|
+
return new HttpLoader(options);
|
|
13
|
+
} };
|
|
14
|
+
}
|
|
15
|
+
function remoteLoader(options) {
|
|
16
|
+
return { async resolve() {
|
|
17
|
+
const { RemoteLoader } = await import("./rivinia-i18n-remote-loader.impl-XKqdLHoJ.mjs");
|
|
18
|
+
return new RemoteLoader(options);
|
|
19
|
+
} };
|
|
20
|
+
}
|
|
21
|
+
function customLoader(load) {
|
|
22
|
+
return { async resolve() {
|
|
23
|
+
return { load };
|
|
24
|
+
} };
|
|
25
|
+
}
|
|
26
|
+
function getStorage(strategy) {
|
|
27
|
+
if (strategy === "none") return null;
|
|
28
|
+
if (typeof window === "undefined") return null;
|
|
29
|
+
try {
|
|
30
|
+
return strategy === "session" ? window.sessionStorage : window.localStorage;
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function safeGetItem(key, strategy) {
|
|
36
|
+
const storage = getStorage(strategy);
|
|
37
|
+
if (!storage) return null;
|
|
38
|
+
try {
|
|
39
|
+
return storage.getItem(key);
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function safeSetItem(key, value, strategy) {
|
|
45
|
+
const storage = getStorage(strategy);
|
|
46
|
+
if (!storage) return;
|
|
47
|
+
try {
|
|
48
|
+
storage.setItem(key, value);
|
|
49
|
+
} catch {}
|
|
50
|
+
}
|
|
51
|
+
function detectBrowserLanguage(supportedIds, browserLanguages) {
|
|
52
|
+
if (!browserLanguages || browserLanguages.length === 0) return null;
|
|
53
|
+
const supported = supportedIds.map((id) => id.toLowerCase());
|
|
54
|
+
for (const raw of browserLanguages) {
|
|
55
|
+
const tag = raw.trim().toLowerCase();
|
|
56
|
+
if (!tag) continue;
|
|
57
|
+
const exact = supported.indexOf(tag);
|
|
58
|
+
if (exact !== -1) return supportedIds[exact];
|
|
59
|
+
}
|
|
60
|
+
for (const raw of browserLanguages) {
|
|
61
|
+
const base = raw.trim().toLowerCase().split(/[-_]/)[0];
|
|
62
|
+
if (!base) continue;
|
|
63
|
+
const hit = supported.indexOf(base);
|
|
64
|
+
if (hit !== -1) return supportedIds[hit];
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
function browserLanguages() {
|
|
69
|
+
if (typeof window === "undefined" || typeof navigator === "undefined") return void 0;
|
|
70
|
+
try {
|
|
71
|
+
if (Array.isArray(navigator.languages) && navigator.languages.length > 0) return [...navigator.languages];
|
|
72
|
+
return typeof navigator.language === "string" ? [navigator.language] : void 0;
|
|
73
|
+
} catch {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function formatIcu(template, params, locale) {
|
|
78
|
+
return parseMessage(template, 0, template.length, params, locale, null).text;
|
|
79
|
+
}
|
|
80
|
+
function parseMessage(src, start, end, params, locale, pluralValue) {
|
|
81
|
+
let out = "";
|
|
82
|
+
let i = start;
|
|
83
|
+
while (i < end) {
|
|
84
|
+
const ch = src[i];
|
|
85
|
+
if (ch === "{") {
|
|
86
|
+
const arg = parseArgument(src, i, end, params, locale, pluralValue);
|
|
87
|
+
if (!arg.ok) return {
|
|
88
|
+
text: out + src.slice(i, end),
|
|
89
|
+
next: end,
|
|
90
|
+
ok: true
|
|
91
|
+
};
|
|
92
|
+
out += arg.text;
|
|
93
|
+
i = arg.next;
|
|
94
|
+
} else if (ch === "}") return {
|
|
95
|
+
text: out,
|
|
96
|
+
next: i,
|
|
97
|
+
ok: true
|
|
98
|
+
};
|
|
99
|
+
else if (ch === "#" && pluralValue !== null) {
|
|
100
|
+
out += String(pluralValue);
|
|
101
|
+
i++;
|
|
102
|
+
} else {
|
|
103
|
+
out += ch;
|
|
104
|
+
i++;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
text: out,
|
|
109
|
+
next: i,
|
|
110
|
+
ok: true
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function parseArgument(src, start, end, params, locale, outerPlural) {
|
|
114
|
+
let i = skipSpaces(src, start + 1, end);
|
|
115
|
+
const name = readWord(src, i, end);
|
|
116
|
+
i = skipSpaces(src, name.next, end);
|
|
117
|
+
if (i >= end) return {
|
|
118
|
+
text: src.slice(start, end),
|
|
119
|
+
next: end,
|
|
120
|
+
ok: true
|
|
121
|
+
};
|
|
122
|
+
if (src[i] === "}") {
|
|
123
|
+
const value = params[name.word];
|
|
124
|
+
return {
|
|
125
|
+
text: value === void 0 || value === null || name.word === "" ? src.slice(start, i + 1) : String(value),
|
|
126
|
+
next: i + 1,
|
|
127
|
+
ok: true
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (src[i] !== "," || name.word === "") return {
|
|
131
|
+
text: src.slice(start, end),
|
|
132
|
+
next: end,
|
|
133
|
+
ok: true
|
|
134
|
+
};
|
|
135
|
+
i = skipSpaces(src, i + 1, end);
|
|
136
|
+
const type = readWord(src, i, end);
|
|
137
|
+
i = skipSpaces(src, type.next, end);
|
|
138
|
+
if (i >= end || src[i] !== ",") return {
|
|
139
|
+
text: src.slice(start, end),
|
|
140
|
+
next: end,
|
|
141
|
+
ok: true
|
|
142
|
+
};
|
|
143
|
+
if (type.word !== "plural" && type.word !== "select") return {
|
|
144
|
+
text: src.slice(start, end),
|
|
145
|
+
next: end,
|
|
146
|
+
ok: true
|
|
147
|
+
};
|
|
148
|
+
i++;
|
|
149
|
+
const numeric = type.word === "plural" ? toFiniteNumber(params[name.word]) : null;
|
|
150
|
+
const branches = /* @__PURE__ */ new Map();
|
|
151
|
+
i = skipSpaces(src, i, end);
|
|
152
|
+
let closed = false;
|
|
153
|
+
while (i < end) {
|
|
154
|
+
i = skipSpaces(src, i, end);
|
|
155
|
+
if (i < end && src[i] === "}") {
|
|
156
|
+
closed = true;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
const sel = readSelector(src, i, end);
|
|
160
|
+
if (sel.selector === null) return {
|
|
161
|
+
text: src.slice(start, end),
|
|
162
|
+
next: end,
|
|
163
|
+
ok: true
|
|
164
|
+
};
|
|
165
|
+
i = skipSpaces(src, sel.next, end);
|
|
166
|
+
if (i >= end || src[i] !== "{") return {
|
|
167
|
+
text: src.slice(start, end),
|
|
168
|
+
next: end,
|
|
169
|
+
ok: true
|
|
170
|
+
};
|
|
171
|
+
const body = parseMessage(src, i + 1, end, params, locale, numeric ?? outerPlural);
|
|
172
|
+
branches.set(sel.selector, body.text);
|
|
173
|
+
i = body.next + 1;
|
|
174
|
+
}
|
|
175
|
+
if (!closed) return {
|
|
176
|
+
text: src.slice(start, end),
|
|
177
|
+
next: end,
|
|
178
|
+
ok: true
|
|
179
|
+
};
|
|
180
|
+
if (type.word === "select") {
|
|
181
|
+
const raw = params[name.word];
|
|
182
|
+
const key = raw === void 0 || raw === null ? "" : String(raw);
|
|
183
|
+
return {
|
|
184
|
+
text: branches.get(key) ?? branches.get("other") ?? "",
|
|
185
|
+
next: i + 1,
|
|
186
|
+
ok: true
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if (numeric === null) return {
|
|
190
|
+
text: branches.get("other") ?? "",
|
|
191
|
+
next: i + 1,
|
|
192
|
+
ok: true
|
|
193
|
+
};
|
|
194
|
+
const exact = branches.get(`=${numeric}`);
|
|
195
|
+
if (exact !== void 0) return {
|
|
196
|
+
text: exact,
|
|
197
|
+
next: i + 1,
|
|
198
|
+
ok: true
|
|
199
|
+
};
|
|
200
|
+
let category;
|
|
201
|
+
try {
|
|
202
|
+
category = new Intl.PluralRules(locale).select(numeric);
|
|
203
|
+
} catch {
|
|
204
|
+
category = "other";
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
text: branches.get(category) ?? branches.get("other") ?? "",
|
|
208
|
+
next: i + 1,
|
|
209
|
+
ok: true
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function toFiniteNumber(value) {
|
|
213
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
214
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
215
|
+
const n = Number(value);
|
|
216
|
+
return Number.isFinite(n) ? n : null;
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
function skipSpaces(src, i, end) {
|
|
221
|
+
while (i < end && /\s/.test(src[i])) i++;
|
|
222
|
+
return i;
|
|
223
|
+
}
|
|
224
|
+
function readWord(src, i, end) {
|
|
225
|
+
const start = skipSpaces(src, i, end);
|
|
226
|
+
let j = start;
|
|
227
|
+
while (j < end && /[^\s,}]+/.test(src[j])) j++;
|
|
228
|
+
return {
|
|
229
|
+
word: src.slice(start, j),
|
|
230
|
+
next: j
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function readSelector(src, i, end) {
|
|
234
|
+
i = skipSpaces(src, i, end);
|
|
235
|
+
if (i < end && src[i] === "=") {
|
|
236
|
+
let j = i + 1;
|
|
237
|
+
if (j < end && src[j] === "-") j++;
|
|
238
|
+
const digits = j;
|
|
239
|
+
while (j < end && /[0-9]/.test(src[j])) j++;
|
|
240
|
+
if (j < end && src[j] === "." && j + 1 < end && /[0-9]/.test(src[j + 1])) {
|
|
241
|
+
j++;
|
|
242
|
+
while (j < end && /[0-9]/.test(src[j])) j++;
|
|
243
|
+
}
|
|
244
|
+
if (j === digits) return {
|
|
245
|
+
selector: null,
|
|
246
|
+
next: i
|
|
247
|
+
};
|
|
248
|
+
return {
|
|
249
|
+
selector: src.slice(i, j),
|
|
250
|
+
next: j
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
const word = readWord(src, i, end);
|
|
254
|
+
if (!word.word) return {
|
|
255
|
+
selector: null,
|
|
256
|
+
next: i
|
|
257
|
+
};
|
|
258
|
+
return {
|
|
259
|
+
selector: word.word,
|
|
260
|
+
next: word.next
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
const RIVINIA_I18N_CONFIG = new InjectionToken("RIVINIA_I18N_CONFIG");
|
|
264
|
+
var ViewTransitionService = class ViewTransitionService {
|
|
265
|
+
_supported = typeof document !== "undefined" && typeof document.startViewTransition === "function";
|
|
266
|
+
run(callback) {
|
|
267
|
+
if (this._supported) document.startViewTransition(callback);
|
|
268
|
+
else callback();
|
|
269
|
+
}
|
|
270
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
271
|
+
minVersion: "12.0.0",
|
|
272
|
+
version: "22.2.2",
|
|
273
|
+
ngImport: i0,
|
|
274
|
+
type: ViewTransitionService,
|
|
275
|
+
deps: [],
|
|
276
|
+
target: i0.ɵɵFactoryTarget.Service
|
|
277
|
+
});
|
|
278
|
+
static ɵprov = i0.ɵɵngDeclareService({
|
|
279
|
+
minVersion: "22.0.0",
|
|
280
|
+
version: "22.2.2",
|
|
281
|
+
ngImport: i0,
|
|
282
|
+
type: ViewTransitionService
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
286
|
+
minVersion: "12.0.0",
|
|
287
|
+
version: "22.2.2",
|
|
288
|
+
ngImport: i0,
|
|
289
|
+
type: ViewTransitionService,
|
|
290
|
+
decorators: [{ type: Service }]
|
|
291
|
+
});
|
|
292
|
+
var RiviniaI18n = class RiviniaI18n {
|
|
293
|
+
_config = inject(RIVINIA_I18N_CONFIG);
|
|
294
|
+
_viewTransition = inject(ViewTransitionService, { optional: true });
|
|
295
|
+
_storageKey = this._config.storageKey ?? "rivinia.i18n.language";
|
|
296
|
+
_storageStrategy = this._config.storageStrategy ?? "local";
|
|
297
|
+
_autoApplyDirection = this._config.autoApplyDirection ?? true;
|
|
298
|
+
_currentLanguageId = signal(this._resolveInitialLanguage(), ...ngDevMode ? [{ debugName: "_currentLanguageId" }] : /* istanbul ignore next */ []);
|
|
299
|
+
_languages = signal(this._config.languages, ...ngDevMode ? [{ debugName: "_languages" }] : /* istanbul ignore next */ []);
|
|
300
|
+
_loadedTranslations = signal({}, ...ngDevMode ? [{ debugName: "_loadedTranslations" }] : /* istanbul ignore next */ []);
|
|
301
|
+
_getLoader = this._config.loader?.resolve ?? (() => jsonLoader().resolve());
|
|
302
|
+
_resolvedLoader = null;
|
|
303
|
+
_translationsCache = /* @__PURE__ */ new Map();
|
|
304
|
+
_inflight = /* @__PURE__ */ new Map();
|
|
305
|
+
_requestToken = 0;
|
|
306
|
+
_applyCount = 0;
|
|
307
|
+
languageChanged = computed(() => this._currentLanguageId(), ...ngDevMode ? [{ debugName: "languageChanged" }] : /* istanbul ignore next */ []);
|
|
308
|
+
languages = this._languages.asReadonly();
|
|
309
|
+
currentLanguage = this._currentLanguageId.asReadonly();
|
|
310
|
+
currentLanguageObject = computed(() => {
|
|
311
|
+
const id = this._currentLanguageId();
|
|
312
|
+
return this._languages().find((l) => l.id === id) ?? this._languages()[0];
|
|
313
|
+
}, ...ngDevMode ? [{ debugName: "currentLanguageObject" }] : /* istanbul ignore next */ []);
|
|
314
|
+
dir = computed(() => this.currentLanguageObject().dir, ...ngDevMode ? [{ debugName: "dir" }] : /* istanbul ignore next */ []);
|
|
315
|
+
isRtl = computed(() => this.dir() === "rtl", ...ngDevMode ? [{ debugName: "isRtl" }] : /* istanbul ignore next */ []);
|
|
316
|
+
_loadingState = signal("idle", ...ngDevMode ? [{ debugName: "_loadingState" }] : /* istanbul ignore next */ []);
|
|
317
|
+
_loadingError = signal(null, ...ngDevMode ? [{ debugName: "_loadingError" }] : /* istanbul ignore next */ []);
|
|
318
|
+
loadingState = this._loadingState.asReadonly();
|
|
319
|
+
loadingError = this._loadingError.asReadonly();
|
|
320
|
+
isLoading = computed(() => this._loadingState() === "loading", ...ngDevMode ? [{ debugName: "isLoading" }] : /* istanbul ignore next */ []);
|
|
321
|
+
constructor() {
|
|
322
|
+
if (this._config.languages.length === 0) throw new Error("[rivinia/i18n] At least one language must be provided in the languages array.");
|
|
323
|
+
if (!this._config.languages.some((l) => l.id === this._config.defaultLanguage)) throw new Error(`[rivinia/i18n] defaultLanguage "${this._config.defaultLanguage}" must be one of the configured language IDs.`);
|
|
324
|
+
effect(() => {
|
|
325
|
+
const id = this._currentLanguageId();
|
|
326
|
+
safeSetItem(this._storageKey, id, this._storageStrategy);
|
|
327
|
+
});
|
|
328
|
+
if (this._autoApplyDirection) effect(() => {
|
|
329
|
+
if (typeof document === "undefined") return;
|
|
330
|
+
const lang = this.currentLanguageObject();
|
|
331
|
+
document.documentElement.dir = lang.dir;
|
|
332
|
+
document.documentElement.lang = lang.id;
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
getLanguage(id) {
|
|
336
|
+
return this._languages().find((l) => l.id === id);
|
|
337
|
+
}
|
|
338
|
+
translate(keyOrTranslations, defaultValueOrParams, maybeParams) {
|
|
339
|
+
if (typeof keyOrTranslations === "string") {
|
|
340
|
+
const { defaultValue, params } = normalizeKeyArgs(defaultValueOrParams, maybeParams);
|
|
341
|
+
const loaded = this._loadedTranslations();
|
|
342
|
+
const resolved = this._resolveKey(loaded, keyOrTranslations);
|
|
343
|
+
if (resolved !== void 0) return this.render(resolved, params);
|
|
344
|
+
const fallback = defaultValue ?? keyOrTranslations;
|
|
345
|
+
return params ? this.render(fallback, params) : fallback;
|
|
346
|
+
}
|
|
347
|
+
return keyOrTranslations[this._currentLanguageId()] ?? Object.values(keyOrTranslations)[0] ?? "";
|
|
348
|
+
}
|
|
349
|
+
loadedTranslations = this._loadedTranslations.asReadonly();
|
|
350
|
+
async loadTranslations(languageId, opts) {
|
|
351
|
+
return this._loadTranslations(languageId, opts);
|
|
352
|
+
}
|
|
353
|
+
toggle() {
|
|
354
|
+
const langs = this._languages();
|
|
355
|
+
if (langs.length < 2) return;
|
|
356
|
+
const newId = this._currentLanguageId() === langs[0].id ? langs[1].id : langs[0].id;
|
|
357
|
+
this.applyLanguage(newId);
|
|
358
|
+
}
|
|
359
|
+
next() {
|
|
360
|
+
const langs = this._languages();
|
|
361
|
+
if (langs.length < 2) return;
|
|
362
|
+
const nextIdx = (langs.findIndex((l) => l.id === this._currentLanguageId()) + 1) % langs.length;
|
|
363
|
+
this.applyLanguage(langs[nextIdx].id);
|
|
364
|
+
}
|
|
365
|
+
previous() {
|
|
366
|
+
const langs = this._languages();
|
|
367
|
+
if (langs.length < 2) return;
|
|
368
|
+
const prevIdx = (langs.findIndex((l) => l.id === this._currentLanguageId()) - 1 + langs.length) % langs.length;
|
|
369
|
+
this.applyLanguage(langs[prevIdx].id);
|
|
370
|
+
}
|
|
371
|
+
setLanguage(id) {
|
|
372
|
+
if (this._config.switchStrategy === "preload-first") {
|
|
373
|
+
this.setLanguageAsync(id);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
this.applyLanguage(id);
|
|
377
|
+
}
|
|
378
|
+
async setLanguageAsync(id) {
|
|
379
|
+
if (id === this._currentLanguageId()) return;
|
|
380
|
+
if (!this._languages().some((l) => l.id === id)) return;
|
|
381
|
+
await this._loadTranslations(id, { silent: true });
|
|
382
|
+
this.applyLanguage(id);
|
|
383
|
+
}
|
|
384
|
+
formatNumber(value, options) {
|
|
385
|
+
return new Intl.NumberFormat(this._currentLanguageId(), options).format(value);
|
|
386
|
+
}
|
|
387
|
+
formatDate(value, options) {
|
|
388
|
+
return new Intl.DateTimeFormat(this._currentLanguageId(), options).format(value);
|
|
389
|
+
}
|
|
390
|
+
applyLanguage(id, opts) {
|
|
391
|
+
if (id === this._currentLanguageId()) return;
|
|
392
|
+
const lang = this._languages().find((l) => l.id === id);
|
|
393
|
+
if (!lang) return;
|
|
394
|
+
this._applyCount++;
|
|
395
|
+
const apply = () => this._currentLanguageId.set(id);
|
|
396
|
+
const vt = this._config.viewTransition;
|
|
397
|
+
if (vt?.enabled && (!vt.skipInitialTransition || this._applyCount > 1) && this._viewTransition != null) {
|
|
398
|
+
vt.onViewTransitionCreated?.({
|
|
399
|
+
language: id,
|
|
400
|
+
direction: lang.dir
|
|
401
|
+
});
|
|
402
|
+
this._viewTransition.run(apply);
|
|
403
|
+
} else apply();
|
|
404
|
+
if (!opts?.skipLoad) this._loadTranslations(id);
|
|
405
|
+
}
|
|
406
|
+
render(template, params) {
|
|
407
|
+
if (!params) return template;
|
|
408
|
+
if (!template.includes("{")) return template;
|
|
409
|
+
try {
|
|
410
|
+
return formatIcu(template, params, this._currentLanguageId());
|
|
411
|
+
} catch {
|
|
412
|
+
return template;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
async _loadTranslations(languageId, opts) {
|
|
416
|
+
const cached = this._translationsCache.get(languageId);
|
|
417
|
+
if (cached) {
|
|
418
|
+
if (!opts?.silent) this._loadedTranslations.set(cached);
|
|
419
|
+
return cached;
|
|
420
|
+
}
|
|
421
|
+
const inflight = this._inflight.get(languageId);
|
|
422
|
+
if (inflight) return inflight;
|
|
423
|
+
const myToken = ++this._requestToken;
|
|
424
|
+
this._loadingState.set("loading");
|
|
425
|
+
const task = (async () => {
|
|
426
|
+
try {
|
|
427
|
+
if (!this._resolvedLoader) this._resolvedLoader = await this._getLoader();
|
|
428
|
+
const translations = await this._resolvedLoader.load(languageId);
|
|
429
|
+
this._translationsCache.set(languageId, translations);
|
|
430
|
+
if (myToken === this._requestToken && !opts?.silent) {
|
|
431
|
+
this._loadedTranslations.set(translations);
|
|
432
|
+
this._loadingError.set(null);
|
|
433
|
+
this._loadingState.set("idle");
|
|
434
|
+
}
|
|
435
|
+
return translations;
|
|
436
|
+
} catch (error) {
|
|
437
|
+
if (myToken === this._requestToken) {
|
|
438
|
+
this._loadingError.set(error);
|
|
439
|
+
this._loadingState.set("error");
|
|
440
|
+
}
|
|
441
|
+
this._config.onLoadError?.(languageId, error);
|
|
442
|
+
return {};
|
|
443
|
+
} finally {
|
|
444
|
+
this._inflight.delete(languageId);
|
|
445
|
+
if (this._inflight.size === 0 && this._loadingState() === "loading") this._loadingState.set("idle");
|
|
446
|
+
}
|
|
447
|
+
})();
|
|
448
|
+
this._inflight.set(languageId, task);
|
|
449
|
+
return task;
|
|
450
|
+
}
|
|
451
|
+
_resolveKey(obj, path) {
|
|
452
|
+
const value = path.split(".").reduce((acc, segment) => acc && typeof acc === "object" ? acc[segment] : void 0, obj);
|
|
453
|
+
if (typeof value === "string") return value;
|
|
454
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
455
|
+
}
|
|
456
|
+
_resolveInitialLanguage() {
|
|
457
|
+
const stored = safeGetItem(this._storageKey, this._storageStrategy);
|
|
458
|
+
if (stored && this._config.languages.some((l) => l.id === stored)) return stored;
|
|
459
|
+
if (this._config.detectBrowser) {
|
|
460
|
+
const detected = detectBrowserLanguage(this._config.languages.map((l) => l.id), browserLanguages());
|
|
461
|
+
if (detected) return detected;
|
|
462
|
+
}
|
|
463
|
+
return this._config.defaultLanguage;
|
|
464
|
+
}
|
|
465
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
466
|
+
minVersion: "12.0.0",
|
|
467
|
+
version: "22.2.2",
|
|
468
|
+
ngImport: i0,
|
|
469
|
+
type: RiviniaI18n,
|
|
470
|
+
deps: [],
|
|
471
|
+
target: i0.ɵɵFactoryTarget.Service
|
|
472
|
+
});
|
|
473
|
+
static ɵprov = i0.ɵɵngDeclareService({
|
|
474
|
+
minVersion: "22.0.0",
|
|
475
|
+
version: "22.2.2",
|
|
476
|
+
ngImport: i0,
|
|
477
|
+
type: RiviniaI18n
|
|
478
|
+
});
|
|
479
|
+
};
|
|
480
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
481
|
+
minVersion: "12.0.0",
|
|
482
|
+
version: "22.2.2",
|
|
483
|
+
ngImport: i0,
|
|
484
|
+
type: RiviniaI18n,
|
|
485
|
+
decorators: [{ type: Service }],
|
|
486
|
+
ctorParameters: () => []
|
|
487
|
+
});
|
|
488
|
+
function normalizeKeyArgs(second, third) {
|
|
489
|
+
if (second && typeof second === "object") return { params: second };
|
|
490
|
+
return {
|
|
491
|
+
defaultValue: second,
|
|
492
|
+
params: third
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
function provideRiviniaI18n(config) {
|
|
496
|
+
return makeEnvironmentProviders([{
|
|
497
|
+
provide: RIVINIA_I18N_CONFIG,
|
|
498
|
+
useValue: config
|
|
499
|
+
}]);
|
|
500
|
+
}
|
|
501
|
+
function injectRiviniaI18n() {
|
|
502
|
+
return inject(RiviniaI18n);
|
|
503
|
+
}
|
|
504
|
+
var RTranslatePipe = class RTranslatePipe {
|
|
505
|
+
_i18n = inject(RiviniaI18n);
|
|
506
|
+
transform(keyOrTranslations, defaultValueOrParams, maybeParams) {
|
|
507
|
+
return this._i18n.translate(keyOrTranslations, defaultValueOrParams, maybeParams);
|
|
508
|
+
}
|
|
509
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
510
|
+
minVersion: "12.0.0",
|
|
511
|
+
version: "22.2.2",
|
|
512
|
+
ngImport: i0,
|
|
513
|
+
type: RTranslatePipe,
|
|
514
|
+
deps: [],
|
|
515
|
+
target: i0.ɵɵFactoryTarget.Pipe
|
|
516
|
+
});
|
|
517
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({
|
|
518
|
+
minVersion: "14.0.0",
|
|
519
|
+
version: "22.2.2",
|
|
520
|
+
ngImport: i0,
|
|
521
|
+
type: RTranslatePipe,
|
|
522
|
+
isStandalone: true,
|
|
523
|
+
name: "rTranslate",
|
|
524
|
+
pure: false
|
|
525
|
+
});
|
|
526
|
+
};
|
|
527
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
528
|
+
minVersion: "12.0.0",
|
|
529
|
+
version: "22.2.2",
|
|
530
|
+
ngImport: i0,
|
|
531
|
+
type: RTranslatePipe,
|
|
532
|
+
decorators: [{
|
|
533
|
+
type: Pipe,
|
|
534
|
+
args: [{
|
|
535
|
+
name: "rTranslate",
|
|
536
|
+
standalone: true,
|
|
537
|
+
pure: false
|
|
538
|
+
}]
|
|
539
|
+
}]
|
|
540
|
+
});
|
|
541
|
+
export { RTranslatePipe, RiviniaI18n, ViewTransitionService, browserLanguages, customLoader, detectBrowserLanguage, formatIcu, httpLoader, injectRiviniaI18n, jsonLoader, provideRiviniaI18n, remoteLoader };
|
|
542
|
+
|
|
543
|
+
//# sourceMappingURL=rivinia-i18n.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rivinia-i18n.mjs","names":[],"sources":["../../../projects/i18n/src/lib/loaders.ts","../../../projects/i18n/src/lib/i18n-utils.ts","../../../projects/i18n/src/lib/icu.ts","../../../projects/i18n/src/lib/i18n-config.ts","../../../projects/i18n/src/lib/view-transition.service.ts","../../../projects/i18n/src/lib/rivinia-i18n.ts","../../../projects/i18n/src/lib/provide-i18n.ts","../../../projects/i18n/src/lib/translate.pipe.ts"],"sourcesContent":["/**\n * Pluggable key-dictionary loader. Returns a flat/nested JSON-compatible map\n * merged into `loadedTranslations` and read by key-based `translate(key)`.\n */\nexport interface TranslationLoader<L extends string = string> {\n load(language: L): Promise<Record<string, unknown>>;\n}\n\n/**\n * Lazy descriptor: `resolve()` dynamic-imports the real implementation, so\n * loader code splits out of the main bundle until first use. Resolved once\n * and cached by the service.\n */\nexport interface LoaderDescriptor<L extends string = string> {\n resolve(): Promise<TranslationLoader<L>>;\n}\n\nexport function jsonLoader(options?: { path?: string }): LoaderDescriptor<string> {\n return {\n async resolve() {\n const { JsonLoader } = await import('./json-loader.impl');\n return new JsonLoader(options);\n },\n };\n}\n\nexport interface HttpLoaderOptions {\n readonly endpoint: string;\n readonly method?: string;\n readonly buildUrl?: (language: string) => string;\n}\n\nexport function httpLoader(options: HttpLoaderOptions): LoaderDescriptor<string> {\n return {\n async resolve() {\n const { HttpLoader } = await import('./http-loader.impl');\n return new HttpLoader(options);\n },\n };\n}\n\nexport interface RemoteLoaderOptions {\n readonly url: (language: string) => string;\n readonly headers?: Record<string, string>;\n}\n\nexport function remoteLoader(options: RemoteLoaderOptions): LoaderDescriptor<string> {\n return {\n async resolve() {\n const { RemoteLoader } = await import('./remote-loader.impl');\n return new RemoteLoader(options);\n },\n };\n}\n\n/** Wraps any function as a loader (mocks, in-memory, third-party SDKs). */\nexport function customLoader<L extends string = string>(\n load: (language: L) => Promise<Record<string, unknown>>,\n): LoaderDescriptor<L> {\n return {\n async resolve() {\n return { load };\n },\n };\n}\n","import type { StorageStrategy } from './i18n-types';\n\nfunction getStorage(strategy: StorageStrategy): Storage | null {\n if (strategy === 'none') return null;\n if (typeof window === 'undefined') return null;\n try {\n return strategy === 'session' ? window.sessionStorage : window.localStorage;\n } catch {\n return null;\n }\n}\n\n/** SSR-safe read. Returns `null` off-browser, on denial, or when missing. */\nexport function safeGetItem(key: string, strategy: StorageStrategy): string | null {\n const storage = getStorage(strategy);\n if (!storage) return null;\n try {\n return storage.getItem(key);\n } catch {\n return null;\n }\n}\n\n/** SSR-safe write. Silently no-ops off-browser or on denial. */\nexport function safeSetItem(key: string, value: string, strategy: StorageStrategy): void {\n const storage = getStorage(strategy);\n if (!storage) return;\n try {\n storage.setItem(key, value);\n } catch {\n // Intentionally silent: persistence is best-effort.\n }\n}\n\n/**\n * Matches the browser language priority list against supported ids.\n * Exact (case-insensitive) matches win first; otherwise base tags match\n * (`ar-EG` → `ar`). Returns `null` when nothing matches or off-browser.\n * Pure and exported for testing — pass `navigator.languages` in app code.\n */\nexport function detectBrowserLanguage<T extends string>(\n supportedIds: readonly T[],\n browserLanguages: readonly string[] | undefined,\n): T | null {\n if (!browserLanguages || browserLanguages.length === 0) return null;\n const supported = supportedIds.map((id) => id.toLowerCase());\n for (const raw of browserLanguages) {\n const tag = raw.trim().toLowerCase();\n if (!tag) continue;\n const exact = supported.indexOf(tag);\n if (exact !== -1) return supportedIds[exact];\n }\n for (const raw of browserLanguages) {\n const base = raw.trim().toLowerCase().split(/[-_]/)[0];\n if (!base) continue;\n const hit = supported.indexOf(base);\n if (hit !== -1) return supportedIds[hit];\n }\n return null;\n}\n\n/** Browser language list, `undefined` off-browser (SSR-safe input for detection). */\nexport function browserLanguages(): readonly string[] | undefined {\n if (typeof window === 'undefined' || typeof navigator === 'undefined') return undefined;\n try {\n if (Array.isArray(navigator.languages) && navigator.languages.length > 0) {\n return [...navigator.languages];\n }\n return typeof navigator.language === 'string' ? [navigator.language] : undefined;\n } catch {\n return undefined;\n }\n}\n","import type { TranslateParams } from './i18n-types';\n\n/**\n * Minimal ICU MessageFormat subset: `{name}` interpolation, `{n, plural, …}`,\n * `{x, select, …}`, `#` inside plurals, and nesting. Categories resolve via\n * the native `Intl.PluralRules(locale)` — Arabic gets all six forms\n * (zero/one/two/few/many/other) with zero extra dependencies.\n *\n * Supported (and ONLY these — documented subset, translators beware):\n * - `{count, plural, =0 {none} one {# item} other {# items}}`\n * - `{gender, select, male {He} female {She} other {They}}`\n * - `{name}` plain interpolation (missing params keep the placeholder)\n *\n * Malformed input never throws: the raw segment is returned as-is.\n */\nexport function formatIcu(\n template: string,\n params: TranslateParams,\n locale: string,\n): string {\n return parseMessage(template, 0, template.length, params, locale, null).text;\n}\n\ninterface Parsed {\n text: string;\n /** Index of the closing `}` (or `end` when the level ran out). */\n next: number;\n ok: boolean;\n}\n\nfunction parseMessage(\n src: string,\n start: number,\n end: number,\n params: TranslateParams,\n locale: string,\n pluralValue: number | null,\n): Parsed {\n let out = '';\n let i = start;\n while (i < end) {\n const ch = src[i];\n if (ch === '{') {\n const arg = parseArgument(src, i, end, params, locale, pluralValue);\n if (!arg.ok) return { text: out + src.slice(i, end), next: end, ok: true };\n out += arg.text;\n i = arg.next;\n } else if (ch === '}') {\n return { text: out, next: i, ok: true };\n } else if (ch === '#' && pluralValue !== null) {\n out += String(pluralValue);\n i++;\n } else {\n out += ch;\n i++;\n }\n }\n return { text: out, next: i, ok: true };\n}\n\nfunction parseArgument(\n src: string,\n start: number,\n end: number,\n params: TranslateParams,\n locale: string,\n outerPlural: number | null,\n): Parsed {\n let i = skipSpaces(src, start + 1, end);\n const name = readWord(src, i, end);\n i = skipSpaces(src, name.next, end);\n if (i >= end) return { text: src.slice(start, end), next: end, ok: true };\n if (src[i] === '}') {\n const value = params[name.word];\n const rendered =\n value === undefined || value === null || name.word === ''\n ? src.slice(start, i + 1)\n : String(value);\n return { text: rendered, next: i + 1, ok: true };\n }\n if (src[i] !== ',' || name.word === '') {\n return { text: src.slice(start, end), next: end, ok: true };\n }\n i = skipSpaces(src, i + 1, end);\n const type = readWord(src, i, end);\n i = skipSpaces(src, type.next, end);\n if (i >= end || src[i] !== ',') return { text: src.slice(start, end), next: end, ok: true };\n if (type.word !== 'plural' && type.word !== 'select') {\n return { text: src.slice(start, end), next: end, ok: true };\n }\n i++;\n const numeric =\n type.word === 'plural' ? toFiniteNumber(params[name.word]) : null;\n const branches = new Map<string, string>();\n i = skipSpaces(src, i, end);\n let closed = false;\n while (i < end) {\n i = skipSpaces(src, i, end);\n if (i < end && src[i] === '}') {\n closed = true;\n break;\n }\n const sel = readSelector(src, i, end);\n if (sel.selector === null) return { text: src.slice(start, end), next: end, ok: true };\n i = skipSpaces(src, sel.next, end);\n if (i >= end || src[i] !== '{') {\n return { text: src.slice(start, end), next: end, ok: true };\n }\n // Bodies render immediately: '#' binds to THIS plural's number, or to an\n // outer plural when nested (select inherits, nested plural overrides).\n const body = parseMessage(\n src,\n i + 1,\n end,\n params,\n locale,\n numeric ?? outerPlural,\n );\n branches.set(sel.selector, body.text);\n i = body.next + 1;\n }\n if (!closed) return { text: src.slice(start, end), next: end, ok: true };\n if (type.word === 'select') {\n const raw = params[name.word];\n const key = raw === undefined || raw === null ? '' : String(raw);\n return { text: branches.get(key) ?? branches.get('other') ?? '', next: i + 1, ok: true };\n }\n if (numeric === null) return { text: branches.get('other') ?? '', next: i + 1, ok: true };\n const exact = branches.get(`=${numeric}`);\n if (exact !== undefined) return { text: exact, next: i + 1, ok: true };\n let category: string;\n try {\n category = new Intl.PluralRules(locale).select(numeric);\n } catch {\n category = 'other';\n }\n return { text: branches.get(category) ?? branches.get('other') ?? '', next: i + 1, ok: true };\n}\n\nfunction toFiniteNumber(value: string | number | boolean | undefined): number | null {\n if (typeof value === 'number') return Number.isFinite(value) ? value : null;\n if (typeof value === 'string' && value.trim() !== '') {\n const n = Number(value);\n return Number.isFinite(n) ? n : null;\n }\n return null;\n}\n\nfunction skipSpaces(src: string, i: number, end: number): number {\n while (i < end && /\\s/.test(src[i])) i++;\n return i;\n}\n\nfunction readWord(src: string, i: number, end: number): { word: string; next: number } {\n const start = skipSpaces(src, i, end);\n let j = start;\n while (j < end && /[^\\s,}]+/.test(src[j])) j++;\n return { word: src.slice(start, j), next: j };\n}\n\nfunction readSelector(\n src: string,\n i: number,\n end: number,\n): { selector: string | null; next: number } {\n i = skipSpaces(src, i, end);\n if (i < end && src[i] === '=') {\n let j = i + 1;\n if (j < end && src[j] === '-') j++;\n const digits = j;\n while (j < end && /[0-9]/.test(src[j])) j++;\n if (j < end && src[j] === '.' && j + 1 < end && /[0-9]/.test(src[j + 1])) {\n j++;\n while (j < end && /[0-9]/.test(src[j])) j++;\n }\n if (j === digits) return { selector: null, next: i };\n return { selector: src.slice(i, j), next: j };\n }\n const word = readWord(src, i, end);\n if (!word.word) return { selector: null, next: i };\n return { selector: word.word, next: word.next };\n}\n","import { InjectionToken } from '@angular/core';\nimport type {\n Language,\n StorageStrategy,\n SwitchStrategy,\n ViewTransitionConfig,\n} from './i18n-types';\nimport type { LoaderDescriptor } from './loaders';\n\n/**\n * Global configuration for `@rivinia/i18n`.\n */\nexport interface RiviniaI18nConfig<T extends string = string> {\n readonly languages: readonly Language<T>[];\n readonly defaultLanguage: T;\n readonly storageKey?: string;\n readonly storageStrategy?: StorageStrategy;\n readonly autoApplyDirection?: boolean;\n readonly viewTransition?: ViewTransitionConfig;\n /**\n * Dictionary source. Defaults to `jsonLoader()` — the conventional\n * `assets/i18n/{language}.json` layout. Override with any descriptor\n * (custom path, HTTP endpoint, in-memory). Inline-only apps that want zero\n * network traffic pass `customLoader(async () => ({}))`.\n */\n readonly loader?: LoaderDescriptor<T>;\n readonly switchStrategy?: SwitchStrategy;\n /** Called when a dictionary load fails. The service still falls back safely. */\n readonly onLoadError?: (language: T, error: unknown) => void;\n /**\n * Match `navigator.languages` against supported ids on first visit\n * (stored preference always wins; base tags match, e.g. `ar-EG` → `ar`).\n * @default false — explicit opt-in, no surprises.\n */\n readonly detectBrowser?: boolean;\n}\n\n/**\n * Internal configuration token. Consumers must use `provideRiviniaI18n()`.\n * @internal\n */\nexport const RIVINIA_I18N_CONFIG = new InjectionToken<RiviniaI18nConfig>(\n 'RIVINIA_I18N_CONFIG',\n);\n\nexport const DEFAULT_STORAGE_KEY = 'rivinia.i18n.language';\nexport const DEFAULT_STORAGE_STRATEGY: StorageStrategy = 'local';\nexport const DEFAULT_AUTO_APPLY_DIRECTION = true;\n","import { Service } from '@angular/core';\n\n/** Progressive-enhancement wrapper around the View Transition API. */\n@Service()\nexport class ViewTransitionService {\n private readonly _supported =\n typeof document !== 'undefined' && typeof document.startViewTransition === 'function';\n\n run(callback: () => void): void {\n if (this._supported) {\n document.startViewTransition(callback);\n } else {\n callback();\n }\n }\n}\n","import { Service, computed, effect, inject, signal } from '@angular/core';\nimport {\n DEFAULT_AUTO_APPLY_DIRECTION,\n DEFAULT_STORAGE_KEY,\n DEFAULT_STORAGE_STRATEGY,\n RIVINIA_I18N_CONFIG,\n type RiviniaI18nConfig,\n} from './i18n-config';\nimport type { Direction } from './i18n-types';\nimport type { Language } from './i18n-types';\nimport type { StorageStrategy } from './i18n-types';\nimport type { TranslateParams } from './i18n-types';\nimport type { Translation } from './i18n-types';\nimport type { TranslationLoader } from './loaders';\nimport { jsonLoader } from './loaders';\nimport { browserLanguages, detectBrowserLanguage, safeGetItem, safeSetItem } from './i18n-utils';\nimport { formatIcu } from './icu';\nimport { ViewTransitionService } from './view-transition.service';\n\n/**\n * Headless language owner. State (signals, readonly): current language,\n * direction, loader status, dictionaries. Changes only via the methods below.\n * Side effects (persistence + `<html dir/lang>`) run in effects; everything\n * SSR-guarded. No components, no pipes, no styles inside.\n */\n@Service()\nexport class RiviniaI18n<L extends string = string> {\n private readonly _config = inject<RiviniaI18nConfig<L>>(RIVINIA_I18N_CONFIG);\n private readonly _viewTransition = inject(ViewTransitionService, { optional: true });\n private readonly _storageKey = this._config.storageKey ?? DEFAULT_STORAGE_KEY;\n private readonly _storageStrategy: StorageStrategy =\n this._config.storageStrategy ?? DEFAULT_STORAGE_STRATEGY;\n private readonly _autoApplyDirection: boolean =\n this._config.autoApplyDirection ?? DEFAULT_AUTO_APPLY_DIRECTION;\n\n private readonly _currentLanguageId = signal<L>(this._resolveInitialLanguage());\n private readonly _languages = signal<readonly Language<L>[]>(this._config.languages);\n private readonly _loadedTranslations = signal<Record<string, unknown>>({});\n /**\n * Explicit loader wins; otherwise the conventional JSON layout\n * (`assets/i18n/{language}.json` unless the consumer overrides the path).\n * The descriptor still code-splits: the fetch implementation loads only on\n * first resolve.\n */\n private readonly _getLoader: () => Promise<TranslationLoader<L>> =\n this._config.loader?.resolve ?? (() => jsonLoader().resolve() as Promise<TranslationLoader<L>>);\n private _resolvedLoader: TranslationLoader<L> | null = null;\n private readonly _translationsCache = new Map<L, Record<string, unknown>>();\n private readonly _inflight = new Map<L, Promise<Record<string, unknown>>>();\n /**\n * Last-request-wins guard for rapid switches: each load captures a token;\n * stale out-of-order responses stay cached but never overwrite the signal.\n */\n private _requestToken = 0;\n private _applyCount = 0;\n\n readonly languageChanged = computed<L>(() => this._currentLanguageId());\n readonly languages = this._languages.asReadonly();\n readonly currentLanguage = this._currentLanguageId.asReadonly();\n\n readonly currentLanguageObject = computed<Language<L>>(() => {\n const id = this._currentLanguageId();\n return this._languages().find((l) => l.id === id) ?? this._languages()[0];\n });\n\n readonly dir = computed<Direction>(() => this.currentLanguageObject().dir);\n readonly isRtl = computed<boolean>(() => this.dir() === 'rtl');\n\n private readonly _loadingState = signal<'idle' | 'loading' | 'error'>('idle');\n private readonly _loadingError = signal<unknown>(null);\n\n /** Loader state for skeletons/spinners. */\n readonly loadingState = this._loadingState.asReadonly();\n readonly loadingError = this._loadingError.asReadonly();\n readonly isLoading = computed(() => this._loadingState() === 'loading');\n\n constructor() {\n if (this._config.languages.length === 0) {\n throw new Error('[rivinia/i18n] At least one language must be provided in the languages array.');\n }\n if (!this._config.languages.some((l) => l.id === this._config.defaultLanguage)) {\n throw new Error(\n `[rivinia/i18n] defaultLanguage \"${this._config.defaultLanguage}\" must be one of the configured language IDs.`,\n );\n }\n\n effect(() => {\n const id = this._currentLanguageId();\n safeSetItem(this._storageKey, id, this._storageStrategy);\n });\n\n if (this._autoApplyDirection) {\n effect(() => {\n if (typeof document === 'undefined') {\n return;\n }\n const lang = this.currentLanguageObject();\n document.documentElement.dir = lang.dir;\n document.documentElement.lang = lang.id;\n });\n }\n }\n\n getLanguage(id: L): Language<L> | undefined {\n return this._languages().find((l) => l.id === id);\n }\n\n translate(key: string, defaultValue?: string, params?: TranslateParams): string;\n translate(key: string, params?: TranslateParams): string;\n translate(translations: Translation<L>): string;\n\n translate(\n keyOrTranslations: string | Translation<L>,\n defaultValueOrParams?: string | TranslateParams,\n maybeParams?: TranslateParams,\n ): string {\n if (typeof keyOrTranslations === 'string') {\n const { defaultValue, params } = normalizeKeyArgs(defaultValueOrParams, maybeParams);\n const loaded = this._loadedTranslations();\n const resolved = this._resolveKey(loaded, keyOrTranslations);\n if (resolved !== undefined) {\n return this.render(resolved, params);\n }\n const fallback = defaultValue ?? keyOrTranslations;\n return params ? this.render(fallback, params) : fallback;\n }\n const currentId = this._currentLanguageId();\n return keyOrTranslations[currentId] ?? Object.values(keyOrTranslations)[0] ?? '';\n }\n\n loadedTranslations = this._loadedTranslations.asReadonly();\n\n /** Preload without switching (use in `APP_INITIALIZER` / route guards). */\n async loadTranslations(\n languageId: L,\n opts?: { silent?: boolean },\n ): Promise<Record<string, unknown>> {\n return this._loadTranslations(languageId, opts);\n }\n\n toggle(): void {\n const langs = this._languages();\n if (langs.length < 2) return;\n const currentId = this._currentLanguageId();\n const newId = currentId === langs[0].id ? langs[1].id : langs[0].id;\n this.applyLanguage(newId);\n }\n\n next(): void {\n const langs = this._languages();\n if (langs.length < 2) return;\n const currentIdx = langs.findIndex((l) => l.id === this._currentLanguageId());\n const nextIdx = (currentIdx + 1) % langs.length;\n this.applyLanguage(langs[nextIdx].id);\n }\n\n previous(): void {\n const langs = this._languages();\n if (langs.length < 2) return;\n const currentIdx = langs.findIndex((l) => l.id === this._currentLanguageId());\n const prevIdx = (currentIdx - 1 + langs.length) % langs.length;\n this.applyLanguage(langs[prevIdx].id);\n }\n\n setLanguage(id: L): void {\n if (this._config.switchStrategy === 'preload-first') {\n void this.setLanguageAsync(id);\n return;\n }\n this.applyLanguage(id);\n }\n\n /** Preload-first switch: await the dictionary, then flip — no raw-key flash. */\n async setLanguageAsync(id: L): Promise<void> {\n if (id === this._currentLanguageId()) return;\n if (!this._languages().some((l) => l.id === id)) return;\n await this._loadTranslations(id, { silent: true });\n this.applyLanguage(id);\n }\n\n /** Number formatting bound to the current language (pure Intl wrapper). */\n formatNumber(value: number, options?: Intl.NumberFormatOptions): string {\n return new Intl.NumberFormat(this._currentLanguageId(), options).format(value);\n }\n\n /** Date/time formatting bound to the current language (pure Intl wrapper). */\n formatDate(value: Date | number, options?: Intl.DateTimeFormatOptions): string {\n return new Intl.DateTimeFormat(this._currentLanguageId(), options).format(value);\n }\n\n private applyLanguage(id: L, opts?: { skipLoad?: boolean }): void {\n if (id === this._currentLanguageId()) return;\n\n const lang = this._languages().find((l) => l.id === id);\n if (!lang) return;\n\n this._applyCount++;\n\n const apply = () => this._currentLanguageId.set(id);\n const vt = this._config.viewTransition;\n const useTransition =\n vt?.enabled &&\n (!vt.skipInitialTransition || this._applyCount > 1) &&\n this._viewTransition != null;\n\n if (useTransition) {\n vt!.onViewTransitionCreated?.({ language: id, direction: lang.dir });\n this._viewTransition!.run(apply);\n } else {\n apply();\n }\n\n if (!opts?.skipLoad) {\n void this._loadTranslations(id);\n }\n }\n\n private render(template: string, params?: TranslateParams): string {\n if (!params) return template;\n if (!template.includes('{')) return template;\n try {\n return formatIcu(template, params, this._currentLanguageId());\n } catch {\n return template;\n }\n }\n\n private async _loadTranslations(\n languageId: L,\n opts?: { silent?: boolean },\n ): Promise<Record<string, unknown>> {\n const cached = this._translationsCache.get(languageId);\n if (cached) {\n if (!opts?.silent) {\n this._loadedTranslations.set(cached);\n }\n return cached;\n }\n\n const inflight = this._inflight.get(languageId);\n if (inflight) return inflight;\n\n const myToken = ++this._requestToken;\n this._loadingState.set('loading');\n\n const task = (async () => {\n try {\n if (!this._resolvedLoader) {\n this._resolvedLoader = await this._getLoader!();\n }\n const translations = await this._resolvedLoader.load(languageId);\n\n this._translationsCache.set(languageId, translations);\n\n if (myToken === this._requestToken && !opts?.silent) {\n this._loadedTranslations.set(translations);\n this._loadingError.set(null);\n this._loadingState.set('idle');\n }\n\n return translations;\n } catch (error) {\n if (myToken === this._requestToken) {\n this._loadingError.set(error);\n this._loadingState.set('error');\n }\n this._config.onLoadError?.(languageId, error);\n return {};\n } finally {\n this._inflight.delete(languageId);\n if (this._inflight.size === 0 && this._loadingState() === 'loading') {\n this._loadingState.set('idle');\n }\n }\n })();\n\n this._inflight.set(languageId, task);\n return task;\n }\n\n private _resolveKey(obj: Record<string, unknown>, path: string): string | undefined {\n const value = path.split('.').reduce<unknown>(\n (acc, segment) =>\n acc && typeof acc === 'object'\n ? (acc as Record<string, unknown>)[segment]\n : undefined,\n obj,\n );\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n return undefined;\n }\n\n private _resolveInitialLanguage(): L {\n const stored = safeGetItem(this._storageKey, this._storageStrategy);\n if (stored && this._config.languages.some((l) => l.id === stored)) {\n return stored as L;\n }\n if (this._config.detectBrowser) {\n const detected = detectBrowserLanguage(\n this._config.languages.map((l) => l.id),\n browserLanguages(),\n );\n if (detected) return detected;\n }\n return this._config.defaultLanguage;\n }\n}\n\nfunction normalizeKeyArgs(\n second?: string | TranslateParams,\n third?: TranslateParams,\n): { defaultValue?: string; params?: TranslateParams } {\n if (second && typeof second === 'object') {\n return { params: second };\n }\n return { defaultValue: second, params: third };\n}\n","import { EnvironmentProviders, inject, makeEnvironmentProviders } from '@angular/core';\nimport { RIVINIA_I18N_CONFIG, type RiviniaI18nConfig } from './i18n-config';\nimport { RiviniaI18n } from './rivinia-i18n';\n\n/**\n * Configures `@rivinia/i18n` for the application. Call once at bootstrap.\n *\n * @example\n * ```ts\n * provideRiviniaI18n({\n * defaultLanguage: 'ar',\n * languages: [\n * { id: 'ar', nativeName: 'العربية', dir: 'rtl' },\n * { id: 'en', nativeName: 'English', dir: 'ltr' },\n * ],\n * })\n * ```\n */\nexport function provideRiviniaI18n<L extends string>(\n config: RiviniaI18nConfig<L>,\n): EnvironmentProviders {\n return makeEnvironmentProviders([{ provide: RIVINIA_I18N_CONFIG, useValue: config }]);\n}\n\n/** Shorthand for `inject(RiviniaI18n)`. */\nexport function injectRiviniaI18n(): RiviniaI18n<string> {\n return inject(RiviniaI18n);\n}\n","import { Pipe, inject } from '@angular/core';\nimport { RiviniaI18n } from './rivinia-i18n';\nimport type { TranslateParams } from './i18n-types';\nimport type { Translation } from './i18n-types';\n\n/**\n * Template pipe delegating to `RiviniaI18n.translate()`.\n *\n * Impure (`pure: false`) by necessity: the service reads signals on every\n * call, and a pure pipe would not re-evaluate on language switches. For long\n * lists prefer `translate()` in component code over this pipe.\n */\n@Pipe({\n name: 'rTranslate',\n standalone: true,\n pure: false,\n})\nexport class RTranslatePipe<L extends string = string> {\n private readonly _i18n = inject(RiviniaI18n<L>);\n\n transform(key: string, defaultValue?: string, params?: TranslateParams): string;\n transform(key: string, params?: TranslateParams): string;\n transform(translations: Translation<L>): string;\n\n transform(\n keyOrTranslations: string | Translation<L>,\n defaultValueOrParams?: string | TranslateParams,\n maybeParams?: TranslateParams,\n ): string {\n return this._i18n.translate(\n keyOrTranslations as string,\n defaultValueOrParams as string,\n maybeParams as TranslateParams,\n );\n }\n}\n"],"mappings":";;AAiBA,SAAgB,WAAW,SAA2B;CACpD,OAAO,EACL,MAAM,UAAO;EACX,MAAM,EAAE,eAAe,MAAM,OAAO;EACpC,OAAO,IAAI,WAAW,OAAO;CAC/B,EACD;AACH;AAQA,SAAgB,WAAW,SAA0B;CACnD,OAAO,EACL,MAAM,UAAO;EACX,MAAM,EAAE,eAAe,MAAM,OAAO;EACpC,OAAO,IAAI,WAAW,OAAO;CAC/B,EACD;AACH;AAOA,SAAgB,aAAa,SAA4B;CACvD,OAAO,EACL,MAAM,UAAO;EACX,MAAM,EAAE,iBAAiB,MAAM,OAAO;EACtC,OAAO,IAAI,aAAa,OAAO;CACjC,EACD;AACH;AAGA,SAAgB,aACd,MAAuD;CAEvD,OAAO,EACL,MAAM,UAAO;EACX,OAAO,EAAE,KAAI;CACf,EACD;AACH;AC9DA,SAAS,WAAW,UAAyB;CAC3C,IAAI,aAAa,QAAQ,OAAO;CAChC,IAAI,OAAO,WAAW,aAAa,OAAO;CAC1C,IAAI;EACF,OAAO,aAAa,YAAY,OAAO,iBAAiB,OAAO;CACjE,QAAQ;EACN,OAAO;CACT;AACF;AAGA,SAAgB,YAAY,KAAa,UAAyB;CAChE,MAAM,UAAU,WAAW,QAAQ;CACnC,IAAI,CAAC,SAAS,OAAO;CACrB,IAAI;EACF,OAAO,QAAQ,QAAQ,GAAG;CA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GACJ,MAAM;GACN,YAAY;GACZ,MAAM;EACP,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rivinia/i18n",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Headless language manager for Angular: signals, RTL, loaders, ICU plurals, browser detection, Intl formatting.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"angular",
|
|
7
|
+
"i18n",
|
|
8
|
+
"localization",
|
|
9
|
+
"signals",
|
|
10
|
+
"rtl",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@angular/core": "^22.0.0"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"schematics": "./schematics/collection.json",
|
|
19
|
+
"module": "fesm2022/rivinia-i18n.mjs",
|
|
20
|
+
"typings": "types/rivinia-i18n.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
"./package.json": {
|
|
23
|
+
"default": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./types/rivinia-i18n.d.ts",
|
|
27
|
+
"default": "./fesm2022/rivinia-i18n.mjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"type": "module",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"tslib": "^2.3.0"
|
|
33
|
+
}
|
|
6
34
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
|
|
3
|
+
"schematics": {
|
|
4
|
+
"ng-add": {
|
|
5
|
+
"description": "Add provideRiviniaI18n() with an ar/en starter to the application config.",
|
|
6
|
+
"factory": "./ng-add/index.cjs#ngAdd",
|
|
7
|
+
"schema": "./ng-add/schema.json"
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ngAdd = ngAdd;
|
|
4
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
+
const PROVIDE_IMPORT = `import { provideRiviniaI18n } from '@rivinia/i18n';`;
|
|
6
|
+
const STARTER = (defaultLanguage, detectBrowser) => {
|
|
7
|
+
const detect = detectBrowser ? ',\n detectBrowser: true' : '';
|
|
8
|
+
return (`provideRiviniaI18n({\n` +
|
|
9
|
+
` defaultLanguage: '${defaultLanguage}',\n` +
|
|
10
|
+
` languages: [\n` +
|
|
11
|
+
` { id: 'ar', nativeName: 'العربية', dir: 'rtl' },\n` +
|
|
12
|
+
` { id: 'en', nativeName: 'English', dir: 'ltr' },\n` +
|
|
13
|
+
` ],${detect}\n` +
|
|
14
|
+
` })`);
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* `ng add @rivinia/i18n` — wires a starter bilingual config.
|
|
18
|
+
*
|
|
19
|
+
* - Emits an editable ar/en starter (default language + optional detection).
|
|
20
|
+
* Real apps replace the list with their own languages afterwards.
|
|
21
|
+
* - Never overwrites user files; idempotent; warn-skips unknown layouts
|
|
22
|
+
* without failing installs.
|
|
23
|
+
*/
|
|
24
|
+
function ngAdd(options) {
|
|
25
|
+
return (tree, context) => {
|
|
26
|
+
let configPath;
|
|
27
|
+
try {
|
|
28
|
+
configPath = findAppConfig(tree, options.project);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
context.logger.warn(`[rivinia/i18n] workspace lookup failed (${error instanceof Error ? error.message : error}) — skipping. ` +
|
|
32
|
+
`Add provideRiviniaI18n() manually (see README).`);
|
|
33
|
+
return tree;
|
|
34
|
+
}
|
|
35
|
+
if (!configPath || !tree.exists(configPath)) {
|
|
36
|
+
context.logger.warn(`[rivinia/i18n] app.config.ts not found — skipping. ` +
|
|
37
|
+
`Add provideRiviniaI18n() manually (see README).`);
|
|
38
|
+
return tree;
|
|
39
|
+
}
|
|
40
|
+
let content = tree.read(configPath)?.toString('utf-8') ?? '';
|
|
41
|
+
if (!content) {
|
|
42
|
+
throw new schematics_1.SchematicsException(`[rivinia/i18n] ${configPath} is empty.`);
|
|
43
|
+
}
|
|
44
|
+
let changed = false;
|
|
45
|
+
if (!content.includes(PROVIDE_IMPORT)) {
|
|
46
|
+
content = insertAfterLastImport(content, PROVIDE_IMPORT);
|
|
47
|
+
changed = true;
|
|
48
|
+
}
|
|
49
|
+
if (!content.includes('provideRiviniaI18n(')) {
|
|
50
|
+
const call = STARTER(options.defaultLanguage && options.defaultLanguage.length > 0
|
|
51
|
+
? options.defaultLanguage
|
|
52
|
+
: 'ar', options.detectBrowser === true);
|
|
53
|
+
content = insertProvider(content, call);
|
|
54
|
+
changed = true;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
context.logger.info('[rivinia/i18n] provideRiviniaI18n() already present — skipped.');
|
|
58
|
+
}
|
|
59
|
+
if (changed) {
|
|
60
|
+
tree.overwrite(configPath, content);
|
|
61
|
+
context.logger.info(`[rivinia/i18n] wired into ${configPath}.`);
|
|
62
|
+
}
|
|
63
|
+
return tree;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function defaultProjectName(tree, requested) {
|
|
67
|
+
if (requested)
|
|
68
|
+
return requested;
|
|
69
|
+
const angularJson = tree.read('/angular.json')?.toString('utf-8');
|
|
70
|
+
if (!angularJson) {
|
|
71
|
+
throw new schematics_1.SchematicsException('[rivinia/i18n] angular.json not found.');
|
|
72
|
+
}
|
|
73
|
+
const workspace = JSON.parse(angularJson);
|
|
74
|
+
if (workspace.defaultProject && typeof workspace.defaultProject === 'string') {
|
|
75
|
+
return workspace.defaultProject;
|
|
76
|
+
}
|
|
77
|
+
const names = Object.keys(workspace.projects ?? {});
|
|
78
|
+
if (names.length === 0) {
|
|
79
|
+
throw new schematics_1.SchematicsException('[rivinia/i18n] no projects in angular.json.');
|
|
80
|
+
}
|
|
81
|
+
return names[0];
|
|
82
|
+
}
|
|
83
|
+
function findAppConfig(tree, requestedProject) {
|
|
84
|
+
const angularJson = tree.read('/angular.json')?.toString('utf-8');
|
|
85
|
+
if (!angularJson)
|
|
86
|
+
return null;
|
|
87
|
+
const workspace = JSON.parse(angularJson);
|
|
88
|
+
const name = defaultProjectName(tree, requestedProject);
|
|
89
|
+
const project = workspace.projects?.[name];
|
|
90
|
+
if (!project)
|
|
91
|
+
return null;
|
|
92
|
+
const sourceRoot = project.sourceRoot ?? (project.root ? `${project.root}/src` : 'src');
|
|
93
|
+
return `/${sourceRoot}/app/app.config.ts`;
|
|
94
|
+
}
|
|
95
|
+
function insertAfterLastImport(content, line) {
|
|
96
|
+
const lines = content.split('\n');
|
|
97
|
+
let idx = -1;
|
|
98
|
+
for (let i = 0; i < lines.length; i++) {
|
|
99
|
+
if (/^\s*import\s/.test(lines[i]))
|
|
100
|
+
idx = i;
|
|
101
|
+
}
|
|
102
|
+
lines.splice(idx + 1, 0, line);
|
|
103
|
+
return lines.join('\n');
|
|
104
|
+
}
|
|
105
|
+
function insertProvider(content, call) {
|
|
106
|
+
const match = /providers\s*:\s*\[/.exec(content);
|
|
107
|
+
if (!match) {
|
|
108
|
+
throw new schematics_1.SchematicsException('[rivinia/i18n] no `providers: [` array found in app.config.ts — add providers manually.');
|
|
109
|
+
}
|
|
110
|
+
const at = match.index + match[0].length;
|
|
111
|
+
return `${content.slice(0, at)}\n ${call},${content.slice(at)}`;
|
|
112
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "rivinia-i18n-ng-add",
|
|
4
|
+
"title": "Rivinia i18n ng-add options",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"defaultLanguage": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "Default language id for the starter config (must exist in your languages list).",
|
|
10
|
+
"x-prompt": {
|
|
11
|
+
"message": "Default language id for this project (Enter for 'ar')?",
|
|
12
|
+
"type": "input"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"detectBrowser": {
|
|
16
|
+
"type": "boolean",
|
|
17
|
+
"description": "Match navigator.languages on first visit (stored preference always wins).",
|
|
18
|
+
"x-prompt": {
|
|
19
|
+
"message": "Detect the browser language on first visit?",
|
|
20
|
+
"type": "confirmation"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"project": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"description": "Angular CLI project name — only for multi-app workspaces. Defaults to the workspace default project.",
|
|
26
|
+
"default": ""
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"required": []
|
|
30
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { EnvironmentProviders, InjectionToken } from "@angular/core";
|
|
3
|
+
/** Text rendering direction. */
|
|
4
|
+
type Direction = 'ltr' | 'rtl';
|
|
5
|
+
/**
|
|
6
|
+
* A supported language. `nativeName` is presentation-only metadata for
|
|
7
|
+
* switcher UIs — Core never reads it internally.
|
|
8
|
+
*/
|
|
9
|
+
interface Language<T extends string = string> {
|
|
10
|
+
readonly id: T;
|
|
11
|
+
readonly nativeName?: string;
|
|
12
|
+
readonly dir: Direction;
|
|
13
|
+
}
|
|
14
|
+
/** Inline typed translations: `{ ar: 'حفظ', en: 'Save' }`. */
|
|
15
|
+
type Translation<T extends string> = Record<T, string>;
|
|
16
|
+
/** Persistence backend. SSR-safe: everything degrades to no-op off-browser. */
|
|
17
|
+
type StorageStrategy = 'local' | 'session' | 'none';
|
|
18
|
+
/** Interpolation + ICU params (`{count}`, `{gender}`). */
|
|
19
|
+
type TranslateParams = Record<string, string | number | boolean>;
|
|
20
|
+
interface ViewTransitionInfo {
|
|
21
|
+
readonly language: string;
|
|
22
|
+
readonly direction: Direction;
|
|
23
|
+
}
|
|
24
|
+
interface ViewTransitionConfig {
|
|
25
|
+
readonly enabled?: boolean;
|
|
26
|
+
readonly skipInitialTransition?: boolean;
|
|
27
|
+
readonly onViewTransitionCreated?: (info: ViewTransitionInfo) => void;
|
|
28
|
+
}
|
|
29
|
+
/** `'instant'`: flip now, load in background. `'preload-first'`: no raw-key flash. */
|
|
30
|
+
type SwitchStrategy = 'instant' | 'preload-first';
|
|
31
|
+
/**
|
|
32
|
+
* Pluggable key-dictionary loader. Returns a flat/nested JSON-compatible map
|
|
33
|
+
* merged into `loadedTranslations` and read by key-based `translate(key)`.
|
|
34
|
+
*/
|
|
35
|
+
interface TranslationLoader<L extends string = string> {
|
|
36
|
+
load(language: L): Promise<Record<string, unknown>>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Lazy descriptor: `resolve()` dynamic-imports the real implementation, so
|
|
40
|
+
* loader code splits out of the main bundle until first use. Resolved once
|
|
41
|
+
* and cached by the service.
|
|
42
|
+
*/
|
|
43
|
+
interface LoaderDescriptor<L extends string = string> {
|
|
44
|
+
resolve(): Promise<TranslationLoader<L>>;
|
|
45
|
+
}
|
|
46
|
+
export declare function jsonLoader(options?: {
|
|
47
|
+
path?: string;
|
|
48
|
+
}): LoaderDescriptor<string>;
|
|
49
|
+
interface HttpLoaderOptions {
|
|
50
|
+
readonly endpoint: string;
|
|
51
|
+
readonly method?: string;
|
|
52
|
+
readonly buildUrl?: (language: string) => string;
|
|
53
|
+
}
|
|
54
|
+
export declare function httpLoader(options: HttpLoaderOptions): LoaderDescriptor<string>;
|
|
55
|
+
interface RemoteLoaderOptions {
|
|
56
|
+
readonly url: (language: string) => string;
|
|
57
|
+
readonly headers?: Record<string, string>;
|
|
58
|
+
}
|
|
59
|
+
export declare function remoteLoader(options: RemoteLoaderOptions): LoaderDescriptor<string>;
|
|
60
|
+
/** Wraps any function as a loader (mocks, in-memory, third-party SDKs). */
|
|
61
|
+
export declare function customLoader<L extends string = string>(load: (language: L) => Promise<Record<string, unknown>>): LoaderDescriptor<L>;
|
|
62
|
+
/**
|
|
63
|
+
* Global configuration for `@rivinia/i18n`.
|
|
64
|
+
*/
|
|
65
|
+
interface RiviniaI18nConfig<T extends string = string> {
|
|
66
|
+
readonly languages: readonly Language<T>[];
|
|
67
|
+
readonly defaultLanguage: T;
|
|
68
|
+
readonly storageKey?: string;
|
|
69
|
+
readonly storageStrategy?: StorageStrategy;
|
|
70
|
+
readonly autoApplyDirection?: boolean;
|
|
71
|
+
readonly viewTransition?: ViewTransitionConfig;
|
|
72
|
+
/**
|
|
73
|
+
* Dictionary source. Defaults to `jsonLoader()` — the conventional
|
|
74
|
+
* `assets/i18n/{language}.json` layout. Override with any descriptor
|
|
75
|
+
* (custom path, HTTP endpoint, in-memory). Inline-only apps that want zero
|
|
76
|
+
* network traffic pass `customLoader(async () => ({}))`.
|
|
77
|
+
*/
|
|
78
|
+
readonly loader?: LoaderDescriptor<T>;
|
|
79
|
+
readonly switchStrategy?: SwitchStrategy;
|
|
80
|
+
/** Called when a dictionary load fails. The service still falls back safely. */
|
|
81
|
+
readonly onLoadError?: (language: T, error: unknown) => void;
|
|
82
|
+
/**
|
|
83
|
+
* Match `navigator.languages` against supported ids on first visit
|
|
84
|
+
* (stored preference always wins; base tags match, e.g. `ar-EG` → `ar`).
|
|
85
|
+
* @default false — explicit opt-in, no surprises.
|
|
86
|
+
*/
|
|
87
|
+
readonly detectBrowser?: boolean;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Internal configuration token. Consumers must use `provideRiviniaI18n()`.
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
declare const RIVINIA_I18N_CONFIG: InjectionToken<RiviniaI18nConfig<string>>;
|
|
94
|
+
declare const DEFAULT_STORAGE_KEY = "rivinia.i18n.language";
|
|
95
|
+
declare const DEFAULT_STORAGE_STRATEGY: StorageStrategy;
|
|
96
|
+
declare const DEFAULT_AUTO_APPLY_DIRECTION = true;
|
|
97
|
+
/** SSR-safe read. Returns `null` off-browser, on denial, or when missing. */
|
|
98
|
+
declare function safeGetItem(key: string, strategy: StorageStrategy): string | null;
|
|
99
|
+
/** SSR-safe write. Silently no-ops off-browser or on denial. */
|
|
100
|
+
declare function safeSetItem(key: string, value: string, strategy: StorageStrategy): void;
|
|
101
|
+
/**
|
|
102
|
+
* Matches the browser language priority list against supported ids.
|
|
103
|
+
* Exact (case-insensitive) matches win first; otherwise base tags match
|
|
104
|
+
* (`ar-EG` → `ar`). Returns `null` when nothing matches or off-browser.
|
|
105
|
+
* Pure and exported for testing — pass `navigator.languages` in app code.
|
|
106
|
+
*/
|
|
107
|
+
export declare function detectBrowserLanguage<T extends string>(supportedIds: readonly T[], browserLanguages: readonly string[] | undefined): T | null;
|
|
108
|
+
/** Browser language list, `undefined` off-browser (SSR-safe input for detection). */
|
|
109
|
+
export declare function browserLanguages(): readonly string[] | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Minimal ICU MessageFormat subset: `{name}` interpolation, `{n, plural, …}`,
|
|
112
|
+
* `{x, select, …}`, `#` inside plurals, and nesting. Categories resolve via
|
|
113
|
+
* the native `Intl.PluralRules(locale)` — Arabic gets all six forms
|
|
114
|
+
* (zero/one/two/few/many/other) with zero extra dependencies.
|
|
115
|
+
*
|
|
116
|
+
* Supported (and ONLY these — documented subset, translators beware):
|
|
117
|
+
* - `{count, plural, =0 {none} one {# item} other {# items}}`
|
|
118
|
+
* - `{gender, select, male {He} female {She} other {They}}`
|
|
119
|
+
* - `{name}` plain interpolation (missing params keep the placeholder)
|
|
120
|
+
*
|
|
121
|
+
* Malformed input never throws: the raw segment is returned as-is.
|
|
122
|
+
*/
|
|
123
|
+
export declare function formatIcu(template: string, params: TranslateParams, locale: string): string;
|
|
124
|
+
/**
|
|
125
|
+
* Headless language owner. State (signals, readonly): current language,
|
|
126
|
+
* direction, loader status, dictionaries. Changes only via the methods below.
|
|
127
|
+
* Side effects (persistence + `<html dir/lang>`) run in effects; everything
|
|
128
|
+
* SSR-guarded. No components, no pipes, no styles inside.
|
|
129
|
+
*/
|
|
130
|
+
export declare class RiviniaI18n<L extends string = string> {
|
|
131
|
+
private readonly _config;
|
|
132
|
+
private readonly _viewTransition;
|
|
133
|
+
private readonly _storageKey;
|
|
134
|
+
private readonly _storageStrategy;
|
|
135
|
+
private readonly _autoApplyDirection;
|
|
136
|
+
private readonly _currentLanguageId;
|
|
137
|
+
private readonly _languages;
|
|
138
|
+
private readonly _loadedTranslations;
|
|
139
|
+
/**
|
|
140
|
+
* Explicit loader wins; otherwise the conventional JSON layout
|
|
141
|
+
* (`assets/i18n/{language}.json` unless the consumer overrides the path).
|
|
142
|
+
* The descriptor still code-splits: the fetch implementation loads only on
|
|
143
|
+
* first resolve.
|
|
144
|
+
*/
|
|
145
|
+
private readonly _getLoader;
|
|
146
|
+
private _resolvedLoader;
|
|
147
|
+
private readonly _translationsCache;
|
|
148
|
+
private readonly _inflight;
|
|
149
|
+
/**
|
|
150
|
+
* Last-request-wins guard for rapid switches: each load captures a token;
|
|
151
|
+
* stale out-of-order responses stay cached but never overwrite the signal.
|
|
152
|
+
*/
|
|
153
|
+
private _requestToken;
|
|
154
|
+
private _applyCount;
|
|
155
|
+
readonly languageChanged: import("@angular/core").Signal<L>;
|
|
156
|
+
readonly languages: import("@angular/core").Signal<readonly Language<L>[]>;
|
|
157
|
+
readonly currentLanguage: import("@angular/core").Signal<L>;
|
|
158
|
+
readonly currentLanguageObject: import("@angular/core").Signal<Language<L>>;
|
|
159
|
+
readonly dir: import("@angular/core").Signal<Direction>;
|
|
160
|
+
readonly isRtl: import("@angular/core").Signal<boolean>;
|
|
161
|
+
private readonly _loadingState;
|
|
162
|
+
private readonly _loadingError;
|
|
163
|
+
/** Loader state for skeletons/spinners. */
|
|
164
|
+
readonly loadingState: import("@angular/core").Signal<"idle" | "loading" | "error">;
|
|
165
|
+
readonly loadingError: import("@angular/core").Signal<unknown>;
|
|
166
|
+
readonly isLoading: import("@angular/core").Signal<boolean>;
|
|
167
|
+
constructor();
|
|
168
|
+
getLanguage(id: L): Language<L> | undefined;
|
|
169
|
+
translate(key: string, defaultValue?: string, params?: TranslateParams): string;
|
|
170
|
+
translate(key: string, params?: TranslateParams): string;
|
|
171
|
+
translate(translations: Translation<L>): string;
|
|
172
|
+
loadedTranslations: import("@angular/core").Signal<Record<string, unknown>>;
|
|
173
|
+
/** Preload without switching (use in `APP_INITIALIZER` / route guards). */
|
|
174
|
+
loadTranslations(languageId: L, opts?: {
|
|
175
|
+
silent?: boolean;
|
|
176
|
+
}): Promise<Record<string, unknown>>;
|
|
177
|
+
toggle(): void;
|
|
178
|
+
next(): void;
|
|
179
|
+
previous(): void;
|
|
180
|
+
setLanguage(id: L): void;
|
|
181
|
+
/** Preload-first switch: await the dictionary, then flip — no raw-key flash. */
|
|
182
|
+
setLanguageAsync(id: L): Promise<void>;
|
|
183
|
+
/** Number formatting bound to the current language (pure Intl wrapper). */
|
|
184
|
+
formatNumber(value: number, options?: Intl.NumberFormatOptions): string;
|
|
185
|
+
/** Date/time formatting bound to the current language (pure Intl wrapper). */
|
|
186
|
+
formatDate(value: Date | number, options?: Intl.DateTimeFormatOptions): string;
|
|
187
|
+
private applyLanguage;
|
|
188
|
+
private render;
|
|
189
|
+
private _loadTranslations;
|
|
190
|
+
private _resolveKey;
|
|
191
|
+
private _resolveInitialLanguage;
|
|
192
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RiviniaI18n<any>, never>;
|
|
193
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Configures `@rivinia/i18n` for the application. Call once at bootstrap.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* provideRiviniaI18n({
|
|
201
|
+
* defaultLanguage: 'ar',
|
|
202
|
+
* languages: [
|
|
203
|
+
* { id: 'ar', nativeName: 'العربية', dir: 'rtl' },
|
|
204
|
+
* { id: 'en', nativeName: 'English', dir: 'ltr' },
|
|
205
|
+
* ],
|
|
206
|
+
* })
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
export declare function provideRiviniaI18n<L extends string>(config: RiviniaI18nConfig<L>): EnvironmentProviders;
|
|
210
|
+
/** Shorthand for `inject(RiviniaI18n)`. */
|
|
211
|
+
export declare function injectRiviniaI18n(): RiviniaI18n<string>;
|
|
212
|
+
/** Progressive-enhancement wrapper around the View Transition API. */
|
|
213
|
+
export declare class ViewTransitionService {
|
|
214
|
+
private readonly _supported;
|
|
215
|
+
run(callback: () => void): void;
|
|
216
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ViewTransitionService, never>;
|
|
217
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Template pipe delegating to `RiviniaI18n.translate()`.
|
|
221
|
+
*
|
|
222
|
+
* Impure (`pure: false`) by necessity: the service reads signals on every
|
|
223
|
+
* call, and a pure pipe would not re-evaluate on language switches. For long
|
|
224
|
+
* lists prefer `translate()` in component code over this pipe.
|
|
225
|
+
*/
|
|
226
|
+
export declare class RTranslatePipe<L extends string = string> {
|
|
227
|
+
private readonly _i18n;
|
|
228
|
+
transform(key: string, defaultValue?: string, params?: TranslateParams): string;
|
|
229
|
+
transform(key: string, params?: TranslateParams): string;
|
|
230
|
+
transform(translations: Translation<L>): string;
|
|
231
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RTranslatePipe<any>, never>;
|
|
232
|
+
static ɵpipe: i0.ɵɵPipeDeclaration<RTranslatePipe<any>, "rTranslate", true>;
|
|
233
|
+
}
|
|
234
|
+
export type { Direction, HttpLoaderOptions, Language, LoaderDescriptor, RemoteLoaderOptions, RiviniaI18nConfig, StorageStrategy, SwitchStrategy, TranslateParams, Translation, TranslationLoader, ViewTransitionConfig, ViewTransitionInfo };
|