@rivinia/i18n 0.6.0 → 0.7.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/CHANGELOG.md +110 -1
- package/README.md +825 -118
- package/cli/rivinia-i18n-keys.mjs +402 -2
- package/fesm2022/rivinia-i18n-ui.mjs +366 -0
- package/fesm2022/rivinia-i18n-ui.mjs.map +1 -0
- package/fesm2022/rivinia-i18n.mjs +30 -4
- package/fesm2022/rivinia-i18n.mjs.map +1 -1
- package/package.json +5 -1
- package/types/rivinia-i18n-ui.d.ts +112 -0
- package/types/rivinia-i18n.d.ts +66 -11
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, Directive, TemplateRef, ViewContainerRef, computed, contentChild, input, isDevMode, output, viewChild } from "@angular/core";
|
|
3
|
+
const cache = /* @__PURE__ */ new Map();
|
|
4
|
+
function languageName(entry) {
|
|
5
|
+
if (entry.nativeName) return entry.nativeName;
|
|
6
|
+
const locale = entry.locale ?? entry.id;
|
|
7
|
+
const key = `${locale}\u0000${entry.id}`;
|
|
8
|
+
const cached = cache.get(key);
|
|
9
|
+
if (cached !== void 0) return cached;
|
|
10
|
+
let name = entry.id;
|
|
11
|
+
if (typeof Intl !== "undefined" && typeof Intl.DisplayNames === "function") try {
|
|
12
|
+
name = new Intl.DisplayNames([locale], { type: "language" }).of(entry.id) ?? entry.id;
|
|
13
|
+
} catch {
|
|
14
|
+
name = entry.id;
|
|
15
|
+
}
|
|
16
|
+
cache.set(key, name);
|
|
17
|
+
return name;
|
|
18
|
+
}
|
|
19
|
+
var RiviniaLanguageTrigger = class RiviniaLanguageTrigger {
|
|
20
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
21
|
+
minVersion: "12.0.0",
|
|
22
|
+
version: "22.2.3",
|
|
23
|
+
ngImport: i0,
|
|
24
|
+
type: RiviniaLanguageTrigger,
|
|
25
|
+
deps: [],
|
|
26
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
27
|
+
});
|
|
28
|
+
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
29
|
+
minVersion: "14.0.0",
|
|
30
|
+
version: "22.2.3",
|
|
31
|
+
type: RiviniaLanguageTrigger,
|
|
32
|
+
isStandalone: true,
|
|
33
|
+
selector: "[rvLanguageTrigger]",
|
|
34
|
+
ngImport: i0
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
38
|
+
minVersion: "12.0.0",
|
|
39
|
+
version: "22.2.3",
|
|
40
|
+
ngImport: i0,
|
|
41
|
+
type: RiviniaLanguageTrigger,
|
|
42
|
+
decorators: [{
|
|
43
|
+
type: Directive,
|
|
44
|
+
args: [{ selector: "[rvLanguageTrigger]" }]
|
|
45
|
+
}]
|
|
46
|
+
});
|
|
47
|
+
var RiviniaLanguageToggle = class RiviniaLanguageToggle {
|
|
48
|
+
manager = input(...ngDevMode ? [void 0, { debugName: "manager" }] : /* istanbul ignore next */ []);
|
|
49
|
+
languages = input([], ...ngDevMode ? [{ debugName: "languages" }] : /* istanbul ignore next */ []);
|
|
50
|
+
current = input(...ngDevMode ? [void 0, { debugName: "current" }] : /* istanbul ignore next */ []);
|
|
51
|
+
label = input(...ngDevMode ? [void 0, { debugName: "label" }] : /* istanbul ignore next */ []);
|
|
52
|
+
busy = input(false, ...ngDevMode ? [{ debugName: "busy" }] : /* istanbul ignore next */ []);
|
|
53
|
+
disabled = input(false, ...ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []);
|
|
54
|
+
icon = input(null, ...ngDevMode ? [{ debugName: "icon" }] : /* istanbul ignore next */ []);
|
|
55
|
+
languageChange = output();
|
|
56
|
+
template = contentChild(RiviniaLanguageTrigger, {
|
|
57
|
+
...ngDevMode ? { debugName: "template" } : /* istanbul ignore next */ {},
|
|
58
|
+
read: TemplateRef
|
|
59
|
+
});
|
|
60
|
+
slot = viewChild("slot", {
|
|
61
|
+
...ngDevMode ? { debugName: "slot" } : /* istanbul ignore next */ {},
|
|
62
|
+
read: ViewContainerRef
|
|
63
|
+
});
|
|
64
|
+
iconSlot = viewChild("iconSlot", {
|
|
65
|
+
...ngDevMode ? { debugName: "iconSlot" } : /* istanbul ignore next */ {},
|
|
66
|
+
read: ViewContainerRef
|
|
67
|
+
});
|
|
68
|
+
sourceLanguages = computed(() => this.manager()?.languages() ?? this.languages(), ...ngDevMode ? [{ debugName: "sourceLanguages" }] : /* istanbul ignore next */ []);
|
|
69
|
+
languageCount = computed(() => this.sourceLanguages().length, ...ngDevMode ? [{ debugName: "languageCount" }] : /* istanbul ignore next */ []);
|
|
70
|
+
manyLanguages = computed(() => this.languageCount() >= 3, ...ngDevMode ? [{ debugName: "manyLanguages" }] : /* istanbul ignore next */ []);
|
|
71
|
+
currentId = computed(() => this.manager()?.currentLanguage() ?? this.current() ?? "", ...ngDevMode ? [{ debugName: "currentId" }] : /* istanbul ignore next */ []);
|
|
72
|
+
target = computed(() => {
|
|
73
|
+
const languages = this.sourceLanguages();
|
|
74
|
+
if (languages.length < 2) return;
|
|
75
|
+
const current = this.currentId();
|
|
76
|
+
return languages.find((language) => language.id !== current);
|
|
77
|
+
}, ...ngDevMode ? [{ debugName: "target" }] : /* istanbul ignore next */ []);
|
|
78
|
+
isBusy = computed(() => {
|
|
79
|
+
const manager = this.manager();
|
|
80
|
+
return manager ? manager.loadingState() === "loading" : this.busy();
|
|
81
|
+
}, ...ngDevMode ? [{ debugName: "isBusy" }] : /* istanbul ignore next */ []);
|
|
82
|
+
visibleName = computed(() => {
|
|
83
|
+
const target = this.target();
|
|
84
|
+
return target ? languageName(target) : "";
|
|
85
|
+
}, ...ngDevMode ? [{ debugName: "visibleName" }] : /* istanbul ignore next */ []);
|
|
86
|
+
accessibleName = computed(() => {
|
|
87
|
+
const name = this.visibleName();
|
|
88
|
+
const label = this.label();
|
|
89
|
+
return label ? `${name}, ${label}` : name;
|
|
90
|
+
}, ...ngDevMode ? [{ debugName: "accessibleName" }] : /* istanbul ignore next */ []);
|
|
91
|
+
dataLanguages = computed(() => {
|
|
92
|
+
const count = this.languageCount();
|
|
93
|
+
if (count === 2) return "2";
|
|
94
|
+
return count >= 3 ? "many" : null;
|
|
95
|
+
}, ...ngDevMode ? [{ debugName: "dataLanguages" }] : /* istanbul ignore next */ []);
|
|
96
|
+
rendered;
|
|
97
|
+
renderedIcon = null;
|
|
98
|
+
warnedMany = false;
|
|
99
|
+
warnedLabel = false;
|
|
100
|
+
ngAfterViewChecked() {
|
|
101
|
+
this.warn();
|
|
102
|
+
this.renderIcon();
|
|
103
|
+
this.renderTrigger();
|
|
104
|
+
}
|
|
105
|
+
async activate(targetId) {
|
|
106
|
+
if (this.disabled() || this.languageCount() !== 2 || this.isBusy()) return;
|
|
107
|
+
if (targetId === this.currentId()) return;
|
|
108
|
+
const manager = this.manager();
|
|
109
|
+
if (!manager) {
|
|
110
|
+
this.languageChange.emit(targetId);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
await manager.setLanguageAsync(targetId);
|
|
114
|
+
if (manager.currentLanguage() === targetId) this.languageChange.emit(targetId);
|
|
115
|
+
}
|
|
116
|
+
warn() {
|
|
117
|
+
if (!isDevMode()) return;
|
|
118
|
+
if (!this.warnedMany && this.manyLanguages()) {
|
|
119
|
+
this.warnedMany = true;
|
|
120
|
+
console.warn("rv-language-toggle: 3 or more languages. The toggle switches between exactly two; use a select or a menu. The button is aria-disabled, not disabled.");
|
|
121
|
+
}
|
|
122
|
+
if (!this.warnedLabel && this.template() && !this.label()) {
|
|
123
|
+
this.warnedLabel = true;
|
|
124
|
+
console.warn("rv-language-toggle: label is missing while rvLanguageTrigger is used. The accessible name falls back to the language name alone.");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
renderIcon() {
|
|
128
|
+
const slot = this.iconSlot();
|
|
129
|
+
if (!slot) {
|
|
130
|
+
this.renderedIcon = null;
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const template = this.icon();
|
|
134
|
+
if (template === this.renderedIcon) return;
|
|
135
|
+
slot.clear();
|
|
136
|
+
if (template) slot.createEmbeddedView(template);
|
|
137
|
+
this.renderedIcon = template;
|
|
138
|
+
}
|
|
139
|
+
renderTrigger() {
|
|
140
|
+
const slot = this.slot();
|
|
141
|
+
const template = this.template();
|
|
142
|
+
const target = this.target();
|
|
143
|
+
const busy = this.isBusy();
|
|
144
|
+
if (!slot || !template || !target) {
|
|
145
|
+
this.rendered = void 0;
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const rendered = this.rendered;
|
|
149
|
+
if (rendered && rendered.template === template && rendered.target === target && rendered.busy === busy) return;
|
|
150
|
+
slot.clear();
|
|
151
|
+
slot.createEmbeddedView(template, {
|
|
152
|
+
$implicit: target,
|
|
153
|
+
busy
|
|
154
|
+
});
|
|
155
|
+
this.rendered = {
|
|
156
|
+
template,
|
|
157
|
+
target,
|
|
158
|
+
busy
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
162
|
+
minVersion: "12.0.0",
|
|
163
|
+
version: "22.2.3",
|
|
164
|
+
ngImport: i0,
|
|
165
|
+
type: RiviniaLanguageToggle,
|
|
166
|
+
deps: [],
|
|
167
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
168
|
+
});
|
|
169
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
170
|
+
minVersion: "17.0.0",
|
|
171
|
+
version: "22.2.3",
|
|
172
|
+
type: RiviniaLanguageToggle,
|
|
173
|
+
isStandalone: true,
|
|
174
|
+
selector: "rv-language-toggle",
|
|
175
|
+
inputs: {
|
|
176
|
+
manager: {
|
|
177
|
+
classPropertyName: "manager",
|
|
178
|
+
publicName: "manager",
|
|
179
|
+
isSignal: true,
|
|
180
|
+
isRequired: false,
|
|
181
|
+
transformFunction: null
|
|
182
|
+
},
|
|
183
|
+
languages: {
|
|
184
|
+
classPropertyName: "languages",
|
|
185
|
+
publicName: "languages",
|
|
186
|
+
isSignal: true,
|
|
187
|
+
isRequired: false,
|
|
188
|
+
transformFunction: null
|
|
189
|
+
},
|
|
190
|
+
current: {
|
|
191
|
+
classPropertyName: "current",
|
|
192
|
+
publicName: "current",
|
|
193
|
+
isSignal: true,
|
|
194
|
+
isRequired: false,
|
|
195
|
+
transformFunction: null
|
|
196
|
+
},
|
|
197
|
+
label: {
|
|
198
|
+
classPropertyName: "label",
|
|
199
|
+
publicName: "label",
|
|
200
|
+
isSignal: true,
|
|
201
|
+
isRequired: false,
|
|
202
|
+
transformFunction: null
|
|
203
|
+
},
|
|
204
|
+
busy: {
|
|
205
|
+
classPropertyName: "busy",
|
|
206
|
+
publicName: "busy",
|
|
207
|
+
isSignal: true,
|
|
208
|
+
isRequired: false,
|
|
209
|
+
transformFunction: null
|
|
210
|
+
},
|
|
211
|
+
disabled: {
|
|
212
|
+
classPropertyName: "disabled",
|
|
213
|
+
publicName: "disabled",
|
|
214
|
+
isSignal: true,
|
|
215
|
+
isRequired: false,
|
|
216
|
+
transformFunction: null
|
|
217
|
+
},
|
|
218
|
+
icon: {
|
|
219
|
+
classPropertyName: "icon",
|
|
220
|
+
publicName: "icon",
|
|
221
|
+
isSignal: true,
|
|
222
|
+
isRequired: false,
|
|
223
|
+
transformFunction: null
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
outputs: { languageChange: "languageChange" },
|
|
227
|
+
host: { properties: {
|
|
228
|
+
"attr.data-languages": "dataLanguages()",
|
|
229
|
+
"attr.data-busy": "languageCount() >= 2 && isBusy() ? \"\" : null",
|
|
230
|
+
"attr.data-disabled": "languageCount() >= 2 && disabled() ? \"\" : null"
|
|
231
|
+
} },
|
|
232
|
+
queries: [{
|
|
233
|
+
propertyName: "template",
|
|
234
|
+
first: true,
|
|
235
|
+
predicate: RiviniaLanguageTrigger,
|
|
236
|
+
descendants: true,
|
|
237
|
+
read: TemplateRef,
|
|
238
|
+
isSignal: true
|
|
239
|
+
}],
|
|
240
|
+
viewQueries: [{
|
|
241
|
+
propertyName: "slot",
|
|
242
|
+
first: true,
|
|
243
|
+
predicate: ["slot"],
|
|
244
|
+
descendants: true,
|
|
245
|
+
read: ViewContainerRef,
|
|
246
|
+
isSignal: true
|
|
247
|
+
}, {
|
|
248
|
+
propertyName: "iconSlot",
|
|
249
|
+
first: true,
|
|
250
|
+
predicate: ["iconSlot"],
|
|
251
|
+
descendants: true,
|
|
252
|
+
read: ViewContainerRef,
|
|
253
|
+
isSignal: true
|
|
254
|
+
}],
|
|
255
|
+
ngImport: i0,
|
|
256
|
+
template: "@if (target(); as target) {\n <button\n type=\"button\"\n class=\"rv-language-toggle__button\"\n [attr.lang]=\"target.id\"\n [attr.dir]=\"target.dir ?? 'auto'\"\n [attr.aria-label]=\"accessibleName()\"\n [attr.aria-busy]=\"isBusy() ? 'true' : null\"\n [attr.aria-disabled]=\"manyLanguages() ? 'true' : null\"\n [disabled]=\"disabled()\"\n (click)=\"activate(target.id)\"\n >\n <span class=\"rv-language-toggle__icon\">\n <ng-container #iconSlot />\n @if (!icon()) {\n <!--\n The default mark: a globe with the two exchange arrows. The latitudes\n of the source artwork are dropped and the meridian narrowed, because\n below ~22px the original drawing fills in at this stroke weight.\n -->\n <svg\n viewBox=\"0 0 64 64\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"4.4\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n aria-hidden=\"true\"\n focusable=\"false\"\n >\n <circle cx=\"32\" cy=\"32\" r=\"18\" />\n <ellipse cx=\"32\" cy=\"32\" rx=\"7.6\" ry=\"18\" />\n <path d=\"M14 32h36\" />\n <path d=\"M19 9.5A25 25 0 0 1 49 13\" />\n <path d=\"m42.5 13.5 6.8-.5-.5-6.5\" />\n <path d=\"M45 54.5A25 25 0 0 1 15 51\" />\n <path d=\"m21.5 50.5-6.8.5.5 6.5\" />\n </svg>\n }\n </span>\n\n @if (template()) {\n <ng-container #slot />\n } @else {\n <span class=\"rv-language-toggle__name\">{{ visibleName() }}</span>\n }\n </button>\n}\n",
|
|
257
|
+
styles: [":host{display:inline-block;font-family:var(--rv-i18n-toggle-font, var(--rv-font, inherit))}.rv-language-toggle__button{display:inline-flex;align-items:center;gap:var(--rv-i18n-toggle-gap, .5rem);padding:var(--rv-i18n-toggle-padding, .5rem .75rem);font:inherit;font-size:var(--rv-i18n-toggle-size, .875rem);line-height:1.2;color:var(--rv-i18n-toggle-fg, var(--rv-fg, currentColor));background-color:var(--rv-i18n-toggle-bg, var(--rv-bg, transparent));border:1px solid var(--rv-i18n-toggle-border, var(--rv-border, currentColor));border-radius:var(--rv-i18n-toggle-radius, var(--rv-radius, .5rem));box-shadow:var(--rv-i18n-toggle-shadow, var(--rv-shadow, none));cursor:pointer}.rv-language-toggle__button:hover{background-color:var( --rv-i18n-toggle-hover-bg, color-mix(in srgb, currentColor 8%, var(--rv-i18n-toggle-bg, var(--rv-bg, transparent))) )}.rv-language-toggle__button:active{background-color:var( --rv-i18n-toggle-active-bg, color-mix(in srgb, currentColor 16%, var(--rv-i18n-toggle-bg, var(--rv-bg, transparent))) )}.rv-language-toggle__button:focus-visible{outline:var(--rv-i18n-toggle-focus-ring, 2px solid currentColor);outline-offset:var(--rv-i18n-toggle-focus-offset, .125rem)}:host([data-busy]) .rv-language-toggle__button{cursor:progress}:host([data-disabled]) .rv-language-toggle__button{opacity:var(--rv-i18n-toggle-disabled-opacity, .45);cursor:not-allowed}:host([data-languages=\"many\"]) .rv-language-toggle__button[aria-disabled=true]{cursor:not-allowed}.rv-language-toggle__icon{display:grid;place-items:stretch;flex:none;width:var(--rv-i18n-toggle-icon-size, 1.5em);height:var(--rv-i18n-toggle-icon-size, 1.5em)}.rv-language-toggle__name{white-space:nowrap}\n"],
|
|
258
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
262
|
+
minVersion: "12.0.0",
|
|
263
|
+
version: "22.2.3",
|
|
264
|
+
ngImport: i0,
|
|
265
|
+
type: RiviniaLanguageToggle,
|
|
266
|
+
decorators: [{
|
|
267
|
+
type: Component,
|
|
268
|
+
args: [{
|
|
269
|
+
selector: "rv-language-toggle",
|
|
270
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
271
|
+
host: {
|
|
272
|
+
"[attr.data-languages]": "dataLanguages()",
|
|
273
|
+
"[attr.data-busy]": "languageCount() >= 2 && isBusy() ? \"\" : null",
|
|
274
|
+
"[attr.data-disabled]": "languageCount() >= 2 && disabled() ? \"\" : null"
|
|
275
|
+
},
|
|
276
|
+
template: "@if (target(); as target) {\n <button\n type=\"button\"\n class=\"rv-language-toggle__button\"\n [attr.lang]=\"target.id\"\n [attr.dir]=\"target.dir ?? 'auto'\"\n [attr.aria-label]=\"accessibleName()\"\n [attr.aria-busy]=\"isBusy() ? 'true' : null\"\n [attr.aria-disabled]=\"manyLanguages() ? 'true' : null\"\n [disabled]=\"disabled()\"\n (click)=\"activate(target.id)\"\n >\n <span class=\"rv-language-toggle__icon\">\n <ng-container #iconSlot />\n @if (!icon()) {\n <!--\n The default mark: a globe with the two exchange arrows. The latitudes\n of the source artwork are dropped and the meridian narrowed, because\n below ~22px the original drawing fills in at this stroke weight.\n -->\n <svg\n viewBox=\"0 0 64 64\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"4.4\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n aria-hidden=\"true\"\n focusable=\"false\"\n >\n <circle cx=\"32\" cy=\"32\" r=\"18\" />\n <ellipse cx=\"32\" cy=\"32\" rx=\"7.6\" ry=\"18\" />\n <path d=\"M14 32h36\" />\n <path d=\"M19 9.5A25 25 0 0 1 49 13\" />\n <path d=\"m42.5 13.5 6.8-.5-.5-6.5\" />\n <path d=\"M45 54.5A25 25 0 0 1 15 51\" />\n <path d=\"m21.5 50.5-6.8.5.5 6.5\" />\n </svg>\n }\n </span>\n\n @if (template()) {\n <ng-container #slot />\n } @else {\n <span class=\"rv-language-toggle__name\">{{ visibleName() }}</span>\n }\n </button>\n}\n",
|
|
277
|
+
styles: [":host{display:inline-block;font-family:var(--rv-i18n-toggle-font, var(--rv-font, inherit))}.rv-language-toggle__button{display:inline-flex;align-items:center;gap:var(--rv-i18n-toggle-gap, .5rem);padding:var(--rv-i18n-toggle-padding, .5rem .75rem);font:inherit;font-size:var(--rv-i18n-toggle-size, .875rem);line-height:1.2;color:var(--rv-i18n-toggle-fg, var(--rv-fg, currentColor));background-color:var(--rv-i18n-toggle-bg, var(--rv-bg, transparent));border:1px solid var(--rv-i18n-toggle-border, var(--rv-border, currentColor));border-radius:var(--rv-i18n-toggle-radius, var(--rv-radius, .5rem));box-shadow:var(--rv-i18n-toggle-shadow, var(--rv-shadow, none));cursor:pointer}.rv-language-toggle__button:hover{background-color:var( --rv-i18n-toggle-hover-bg, color-mix(in srgb, currentColor 8%, var(--rv-i18n-toggle-bg, var(--rv-bg, transparent))) )}.rv-language-toggle__button:active{background-color:var( --rv-i18n-toggle-active-bg, color-mix(in srgb, currentColor 16%, var(--rv-i18n-toggle-bg, var(--rv-bg, transparent))) )}.rv-language-toggle__button:focus-visible{outline:var(--rv-i18n-toggle-focus-ring, 2px solid currentColor);outline-offset:var(--rv-i18n-toggle-focus-offset, .125rem)}:host([data-busy]) .rv-language-toggle__button{cursor:progress}:host([data-disabled]) .rv-language-toggle__button{opacity:var(--rv-i18n-toggle-disabled-opacity, .45);cursor:not-allowed}:host([data-languages=\"many\"]) .rv-language-toggle__button[aria-disabled=true]{cursor:not-allowed}.rv-language-toggle__icon{display:grid;place-items:stretch;flex:none;width:var(--rv-i18n-toggle-icon-size, 1.5em);height:var(--rv-i18n-toggle-icon-size, 1.5em)}.rv-language-toggle__name{white-space:nowrap}\n"]
|
|
278
|
+
}]
|
|
279
|
+
}],
|
|
280
|
+
propDecorators: {
|
|
281
|
+
manager: [{
|
|
282
|
+
type: i0.Input,
|
|
283
|
+
args: [{
|
|
284
|
+
isSignal: true,
|
|
285
|
+
alias: "manager",
|
|
286
|
+
required: false
|
|
287
|
+
}]
|
|
288
|
+
}],
|
|
289
|
+
languages: [{
|
|
290
|
+
type: i0.Input,
|
|
291
|
+
args: [{
|
|
292
|
+
isSignal: true,
|
|
293
|
+
alias: "languages",
|
|
294
|
+
required: false
|
|
295
|
+
}]
|
|
296
|
+
}],
|
|
297
|
+
current: [{
|
|
298
|
+
type: i0.Input,
|
|
299
|
+
args: [{
|
|
300
|
+
isSignal: true,
|
|
301
|
+
alias: "current",
|
|
302
|
+
required: false
|
|
303
|
+
}]
|
|
304
|
+
}],
|
|
305
|
+
label: [{
|
|
306
|
+
type: i0.Input,
|
|
307
|
+
args: [{
|
|
308
|
+
isSignal: true,
|
|
309
|
+
alias: "label",
|
|
310
|
+
required: false
|
|
311
|
+
}]
|
|
312
|
+
}],
|
|
313
|
+
busy: [{
|
|
314
|
+
type: i0.Input,
|
|
315
|
+
args: [{
|
|
316
|
+
isSignal: true,
|
|
317
|
+
alias: "busy",
|
|
318
|
+
required: false
|
|
319
|
+
}]
|
|
320
|
+
}],
|
|
321
|
+
disabled: [{
|
|
322
|
+
type: i0.Input,
|
|
323
|
+
args: [{
|
|
324
|
+
isSignal: true,
|
|
325
|
+
alias: "disabled",
|
|
326
|
+
required: false
|
|
327
|
+
}]
|
|
328
|
+
}],
|
|
329
|
+
icon: [{
|
|
330
|
+
type: i0.Input,
|
|
331
|
+
args: [{
|
|
332
|
+
isSignal: true,
|
|
333
|
+
alias: "icon",
|
|
334
|
+
required: false
|
|
335
|
+
}]
|
|
336
|
+
}],
|
|
337
|
+
languageChange: [{
|
|
338
|
+
type: i0.Output,
|
|
339
|
+
args: ["languageChange"]
|
|
340
|
+
}],
|
|
341
|
+
template: [{
|
|
342
|
+
type: i0.ContentChild,
|
|
343
|
+
args: [i0.forwardRef(() => RiviniaLanguageTrigger), {
|
|
344
|
+
read: TemplateRef,
|
|
345
|
+
isSignal: true
|
|
346
|
+
}]
|
|
347
|
+
}],
|
|
348
|
+
slot: [{
|
|
349
|
+
type: i0.ViewChild,
|
|
350
|
+
args: ["slot", {
|
|
351
|
+
read: ViewContainerRef,
|
|
352
|
+
isSignal: true
|
|
353
|
+
}]
|
|
354
|
+
}],
|
|
355
|
+
iconSlot: [{
|
|
356
|
+
type: i0.ViewChild,
|
|
357
|
+
args: ["iconSlot", {
|
|
358
|
+
read: ViewContainerRef,
|
|
359
|
+
isSignal: true
|
|
360
|
+
}]
|
|
361
|
+
}]
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
export { RiviniaLanguageToggle, RiviniaLanguageTrigger };
|
|
365
|
+
|
|
366
|
+
//# sourceMappingURL=rivinia-i18n-ui.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rivinia-i18n-ui.mjs","names":[],"sources":["../../../projects/i18n/ui/src/lib/utils/language-name.ts","../../../projects/i18n/ui/src/lib/components/language-toggle/language-trigger.directive.ts","../../../projects/i18n/ui/src/lib/components/language-toggle/language-toggle.ts","../../../projects/i18n/ui/src/lib/components/language-toggle/language-toggle.html"],"sourcesContent":["import type { LanguageLike } from '../models/language-view';\n\n/** One lookup per (locale, id); the key cannot collide because of the NUL separator. */\nconst cache = new Map<string, string>();\n\n/** Resolution order: `nativeName` → `Intl.DisplayNames` → the raw id, never empty. */\nexport function languageName(entry: LanguageLike): string {\n if (entry.nativeName) {\n return entry.nativeName;\n }\n\n const locale = entry.locale ?? entry.id;\n const key = `${locale}\\u0000${entry.id}`;\n const cached = cache.get(key);\n if (cached !== undefined) {\n return cached;\n }\n\n let name = entry.id;\n if (typeof Intl !== 'undefined' && typeof Intl.DisplayNames === 'function') {\n try {\n name = new Intl.DisplayNames([locale], { type: 'language' }).of(entry.id) ?? entry.id;\n } catch {\n name = entry.id;\n }\n }\n\n cache.set(key, name);\n return name;\n}\n","import { Directive } from '@angular/core';\nimport type { LanguageLike } from '../../models/language-view';\n\nexport interface RiviniaLanguageTriggerContext {\n $implicit: LanguageLike;\n busy: boolean;\n}\n\n/**\n * Marks the `<ng-template>` rendered inside the button in place of the default\n * name span. The toggle captures it with `contentChild(..., { read: TemplateRef })`\n * and renders it through `ViewContainerRef`, so the template is created only when\n * the button is — and never on the server beyond the same pass.\n */\n@Directive({ selector: '[rvLanguageTrigger]' })\nexport class RiviniaLanguageTrigger {}\n","import {\n ChangeDetectionStrategy,\n Component,\n TemplateRef,\n ViewContainerRef,\n computed,\n contentChild,\n input,\n isDevMode,\n output,\n viewChild,\n} from '@angular/core';\nimport type { LanguageLike, RiviniaLanguageManager } from '../../models/language-view';\nimport { languageName } from '../../utils/language-name';\nimport { RiviniaLanguageTrigger } from './language-trigger.directive';\nimport type { RiviniaLanguageTriggerContext } from './language-trigger.directive';\n\n/**\n * The language toggle: one inner `<button>` that switches to the other language\n * of a two-language manager (or presentational pair). The host is the API; the\n * button owns the name, `lang` and `dir`.\n */\n@Component({\n selector: 'rv-language-toggle',\n changeDetection: ChangeDetectionStrategy.OnPush,\n templateUrl: './language-toggle.html',\n styleUrl: './language-toggle.css',\n host: {\n '[attr.data-languages]': 'dataLanguages()',\n '[attr.data-busy]': 'languageCount() >= 2 && isBusy() ? \"\" : null',\n '[attr.data-disabled]': 'languageCount() >= 2 && disabled() ? \"\" : null',\n },\n})\nexport class RiviniaLanguageToggle {\n readonly manager = input<RiviniaLanguageManager>();\n readonly languages = input<readonly LanguageLike[]>([]);\n readonly current = input<string>();\n readonly label = input<string>();\n readonly busy = input(false);\n readonly disabled = input(false);\n /** Replaces the default globe. Rendered as-is, so size it with the icon box. */\n readonly icon = input<TemplateRef<unknown> | null>(null);\n\n readonly languageChange = output<string>();\n\n readonly template = contentChild(RiviniaLanguageTrigger, { read: TemplateRef });\n\n private readonly slot = viewChild('slot', { read: ViewContainerRef });\n private readonly iconSlot = viewChild('iconSlot', { read: ViewContainerRef });\n\n private readonly sourceLanguages = computed<readonly LanguageLike[]>(\n () => this.manager()?.languages() ?? this.languages(),\n );\n\n readonly languageCount = computed(() => this.sourceLanguages().length);\n\n readonly manyLanguages = computed(() => this.languageCount() >= 3);\n\n private readonly currentId = computed(\n () => this.manager()?.currentLanguage() ?? this.current() ?? '',\n );\n\n /** The language activating the button switches to; `undefined` when nothing renders. */\n readonly target = computed<LanguageLike | undefined>(() => {\n const languages = this.sourceLanguages();\n if (languages.length < 2) {\n return undefined;\n }\n const current = this.currentId();\n return languages.find((language) => language.id !== current);\n });\n\n readonly isBusy = computed(() => {\n const manager = this.manager();\n return manager ? manager.loadingState() === 'loading' : this.busy();\n });\n\n readonly visibleName = computed(() => {\n const target = this.target();\n return target ? languageName(target) : '';\n });\n\n readonly accessibleName = computed(() => {\n const name = this.visibleName();\n const label = this.label();\n return label ? `${name}, ${label}` : name;\n });\n\n readonly dataLanguages = computed(() => {\n const count = this.languageCount();\n if (count === 2) {\n return '2';\n }\n return count >= 3 ? 'many' : null;\n });\n\n private rendered:\n | { template: TemplateRef<unknown>; target: LanguageLike; busy: boolean }\n | undefined;\n private renderedIcon: TemplateRef<unknown> | null = null;\n private warnedMany = false;\n private warnedLabel = false;\n\n ngAfterViewChecked(): void {\n this.warn();\n this.renderIcon();\n this.renderTrigger();\n }\n\n async activate(targetId: string): Promise<void> {\n if (this.disabled() || this.languageCount() !== 2 || this.isBusy()) {\n return;\n }\n if (targetId === this.currentId()) {\n return;\n }\n\n const manager = this.manager();\n if (!manager) {\n this.languageChange.emit(targetId);\n return;\n }\n\n await manager.setLanguageAsync(targetId);\n if (manager.currentLanguage() === targetId) {\n this.languageChange.emit(targetId);\n }\n }\n\n private warn(): void {\n if (!isDevMode()) {\n return;\n }\n if (!this.warnedMany && this.manyLanguages()) {\n this.warnedMany = true;\n console.warn(\n 'rv-language-toggle: 3 or more languages. The toggle switches between exactly two; use a select or a menu. The button is aria-disabled, not disabled.',\n );\n }\n if (!this.warnedLabel && this.template() && !this.label()) {\n this.warnedLabel = true;\n console.warn(\n 'rv-language-toggle: label is missing while rvLanguageTrigger is used. The accessible name falls back to the language name alone.',\n );\n }\n }\n\n /*\n * The embedded view is created in a view hook, not in an effect, so the\n * template is in the DOM by the end of the same change-detection pass\n * (and during server rendering, where render hooks never run).\n */\n private renderIcon(): void {\n const slot = this.iconSlot();\n if (!slot) {\n this.renderedIcon = null;\n return;\n }\n const template = this.icon();\n if (template === this.renderedIcon) {\n return;\n }\n slot.clear();\n if (template) {\n slot.createEmbeddedView(template);\n }\n this.renderedIcon = template;\n }\n\n private renderTrigger(): void {\n const slot = this.slot();\n const template = this.template();\n const target = this.target();\n const busy = this.isBusy();\n\n if (!slot || !template || !target) {\n this.rendered = undefined;\n return;\n }\n const rendered = this.rendered;\n if (rendered && rendered.template === template && rendered.target === target && rendered.busy === busy) {\n return;\n }\n\n slot.clear();\n slot.createEmbeddedView<RiviniaLanguageTriggerContext>(template, { $implicit: target, busy });\n this.rendered = { template, target, busy };\n }\n}\n","@if (target(); as target) {\n <button\n type=\"button\"\n class=\"rv-language-toggle__button\"\n [attr.lang]=\"target.id\"\n [attr.dir]=\"target.dir ?? 'auto'\"\n [attr.aria-label]=\"accessibleName()\"\n [attr.aria-busy]=\"isBusy() ? 'true' : null\"\n [attr.aria-disabled]=\"manyLanguages() ? 'true' : null\"\n [disabled]=\"disabled()\"\n (click)=\"activate(target.id)\"\n >\n <span class=\"rv-language-toggle__icon\">\n <ng-container #iconSlot />\n @if (!icon()) {\n <!--\n The default mark: a globe with the two exchange arrows. The latitudes\n of the source artwork are dropped and the meridian narrowed, because\n below ~22px the original drawing fills in at this stroke weight.\n -->\n <svg\n viewBox=\"0 0 64 64\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"4.4\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n aria-hidden=\"true\"\n focusable=\"false\"\n >\n <circle cx=\"32\" cy=\"32\" r=\"18\" />\n <ellipse cx=\"32\" cy=\"32\" rx=\"7.6\" ry=\"18\" />\n <path d=\"M14 32h36\" />\n <path d=\"M19 9.5A25 25 0 0 1 49 13\" />\n <path d=\"m42.5 13.5 6.8-.5-.5-6.5\" />\n <path d=\"M45 54.5A25 25 0 0 1 15 51\" />\n <path d=\"m21.5 50.5-6.8.5.5 6.5\" />\n </svg>\n }\n </span>\n\n @if (template()) {\n <ng-container #slot />\n } @else {\n <span class=\"rv-language-toggle__name\">{{ visibleName() }}</span>\n }\n </button>\n}\n"],"mappings":";;AAGA,MAAM,wBAAQ,IAAI,IAAG;AAGrB,SAAgB,aAAa,OAAmB;CAC9C,IAAI,MAAM,YACR,OAAO,MAAM;CAGf,MAAM,SAAS,MAAM,UAAU,MAAM;CACrC,MAAM,MAAM,GAAG,OAAM,QAAS,MAAM;CACpC,MAAM,SAAS,MAAM,IAAI,GAAG;CAC5B,IAAI,WAAW,QACb,OAAO;CAGT,IAAI,OAAO,MAAM;CACjB,IAAI,OAAO,SAAS,eAAe,OAAO,KAAK,iBAAiB,YAC9D,IAAI;EACF,OAAO,IAAI,KAAK,aAAa,CAAC,MAAM,GAAG,EAAE,MAAM,WAAU,CAAE,CAAC,CAAC,GAAG,MAAM,EAAE,KAAK,MAAM;CACrF,QAAQ;EACN,OAAO,MAAM;CACf;CAGF,MAAM,IAAI,KAAK,IAAI;CACnB,OAAO;AACT;ACdA,IAAa,yBAAb,MAAa,uBAAsB;CAAtB,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAsB,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAtB,OAAA,OAAA,GAAA,qBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,MAAA;EAAsB,cAAA;EAAA,UAAA;EAAA,UAAA;CAAA,CAAA;;AAAtB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAsB,YAAA,CAAA;EADlC,MAAA;EAAU,MAAA,CAAA,EAAE,UA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CAAA;EAAA,MAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,gBAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA,gBAAA;EAAA,CAAA;EAAA,UAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA,GAAA,iBAAA,sBAAsB,GAAA;IAAI,MAAM;IAAa,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,MAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAE5C,QAAM;IAAI,MAAM;IAAkB,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,UAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAC9B,YAAU;IAAI,MAAM;IAAkB,UAAA;GAAA,CAAA;EAAA,CAAA;CAAA;AAAA,CAAA"}
|
|
@@ -1096,11 +1096,12 @@ var RiviniaI18n = class RiviniaI18n {
|
|
|
1096
1096
|
});
|
|
1097
1097
|
loaderContext = createLoaderContext(this._request ?? null, this._doc);
|
|
1098
1098
|
_languages = signal(this._config.languages, ...ngDevMode ? [{ debugName: "_languages" }] : /* istanbul ignore next */ []);
|
|
1099
|
+
_defaultLanguageId = resolveDefaultLanguage(this._config);
|
|
1099
1100
|
_languageStorage = new LanguageStorage({
|
|
1100
1101
|
key: this._config.storageKey ?? "rivinia.i18n.language",
|
|
1101
1102
|
strategy: this._config.storageStrategy ?? "local",
|
|
1102
1103
|
languages: () => this._languages(),
|
|
1103
|
-
defaultLanguage: this.
|
|
1104
|
+
defaultLanguage: this._defaultLanguageId,
|
|
1104
1105
|
detectBrowser: this._config.detectBrowser ?? false,
|
|
1105
1106
|
document: this._doc,
|
|
1106
1107
|
request: this._request ?? null,
|
|
@@ -1108,12 +1109,23 @@ var RiviniaI18n = class RiviniaI18n {
|
|
|
1108
1109
|
browserLanguages
|
|
1109
1110
|
});
|
|
1110
1111
|
_currentLanguageId = signal(this._languageStorage.resolveInitialLanguage(), ...ngDevMode ? [{ debugName: "_currentLanguageId" }] : /* istanbul ignore next */ []);
|
|
1112
|
+
_warnedLoadErrors = /* @__PURE__ */ new Set();
|
|
1113
|
+
_onDictionaryLoadError = (language, error) => {
|
|
1114
|
+
if (this._config.onLoadError) {
|
|
1115
|
+
this._config.onLoadError(language, error);
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
if (!(this._config.warnOnLoadError ?? isDevMode())) return;
|
|
1119
|
+
if (this._warnedLoadErrors.has(language)) return;
|
|
1120
|
+
this._warnedLoadErrors.add(language);
|
|
1121
|
+
console.error(`[rivinia/i18n] Failed to load the "${language}" dictionary — every key will render as its raw name. Pass \`onLoadError\` to handle load failures yourself.`, error);
|
|
1122
|
+
};
|
|
1111
1123
|
_store = new DictionaryStore({
|
|
1112
1124
|
loader: (context) => this._config.loader ? this._config.loader.resolve(context) : jsonLoader().resolve(context),
|
|
1113
1125
|
loaderContext: this.loaderContext,
|
|
1114
1126
|
request: this._request ?? null,
|
|
1115
1127
|
transfer: this._transfer,
|
|
1116
|
-
onLoadError: this.
|
|
1128
|
+
onLoadError: this._onDictionaryLoadError,
|
|
1117
1129
|
currentLanguage: () => this._currentLanguageId(),
|
|
1118
1130
|
fallbackLanguage: this._fallbackId,
|
|
1119
1131
|
languageIds: () => this._languages().map((l) => l.id),
|
|
@@ -1151,8 +1163,6 @@ var RiviniaI18n = class RiviniaI18n {
|
|
|
1151
1163
|
this._missingKeyReporter.clearParams();
|
|
1152
1164
|
}
|
|
1153
1165
|
constructor() {
|
|
1154
|
-
if (this._config.languages.length === 0) throw new Error("[rivinia/i18n] At least one language must be provided in the languages array.");
|
|
1155
|
-
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.`);
|
|
1156
1166
|
if (this._fallbackId !== null && !this._config.languages.some((l) => l.id === this._fallbackId)) throw new Error(`[rivinia/i18n] fallbackLanguage "${this._fallbackId}" must be one of the configured language IDs.`);
|
|
1157
1167
|
if (this._autoApplyDirection) this._direction.install(() => this.currentLanguageObject());
|
|
1158
1168
|
}
|
|
@@ -1343,6 +1353,22 @@ function normalizeKeyArgs(second, third) {
|
|
|
1343
1353
|
params: third
|
|
1344
1354
|
};
|
|
1345
1355
|
}
|
|
1356
|
+
function resolveDefaultLanguage(config) {
|
|
1357
|
+
const languages = config.languages;
|
|
1358
|
+
if (!Array.isArray(languages) || languages.length === 0) throw new Error("[rivinia/i18n] At least one language must be provided in the languages array.");
|
|
1359
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1360
|
+
languages.forEach((language, index) => {
|
|
1361
|
+
const id = language?.id;
|
|
1362
|
+
if (typeof id !== "string" || id.trim().length === 0) throw new Error(`[rivinia/i18n] language[${index}] needs a non-empty \`id\`.`);
|
|
1363
|
+
if (seen.has(id)) throw new Error(`[rivinia/i18n] Duplicate language id "${id}" in the languages array.`);
|
|
1364
|
+
seen.add(id);
|
|
1365
|
+
});
|
|
1366
|
+
const requested = config.defaultLanguage;
|
|
1367
|
+
if (requested === void 0) return languages[0].id;
|
|
1368
|
+
if (typeof requested !== "string" || requested.trim().length === 0) throw new Error(`[rivinia/i18n] defaultLanguage must be a non-empty string (received ${JSON.stringify(requested) ?? String(requested)}).`);
|
|
1369
|
+
if (!languages.some((language) => language.id === requested)) throw new Error(`[rivinia/i18n] defaultLanguage "${requested}" must be one of the configured language IDs.`);
|
|
1370
|
+
return requested;
|
|
1371
|
+
}
|
|
1346
1372
|
function provideRiviniaI18n(config) {
|
|
1347
1373
|
return makeEnvironmentProviders([{
|
|
1348
1374
|
provide: RIVINIA_I18N_CONFIG,
|