@schukai/monster 4.38.9 → 4.39.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/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/source/components/accessibility/locale-picker.mjs +561 -551
- package/source/components/accessibility/locale-select.mjs +270 -0
- package/source/components/form/select.mjs +2854 -2851
- package/source/i18n/util.mjs +149 -142
@@ -13,17 +13,17 @@
|
|
13
13
|
import { instanceSymbol } from "../../constants.mjs";
|
14
14
|
import { addAttributeToken } from "../../dom/attributes.mjs";
|
15
15
|
import {
|
16
|
-
|
17
|
-
|
16
|
+
ATTRIBUTE_ERRORMESSAGE,
|
17
|
+
ATTRIBUTE_ROLE,
|
18
18
|
} from "../../dom/constants.mjs";
|
19
19
|
import { CustomControl } from "../../dom/customcontrol.mjs";
|
20
20
|
import {
|
21
|
-
|
22
|
-
|
21
|
+
CustomElement,
|
22
|
+
updaterTransformerMethodsSymbol,
|
23
23
|
} from "../../dom/customelement.mjs";
|
24
24
|
import {
|
25
|
-
|
26
|
-
|
25
|
+
assembleMethodSymbol,
|
26
|
+
registerCustomElement,
|
27
27
|
} from "../../dom/customelement.mjs";
|
28
28
|
import { findTargetElementFromEvent } from "../../dom/events.mjs";
|
29
29
|
import { isFunction, isObject } from "../../types/is.mjs";
|
@@ -40,30 +40,35 @@ export { LocalePicker };
|
|
40
40
|
/**
|
41
41
|
* @private
|
42
42
|
* @type {symbol}
|
43
|
+
* Reference to the main picker element
|
43
44
|
*/
|
44
45
|
const localePickerElementSymbol = Symbol("localePickerElement");
|
45
46
|
|
46
47
|
/**
|
47
48
|
* @private
|
48
49
|
* @type {symbol}
|
50
|
+
* Reference to the other languages select element
|
49
51
|
*/
|
50
52
|
const otherLanguagesElementSymbol = Symbol("otherLanguagesElement");
|
51
53
|
|
52
54
|
/**
|
53
55
|
* @private
|
54
56
|
* @type {symbol}
|
57
|
+
* Reference to the language button element
|
55
58
|
*/
|
56
59
|
const buttonLanguageElementSymbol = Symbol("buttonLanguageElement");
|
57
60
|
|
58
61
|
/**
|
59
62
|
* @private
|
60
63
|
* @type {symbol}
|
64
|
+
* Reference to the 'no thanks' button element
|
61
65
|
*/
|
62
66
|
const buttonNoThanksElementSymbol = Symbol("buttonNoThanksElement");
|
63
67
|
|
64
68
|
/**
|
65
69
|
* @private
|
66
70
|
* @type {symbol}
|
71
|
+
* Stores detected languages
|
67
72
|
*/
|
68
73
|
const detectedLanguagesSymbol = Symbol("detectedLanguages");
|
69
74
|
|
@@ -82,584 +87,589 @@ const detectedLanguagesSymbol = Symbol("detectedLanguages");
|
|
82
87
|
* @summary A beautiful LocalePicker that can make your life easier and also looks good.
|
83
88
|
*/
|
84
89
|
class LocalePicker extends CustomElement {
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
90
|
+
/**
|
91
|
+
* This method is called by the `instanceof` operator.
|
92
|
+
* @returns {symbol}
|
93
|
+
*/
|
94
|
+
static get [instanceSymbol]() {
|
95
|
+
return Symbol.for(
|
96
|
+
"@schukai/monster/components/accessibility/locale-picker@@instance",
|
97
|
+
);
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
* Initializes the component.
|
102
|
+
* @return {LocalePicker}
|
103
|
+
*/
|
104
|
+
[assembleMethodSymbol]() {
|
105
|
+
super[assembleMethodSymbol]();
|
106
|
+
initControlReferences.call(this);
|
107
|
+
initEventHandler.call(this);
|
108
|
+
|
109
|
+
return this;
|
110
|
+
}
|
111
|
+
|
112
|
+
/**
|
113
|
+
* To set the options via the HTML Tag, the attribute `data-monster-options` must be used.
|
114
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
115
|
+
*
|
116
|
+
* The individual configuration values can be found in the table.
|
117
|
+
*
|
118
|
+
* @property {Object} templates Template definitions
|
119
|
+
* @property {string} templates.main Main template
|
120
|
+
* @property {Object} labels Label definitions
|
121
|
+
* @property {string} labels.headline Headline
|
122
|
+
* @property {string} labels.text Text
|
123
|
+
* @property {string} labels.button-label Button label
|
124
|
+
* @property {string} labels.button-no-thanks Button no thanks
|
125
|
+
* @property {string} labels.headline-other Headline other languages
|
126
|
+
* @property {Function} callbacks.getTranslation Callback to get the translation for the labels
|
127
|
+
* @property {Object} features Features
|
128
|
+
* @property {boolean} features.removeOnSelected Remove the element when a language is selected
|
129
|
+
* @property {boolean} features.showAlways Show the element always
|
130
|
+
* @property {boolean} disabled Disabled state
|
131
|
+
*/
|
132
|
+
get defaults() {
|
133
|
+
return Object.assign({}, super.defaults, {
|
134
|
+
templates: {
|
135
|
+
main: getTemplate(),
|
136
|
+
},
|
137
|
+
labels: {
|
138
|
+
headline: "Welcome to our Website",
|
139
|
+
text: "This page is currently displayed in ${currentLabel}. However, we also offer this page in your preferred language. Would you like to switch?",
|
140
|
+
"button-label": "Switch to ${preferred.label}",
|
141
|
+
"button-no-thanks": "No, thanks",
|
142
|
+
"headline-other": "Other languages",
|
143
|
+
},
|
144
|
+
|
145
|
+
callbacks: {
|
146
|
+
getTranslation: getTranslations,
|
147
|
+
},
|
148
|
+
|
149
|
+
disabled: false,
|
150
|
+
features: {
|
151
|
+
removeOnSelected: false,
|
152
|
+
showAlways: false,
|
153
|
+
},
|
154
|
+
});
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* Private method that provides a mapping of transformer methods keyed by their names.
|
159
|
+
* These transformer methods define custom transformations for given input values.
|
160
|
+
*
|
161
|
+
* @private
|
162
|
+
* @return {Object} An object containing transformer methods for internal use.
|
163
|
+
*/
|
164
|
+
[updaterTransformerMethodsSymbol]() {
|
165
|
+
return {
|
166
|
+
"replace-placeholder": (value) => {
|
167
|
+
const formatter = new Formatter(this[detectedLanguagesSymbol]);
|
168
|
+
return formatter.format(value);
|
169
|
+
},
|
170
|
+
};
|
171
|
+
}
|
172
|
+
|
173
|
+
/**
|
174
|
+
* Lifecycle method that is called when the custom element is appended into a document-connected element.
|
175
|
+
* Invokes the parent class's connectedCallback method and retrieves the user's preferred language.
|
176
|
+
* Hides or shows the picker depending on the user's language and stored session.
|
177
|
+
*
|
178
|
+
* @return {void}
|
179
|
+
*/
|
180
|
+
connectedCallback() {
|
181
|
+
super.connectedCallback();
|
182
|
+
|
183
|
+
this[detectedLanguagesSymbol] = detectUserLanguagePreference();
|
184
|
+
|
185
|
+
if (
|
186
|
+
!isObject(this[detectedLanguagesSymbol]?.preferred) &&
|
187
|
+
this.getOption("features.showAlways") !== true
|
188
|
+
) {
|
189
|
+
this.hide();
|
190
|
+
|
191
|
+
if (this.getOption("features.removeOnSelected")) {
|
192
|
+
this.remove();
|
193
|
+
}
|
194
|
+
return;
|
195
|
+
}
|
196
|
+
|
197
|
+
if (!isObject(this[detectedLanguagesSymbol]?.preferred)) {
|
198
|
+
this[detectedLanguagesSymbol].preferred = {
|
199
|
+
fullLang: "en",
|
200
|
+
baseLang: "en",
|
201
|
+
label: "English",
|
202
|
+
};
|
203
|
+
}
|
204
|
+
|
205
|
+
const stored = sessionStorage.getItem(buildStorageKey.call(this));
|
206
|
+
if (stored && this.getOption("features.showAlways") !== true) {
|
207
|
+
if (this.getOption("features.removeOnSelected")) {
|
208
|
+
this.remove();
|
209
|
+
}
|
210
|
+
return;
|
211
|
+
}
|
212
|
+
|
213
|
+
this.show();
|
214
|
+
|
215
|
+
if (
|
216
|
+
this[otherLanguagesElementSymbol] instanceof HTMLElement &&
|
217
|
+
this[detectedLanguagesSymbol].offerable &&
|
218
|
+
this[detectedLanguagesSymbol].offerable.length > 1
|
219
|
+
) {
|
220
|
+
this[otherLanguagesElementSymbol].classList.remove("hidden");
|
221
|
+
this[otherLanguagesElementSymbol].setOption(
|
222
|
+
"mapping.labelTemplate",
|
223
|
+
"${label}",
|
224
|
+
);
|
225
|
+
this[otherLanguagesElementSymbol].setOption(
|
226
|
+
"mapping.valueTemplate",
|
227
|
+
"${href}",
|
228
|
+
);
|
229
|
+
this[otherLanguagesElementSymbol].importOptions(
|
230
|
+
this[detectedLanguagesSymbol]?.offerable || [],
|
231
|
+
);
|
232
|
+
}
|
233
|
+
|
234
|
+
if (
|
235
|
+
this[detectedLanguagesSymbol].offerable &&
|
236
|
+
this[detectedLanguagesSymbol].offerable.length > 0
|
237
|
+
) {
|
238
|
+
const getTranslationCallback = this.getOption("callbacks.getTranslation");
|
239
|
+
if (isFunction(getTranslationCallback)) {
|
240
|
+
const translations = getTranslationCallback(
|
241
|
+
this[detectedLanguagesSymbol].offerable[0].baseLang,
|
242
|
+
);
|
243
|
+
|
244
|
+
this.setOption("labels", translations.labels);
|
245
|
+
if (this[otherLanguagesElementSymbol]) {
|
246
|
+
this[otherLanguagesElementSymbol].setOption(
|
247
|
+
"labels.select-an-option",
|
248
|
+
translations.selectAnOption,
|
249
|
+
);
|
250
|
+
}
|
251
|
+
}
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
/**
|
256
|
+
* Resets the locale picker by removing the stored value from the local storage.
|
257
|
+
*
|
258
|
+
* @returns {LocalePicker}
|
259
|
+
*/
|
260
|
+
reset() {
|
261
|
+
sessionStorage.removeItem(buildStorageKey.call(this));
|
262
|
+
this.show();
|
263
|
+
return this;
|
264
|
+
}
|
265
|
+
|
266
|
+
/**
|
267
|
+
* Hides the locale picker.
|
268
|
+
*
|
269
|
+
* @returns {LocalePicker}
|
270
|
+
*/
|
271
|
+
hide() {
|
272
|
+
this.style.display = "none";
|
273
|
+
|
274
|
+
if (!this[localePickerElementSymbol]) {
|
275
|
+
return this;
|
276
|
+
}
|
277
|
+
|
278
|
+
this[localePickerElementSymbol].style.display = "none";
|
279
|
+
return this;
|
280
|
+
}
|
281
|
+
|
282
|
+
/**
|
283
|
+
* Shows the locale picker.
|
284
|
+
* @returns {LocalePicker}
|
285
|
+
*/
|
286
|
+
show() {
|
287
|
+
this.style.display = "block";
|
288
|
+
|
289
|
+
if (!this[localePickerElementSymbol]) {
|
290
|
+
return this;
|
291
|
+
}
|
292
|
+
|
293
|
+
this[localePickerElementSymbol].style.display = "block";
|
294
|
+
return this;
|
295
|
+
}
|
296
|
+
|
297
|
+
/**
|
298
|
+
* @return {string}
|
299
|
+
*/
|
300
|
+
static getTag() {
|
301
|
+
return "monster-locale-picker";
|
302
|
+
}
|
303
|
+
|
304
|
+
/**
|
305
|
+
* @return {CSSStyleSheet[]}
|
306
|
+
*/
|
307
|
+
static getCSSStyleSheet() {
|
308
|
+
return [LocalePickerStyleSheet];
|
309
|
+
}
|
310
|
+
}
|
311
|
+
|
312
|
+
/**
|
313
|
+
* @private
|
314
|
+
* @return {void}
|
315
|
+
* Initializes references to all relevant elements in the picker.
|
316
|
+
*/
|
317
|
+
function initControlReferences() {
|
318
|
+
this[localePickerElementSymbol] = this.shadowRoot.querySelector(
|
319
|
+
`[${ATTRIBUTE_ROLE}="control"]`,
|
320
|
+
);
|
321
|
+
|
322
|
+
this[otherLanguagesElementSymbol] = this.shadowRoot.querySelector(
|
323
|
+
`[${ATTRIBUTE_ROLE}="other-languages"]`,
|
324
|
+
);
|
325
|
+
|
326
|
+
this[buttonNoThanksElementSymbol] = this.shadowRoot.querySelector(
|
327
|
+
`[${ATTRIBUTE_ROLE}="button-no-thanks"]`,
|
328
|
+
);
|
329
|
+
|
330
|
+
this[buttonLanguageElementSymbol] = this.shadowRoot.querySelector(
|
331
|
+
`[${ATTRIBUTE_ROLE}="button-language"]`,
|
332
|
+
);
|
305
333
|
}
|
306
334
|
|
307
335
|
/**
|
308
336
|
* @private
|
309
337
|
* @return {initEventHandler}
|
338
|
+
* Initializes all event handlers for the picker.
|
310
339
|
*/
|
311
340
|
function initEventHandler() {
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
341
|
+
const self = this;
|
342
|
+
const element = this[localePickerElementSymbol];
|
343
|
+
|
344
|
+
const type = "click";
|
345
|
+
|
346
|
+
element.addEventListener(type, function (event) {
|
347
|
+
const callback = self.getOption("actions.click");
|
348
|
+
|
349
|
+
fireCustomEvent(self, "monster-locale-picker-clicked", {
|
350
|
+
element: self,
|
351
|
+
});
|
352
|
+
|
353
|
+
if (!isFunction(callback)) {
|
354
|
+
return;
|
355
|
+
}
|
356
|
+
|
357
|
+
const element = findTargetElementFromEvent(
|
358
|
+
event,
|
359
|
+
ATTRIBUTE_ROLE,
|
360
|
+
"control",
|
361
|
+
);
|
362
|
+
|
363
|
+
if (!(element instanceof Node && self.hasNode(element))) {
|
364
|
+
return;
|
365
|
+
}
|
366
|
+
|
367
|
+
callback.call(self, event);
|
368
|
+
});
|
369
|
+
|
370
|
+
this[buttonNoThanksElementSymbol].setOption("actions.click", () => {
|
371
|
+
sessionStorage.setItem(buildStorageKey.call(this), "1");
|
372
|
+
this.hide();
|
373
|
+
if (this.getOption("features.removeOnSelected")) {
|
374
|
+
this.remove();
|
375
|
+
}
|
376
|
+
});
|
377
|
+
|
378
|
+
this[buttonLanguageElementSymbol].setOption("actions.click", () => {
|
379
|
+
sessionStorage.setItem(buildStorageKey.call(this), "1");
|
380
|
+
window.location.href = this[detectedLanguagesSymbol].offerable?.[0]?.href;
|
381
|
+
});
|
382
|
+
|
383
|
+
this[otherLanguagesElementSymbol].addEventListener("change", (event) => {
|
384
|
+
const element = findTargetElementFromEvent(
|
385
|
+
event,
|
386
|
+
ATTRIBUTE_ROLE,
|
387
|
+
"other-languages",
|
388
|
+
);
|
389
|
+
|
390
|
+
if (element) {
|
391
|
+
const selected = element?.value;
|
392
|
+
if (selected) {
|
393
|
+
sessionStorage.setItem(buildStorageKey.call(this), "1");
|
394
|
+
window.location.href = selected;
|
395
|
+
}
|
396
|
+
}
|
397
|
+
});
|
398
|
+
|
399
|
+
return this;
|
371
400
|
}
|
372
401
|
|
373
402
|
/**
|
374
403
|
* @private
|
375
404
|
* @returns {string}
|
405
|
+
* Builds the session storage key for the picker.
|
376
406
|
*/
|
377
407
|
function buildStorageKey() {
|
378
|
-
|
408
|
+
return "locale-picker-" + this[detectedLanguagesSymbol].current;
|
379
409
|
}
|
380
410
|
|
381
411
|
/**
|
382
412
|
* @private
|
383
413
|
* @param lang
|
384
414
|
* @returns {Object}
|
415
|
+
* Returns translations for the given language.
|
385
416
|
*/
|
386
417
|
function getTranslations(lang) {
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
}
|
626
|
-
|
627
|
-
/**
|
628
|
-
* @private
|
629
|
-
* @return {void}
|
630
|
-
*/
|
631
|
-
function initControlReferences() {
|
632
|
-
this[localePickerElementSymbol] = this.shadowRoot.querySelector(
|
633
|
-
`[${ATTRIBUTE_ROLE}="control"]`,
|
634
|
-
);
|
635
|
-
|
636
|
-
this[otherLanguagesElementSymbol] = this.shadowRoot.querySelector(
|
637
|
-
`[${ATTRIBUTE_ROLE}="other-languages"]`,
|
638
|
-
);
|
639
|
-
|
640
|
-
this[buttonNoThanksElementSymbol] = this.shadowRoot.querySelector(
|
641
|
-
`[${ATTRIBUTE_ROLE}="button-no-thanks"]`,
|
642
|
-
);
|
643
|
-
|
644
|
-
this[buttonLanguageElementSymbol] = this.shadowRoot.querySelector(
|
645
|
-
`[${ATTRIBUTE_ROLE}="button-language"]`,
|
646
|
-
);
|
418
|
+
const map = {
|
419
|
+
en: {
|
420
|
+
headline: "Welcome to our Website",
|
421
|
+
text: "This page is currently displayed in ${currentLabel}. However, we also offer this page in your preferred language. Would you like to switch?",
|
422
|
+
"button-label": "Switch to ${preferred.label}",
|
423
|
+
"button-no-thanks": "No, thanks",
|
424
|
+
"headline-other": "Other languages",
|
425
|
+
},
|
426
|
+
de: {
|
427
|
+
headline: "Willkommen auf unserer Webseite",
|
428
|
+
text: "Diese Seite wird aktuell auf ${currentLabel} angezeigt. Wir bieten jedoch auch diese Seite in Ihrer bevorzugten Sprache an. Möchten Sie wechseln?",
|
429
|
+
"button-label": "Wechseln zu ${preferred.label}",
|
430
|
+
"button-no-thanks": "Nein, danke",
|
431
|
+
"headline-other": "Andere Sprachen",
|
432
|
+
},
|
433
|
+
fr: {
|
434
|
+
headline: "Bienvenue sur notre site web",
|
435
|
+
text: "Cette page est actuellement affichée en ${currentLabel}. Cependant, nous proposons également cette page dans votre langue préférée. Souhaitez-vous changer?",
|
436
|
+
"button-label": "Changer pour ${preferred.label}",
|
437
|
+
"button-no-thanks": "Non, merci",
|
438
|
+
"headline-other": "Autres langues",
|
439
|
+
},
|
440
|
+
es: {
|
441
|
+
headline: "Bienvenido a nuestro sitio web",
|
442
|
+
text: "Esta página se muestra actualmente en ${currentLabel}. Sin embargo, también ofrecemos esta página en su idioma preferido. ¿Le gustaría cambiar?",
|
443
|
+
"button-label": "Cambiar a ${preferred.label}",
|
444
|
+
"button-no-thanks": "No, gracias",
|
445
|
+
"headline-other": "Otros idiomas",
|
446
|
+
},
|
447
|
+
it: {
|
448
|
+
headline: "Benvenuti sul nostro sito web",
|
449
|
+
text: "Questa pagina è attualmente visualizzata in ${currentLabel}. Tuttavia, offriamo anche questa pagina nella tua lingua preferita. Vuoi cambiare?",
|
450
|
+
"button-label": "Cambia nella ${preferred.label}",
|
451
|
+
"button-no-thanks": "No, grazie",
|
452
|
+
"headline-other": "Altre lingue",
|
453
|
+
},
|
454
|
+
pt: {
|
455
|
+
headline: "Bem-vindo ao nosso site",
|
456
|
+
text: "Esta página está atualmente exibida em ${currentLabel}. No entanto, também oferecemos esta página no seu idioma preferido. Gostaria de mudar?",
|
457
|
+
"button-label": "Mudar para ${preferred.label}",
|
458
|
+
"button-no-thanks": "Não, obrigado",
|
459
|
+
"headline-other": "Outros idiomas",
|
460
|
+
},
|
461
|
+
nl: {
|
462
|
+
headline: "Welkom op onze website",
|
463
|
+
text: "Deze pagina wordt momenteel weergegeven in ${currentLabel}. We bieden deze pagina echter ook aan in uw voorkeurstaal. Wilt u overschakelen?",
|
464
|
+
"button-label": "Overschakelen naar ${preferred.label}",
|
465
|
+
"button-no-thanks": "Nee, bedankt",
|
466
|
+
"headline-other": "Andere talen",
|
467
|
+
},
|
468
|
+
pl: {
|
469
|
+
headline: "Witamy na naszej stronie",
|
470
|
+
text: "Ta strona jest obecnie wyświetlana po ${currentLabel}. Oferujemy jednak również tę stronę w Twoim preferowanym języku. Czy chcesz przełączyć?",
|
471
|
+
"button-label": "Przełącz na ${preferred.label}",
|
472
|
+
"button-no-thanks": "Nie, dziękuję",
|
473
|
+
"headline-other": "Inne języki",
|
474
|
+
},
|
475
|
+
ru: {
|
476
|
+
headline: "Добро пожаловать на наш сайт",
|
477
|
+
text: "Эта страница в настоящее время отображается на ${currentLabel}. Однако мы также предлагаем эту страницу на вашем предпочтительном языке. Хотите переключиться?",
|
478
|
+
"button-label": "Переключиться на ${preferred.label}",
|
479
|
+
"button-no-thanks": "Нет, спасибо",
|
480
|
+
"headline-other": "Другие языки",
|
481
|
+
},
|
482
|
+
cs: {
|
483
|
+
headline: "Vítejte na našem webu",
|
484
|
+
text: "Tato stránka je aktuálně zobrazena v ${currentLabel}. Nabízíme však tuto stránku také ve vašem preferovaném jazyce. Chcete přejít?",
|
485
|
+
"button-label": "Přejít na ${preferred.label}",
|
486
|
+
"button-no-thanks": "Ne, děkuji",
|
487
|
+
"headline-other": "Další jazyky",
|
488
|
+
},
|
489
|
+
sk: {
|
490
|
+
headline: "Vitajte na našej webovej stránke",
|
491
|
+
text: "Táto stránka je v súčasnosti zobrazená v ${currentLabel}. Ponúkame však túto stránku aj vo vašom preferovanom jazyku. Chcete prejsť?",
|
492
|
+
"button-label": "Prepnúť na ${preferred.label}",
|
493
|
+
"button-no-thanks": "Nie, ďakujem",
|
494
|
+
"headline-other": "Iné jazyky",
|
495
|
+
},
|
496
|
+
|
497
|
+
bg: {
|
498
|
+
headline: "Добре дошли на нашия уебсайт",
|
499
|
+
text: "Тази страница в момента се показва на ${currentLabel}. Въпреки това, предлагаме също тази страница на Вашия предпочитан език. Желаете ли да превключите?",
|
500
|
+
"button-label": "Превключете на ${preferred.label}",
|
501
|
+
"button-no-thanks": "Не, благодаря",
|
502
|
+
"headline-other": "Други езици",
|
503
|
+
},
|
504
|
+
hr: {
|
505
|
+
headline: "Dobrodošli na našu web stranicu",
|
506
|
+
text: "Ova stranica trenutno je prikazana na ${currentLabel}. Međutim, nudimo i ovu stranicu na vašem preferiranom jeziku. Želite li prebaciti?",
|
507
|
+
"button-label": "Prebaci na ${preferred.label}",
|
508
|
+
"button-no-thanks": "Ne, hvala",
|
509
|
+
"headline-other": "Drugi jezici",
|
510
|
+
},
|
511
|
+
fi: {
|
512
|
+
headline: "Tervetuloa verkkosivustollemme",
|
513
|
+
text: "Tämä sivu on tällä hetkellä näkyvissä ${currentLabel}. Tarjoamme kuitenkin tätä sivua myös suosimallasi kielellä. Haluaisitko vaihtaa?",
|
514
|
+
"button-label": "Vaihda ${preferred.label}",
|
515
|
+
"button-no-thanks": "Ei kiitos",
|
516
|
+
"headline-other": "Muut kielet",
|
517
|
+
},
|
518
|
+
sv: {
|
519
|
+
headline: "Välkommen till vår webbplats",
|
520
|
+
text: "Denna sida visas för närvarande på ${currentLabel}. Vi erbjuder dock även denna sida på ditt föredragna språk. Skulle du vilja byta?",
|
521
|
+
"button-label": "Byt till ${preferred.label}",
|
522
|
+
"button-no-thanks": "Nej tack",
|
523
|
+
"headline-other": "Andra språk",
|
524
|
+
},
|
525
|
+
el: {
|
526
|
+
headline: "Καλώς ήρθατε στην ιστοσελίδα μας",
|
527
|
+
text: "Αυτή η σελίδα εμφανίζεται προς το παρόν στα ${currentLabel}. Ωστόσο, προσφέρουμε επίσης αυτή τη σελίδα στην προτιμώμενη γλώσσα σας. Θα θέλατε να αλλάξετε;",
|
528
|
+
"button-label": "Αλλαγή σε ${preferred.label}",
|
529
|
+
"button-no-thanks": "Όχι, ευχαριστώ",
|
530
|
+
"headline-other": "Άλλες γλώσσες",
|
531
|
+
},
|
532
|
+
hu: {
|
533
|
+
headline: "Üdvözöljük weboldalunkon",
|
534
|
+
text: "Ez az oldal jelenleg ${currentLabel} nyelven jelenik meg. Azonban kínáljuk ezt az oldalt a preferált nyelvén is. Szeretne váltani?",
|
535
|
+
"button-label": "Váltás ${preferred.label} nyelvre",
|
536
|
+
"button-no-thanks": "Nem, köszönöm",
|
537
|
+
"headline-other": "További nyelvek",
|
538
|
+
},
|
539
|
+
ro: {
|
540
|
+
headline: "Bine ați venit pe site-ul nostru",
|
541
|
+
text: "Această pagină este afișată în prezent în ${currentLabel}. Totuși, oferim de asemenea această pagină în limba dumneavoastră preferată. Doriți să schimbați?",
|
542
|
+
"button-label": "Schimbați în ${preferred.label}",
|
543
|
+
"button-no-thanks": "Nu, mulțumesc",
|
544
|
+
"headline-other": "Alte limbi",
|
545
|
+
},
|
546
|
+
da: {
|
547
|
+
headline: "Velkommen til vores hjemmeside",
|
548
|
+
text: "Denne side vises i øjeblikket på ${currentLabel}. Vi tilbyder dog også denne side på dit foretrukne sprog. Vil du skifte?",
|
549
|
+
"button-label": "Skift til ${preferred.label}",
|
550
|
+
"button-no-thanks": "Nej tak",
|
551
|
+
"headline-other": "Andre sprog",
|
552
|
+
},
|
553
|
+
no: {
|
554
|
+
headline: "Velkommen til vår nettside",
|
555
|
+
text: "Denne siden vises for øyeblikket på ${currentLabel}. Vi tilbyr imidlertid også denne siden på ditt foretrukne språk. Ønsker du å bytte?",
|
556
|
+
"button-label": "Bytt til ${preferred.label}",
|
557
|
+
"button-no-thanks": "Nei, takk",
|
558
|
+
"headline-other": "Andre språk",
|
559
|
+
},
|
560
|
+
hi: {
|
561
|
+
headline: "हमारी वेबसाइट पर आपका स्वागत है",
|
562
|
+
text: "यह पृष्ठ वर्तमान में ${currentLabel} में प्रदर्शित हो रहा है। हालांकि, हम इस पृष्ठ को आपकी पसंदीदा भाषा में भी प्रदान करते हैं। क्या आप स्विच करना चाहेंगे?",
|
563
|
+
"button-label": "${preferred.label} में स्विच करें",
|
564
|
+
"button-no-thanks": "नहीं, धन्यवाद",
|
565
|
+
"headline-other": "अन्य भाषाएँ",
|
566
|
+
},
|
567
|
+
bn: {
|
568
|
+
headline: "আমাদের ওয়েবসাইটে আপনাকে স্বাগতম",
|
569
|
+
text: "এই পৃষ্ঠাটি বর্তমানে ${currentLabel} প্রদর্শিত হচ্ছে। তবে, আমরা এই পৃষ্ঠাটি আপনার পছন্দের ভাষায়ও অফার করি। আপনি কি সুইচ করতে চান?",
|
570
|
+
"button-label": "${preferred.label}-এ সুইচ করুন",
|
571
|
+
"button-no-thanks": "না, ধন্যবাদ",
|
572
|
+
"headline-other": "অন্যান্য ভাষাসমূহ",
|
573
|
+
},
|
574
|
+
ta: {
|
575
|
+
headline: "எங்கள் இணையதளத்திற்கு வருக",
|
576
|
+
text: "இந்த பக்கம் தற்போது ${currentLabel} என்ற மொழியில் காட்சியளிக்கப்படுகிறது. எனினும், நாங்கள் இந்த பக்கத்தை உங்கள் விருப்ப மொழியிலும் வழங்குகிறோம். நீங்கள் மாற்ற விரும்புகிறீர்களா?",
|
577
|
+
"button-label": "${preferred.label}-க்கு மாற்றவும்",
|
578
|
+
"button-no-thanks": "இல்லை, நன்றி",
|
579
|
+
"headline-other": "மற்ற மொழிகள்",
|
580
|
+
},
|
581
|
+
te: {
|
582
|
+
headline: "మా వెబ్సైట్కు స్వాగతం",
|
583
|
+
text: "ఈ పేజీ ప్రస్తుతం ${currentLabel}లో ప్రదర్శితం అవుతున్నది. అయితే, మేము ఈ పేజీని మీ ఇష్టపడే భాషలో కూడా అందిస్తున్నాము. మీరు మార్చాలనుకుంటున్నారా?",
|
584
|
+
"button-label": "${preferred.label}కి మార్చండి",
|
585
|
+
"button-no-thanks": "కాదు, ధన్యవాదాలు",
|
586
|
+
"headline-other": "ఇతర భాషలు",
|
587
|
+
},
|
588
|
+
mr: {
|
589
|
+
headline: "आपले आमच्या वेबसाइटवर स्वागत आहे",
|
590
|
+
text: "हे पान सध्या ${currentLabel}मध्ये दाखविले जात आहे. परंतु, आम्ही हे पान आपल्या पसंतीच्या भाषेतही देत आहोत. आपण स्विच करू इच्छिता का?",
|
591
|
+
"button-label": "${preferred.label}मध्ये स्विच करा",
|
592
|
+
"button-no-thanks": "नाही, धन्यवाद",
|
593
|
+
"headline-other": "इतर भाषा",
|
594
|
+
},
|
595
|
+
zh: {
|
596
|
+
headline: "欢迎访问我们的网站",
|
597
|
+
text: "本页面当前显示为${currentLabel}。然而,我们还提供您偏好的语言版本。您想切换吗?",
|
598
|
+
"button-label": "切换到${preferred.label}",
|
599
|
+
"button-no-thanks": "不,谢谢",
|
600
|
+
"headline-other": "其他语言",
|
601
|
+
},
|
602
|
+
ja: {
|
603
|
+
headline: "私たちのウェブサイトへようこそ",
|
604
|
+
text: "このページは現在${currentLabel}で表示されています。しかし、私たちはあなたの好みの言語でこのページを提供しています。切り替えますか?",
|
605
|
+
"button-label": "${preferred.label}に切り替える",
|
606
|
+
"button-no-thanks": "いいえ、結構です",
|
607
|
+
"headline-other": "他の言語",
|
608
|
+
},
|
609
|
+
};
|
610
|
+
|
611
|
+
const selectAnOption = {
|
612
|
+
en: "Select a language",
|
613
|
+
de: "Wählen Sie eine Sprache",
|
614
|
+
fr: "Sélectionnez une langue",
|
615
|
+
es: "Seleccione un idioma",
|
616
|
+
it: "Seleziona una lingua",
|
617
|
+
pt: "Selecione um idioma",
|
618
|
+
nl: "Selecteer een taal",
|
619
|
+
pl: "Wybierz język",
|
620
|
+
ru: "Выберите язык",
|
621
|
+
cs: "Vyberte jazyk",
|
622
|
+
sk: "Vyberte jazyk",
|
623
|
+
bg: "Изберете език",
|
624
|
+
hr: "Odaberite jezik",
|
625
|
+
fi: "Valitse kieli",
|
626
|
+
sv: "Välj ett språk",
|
627
|
+
el: "Επιλέξτε γλώσσα",
|
628
|
+
hu: "Válasszon egy nyelvet",
|
629
|
+
ro: "Selectați o limbă",
|
630
|
+
da: "Vælg et sprog",
|
631
|
+
no: "Velg et språk",
|
632
|
+
hi: "एक भाषा चुनें",
|
633
|
+
bn: "একটি ভাষা নির্বাচন করুন",
|
634
|
+
ta: "ஒரு மொழியைத் தேர்ந்தெடுக்கவும்",
|
635
|
+
te: "భాషను ఎంచుకోండి",
|
636
|
+
mr: "एक भाषा निवडा",
|
637
|
+
zh: "选择一种语言",
|
638
|
+
ja: "言語を選択してください",
|
639
|
+
};
|
640
|
+
|
641
|
+
const result = {};
|
642
|
+
|
643
|
+
if (map[lang]) {
|
644
|
+
result["labels"] = map[lang];
|
645
|
+
} else {
|
646
|
+
result["labels"] = map["en"];
|
647
|
+
}
|
648
|
+
|
649
|
+
if (selectAnOption[lang]) {
|
650
|
+
result["selectAnOption"] = selectAnOption[lang];
|
651
|
+
} else {
|
652
|
+
result["selectAnOption"] = selectAnOption["en"];
|
653
|
+
}
|
654
|
+
|
655
|
+
return result;
|
647
656
|
}
|
648
657
|
|
649
658
|
/**
|
650
659
|
* @private
|
651
660
|
* @return {string}
|
661
|
+
* Returns the template for the component.
|
652
662
|
*/
|
653
663
|
function getTemplate() {
|
654
|
-
|
655
|
-
|
664
|
+
// language=HTML
|
665
|
+
return `
|
656
666
|
<div data-monster-role="control" part="control">
|
657
667
|
<h2 data-monster-role="headline" part="headline" data-monster-replace="path:labels.headline"></h2>
|
658
|
-
<p data-monster-replace="path:labels.text | call:replace-placeholder"></p>
|
668
|
+
<p part="text" data-monster-replace="path:labels.text | call:replace-placeholder"></p>
|
659
669
|
<div data-monster-role="container" part="container">
|
660
|
-
<monster-button data-monster-role="button-language"
|
670
|
+
<monster-button data-monster-role="button-language" part="button-language"
|
661
671
|
data-monster-replace="path:labels.button-label | call:replace-placeholder"></monster-button>
|
662
|
-
<monster-button data-monster-role="button-no-thanks"
|
672
|
+
<monster-button data-monster-role="button-no-thanks" part="button-no-thanks"
|
663
673
|
data-monster-replace="path:labels.button-no-thanks | call:replace-placeholder"></monster-button>
|
664
674
|
<monster-select class="hidden" data-monster-role="other-languages"></monster-select>
|
665
675
|
</div>
|