@platecms/delta-types 1.13.0 → 1.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platecms/delta-types",
3
- "version": "1.13.0",
3
+ "version": "1.15.0",
4
4
  "description": "This package contains various utility types.",
5
5
  "license": "UNLICENSED",
6
6
  "publishConfig": {
@@ -17,8 +17,8 @@
17
17
  "src/**/*"
18
18
  ],
19
19
  "peerDependencies": {
20
- "@platecms/delta-cast": "1.13.0",
21
- "@platecms/delta-plate-resource-notation": "1.13.0",
20
+ "@platecms/delta-cast": "1.15.0",
21
+ "@platecms/delta-plate-resource-notation": "1.15.0",
22
22
  "class-transformer": "0.5.1",
23
23
  "reflect-metadata": "0.2.2",
24
24
  "tslib": "2.8.1"
package/src/index.ts CHANGED
@@ -6,3 +6,7 @@ export * from "./lib/stage.enum";
6
6
  export * from "./lib/header-keys.enum";
7
7
  export * from "./lib/action-type.enum";
8
8
  export * from "./lib/processed-asset-options.interface";
9
+ export * from "./lib/language-status.enum";
10
+ export type * from "./lib/language-option.interface";
11
+ export * from "./lib/language-options.const";
12
+ export * from "./lib/language-locale.util";
@@ -0,0 +1,74 @@
1
+ import { LanguageOption } from "./language-option.interface";
2
+ import { LANGUAGE_OPTIONS } from "./language-options.const";
3
+
4
+ export function languageOptionKey(code: string, countryCode: string): string {
5
+ return `${code.toLowerCase()}:${countryCode.toUpperCase()}`;
6
+ }
7
+
8
+ export const LANGUAGE_OPTIONS_BY_KEY: ReadonlyMap<string, LanguageOption> = new Map(
9
+ LANGUAGE_OPTIONS.map((option) => [languageOptionKey(option.code, option.countryCode), option]),
10
+ );
11
+
12
+ export function formatLocale(code: string, countryCode: string): string {
13
+ return `${code.toLowerCase()}-${countryCode.toUpperCase()}`;
14
+ }
15
+
16
+ export function formatLocaleFromEntity(
17
+ entity: Record<string, unknown> & { code: string; countryCode: string },
18
+ ): string {
19
+ return formatLocale(entity.code, entity.countryCode);
20
+ }
21
+
22
+ export function parseLocale(locale: string): { code: string; countryCode: string } {
23
+ const dashIndex = locale.indexOf("-");
24
+ if (dashIndex <= 0) {
25
+ throw new Error("Invalid locale format. Expected locale in the form 'll-CC'.");
26
+ }
27
+
28
+ return {
29
+ code: locale.slice(0, dashIndex).toLowerCase(),
30
+ countryCode: locale.slice(dashIndex + 1).toUpperCase(),
31
+ };
32
+ }
33
+
34
+ export function findLanguageOption(code: string, countryCode: string): LanguageOption | undefined {
35
+ return LANGUAGE_OPTIONS_BY_KEY.get(languageOptionKey(code, countryCode));
36
+ }
37
+
38
+ export function isValidLanguageOption(code: string, countryCode: string): boolean {
39
+ return findLanguageOption(code, countryCode) != null;
40
+ }
41
+
42
+ export function assertKnownLanguageOption(code: string, countryCode: string): LanguageOption {
43
+ const option = findLanguageOption(code, countryCode);
44
+ if (option == null) {
45
+ throw new Error(`Unknown language option '${formatLocale(code, countryCode)}'.`);
46
+ }
47
+
48
+ return option;
49
+ }
50
+
51
+ export function formatLanguageDisplayName(
52
+ code: string,
53
+ countryCode: string,
54
+ uiLocale: string,
55
+ selectedLocales: readonly Pick<LanguageOption, "code" | "countryCode">[] = [],
56
+ options: { alwaysIncludeRegion?: boolean } = {},
57
+ ): string {
58
+ const normalizedCode = code.toLowerCase();
59
+ const normalizedCountryCode = countryCode.toUpperCase();
60
+ const languageNames = new Intl.DisplayNames([uiLocale], { type: "language" });
61
+ const regionNames = new Intl.DisplayNames([uiLocale], { type: "region" });
62
+ const languageName = languageNames.of(normalizedCode) ?? normalizedCode;
63
+ const regionName = regionNames.of(normalizedCountryCode) ?? normalizedCountryCode;
64
+
65
+ const hasConflict =
66
+ options.alwaysIncludeRegion === true ||
67
+ selectedLocales.filter((locale) => locale.code.toLowerCase() === normalizedCode).length > 1;
68
+
69
+ if (hasConflict) {
70
+ return `${languageName} (${regionName})`;
71
+ }
72
+
73
+ return languageName;
74
+ }
@@ -0,0 +1,4 @@
1
+ export interface LanguageOption {
2
+ readonly code: string;
3
+ readonly countryCode: string;
4
+ }
@@ -0,0 +1,600 @@
1
+ import { LanguageOption } from "./language-option.interface";
2
+
3
+ export const LANGUAGE_OPTIONS: readonly LanguageOption[] = [
4
+ {
5
+ code: "af",
6
+ countryCode: "ZA",
7
+ },
8
+ {
9
+ code: "ar",
10
+ countryCode: "AE",
11
+ },
12
+ {
13
+ code: "ar",
14
+ countryCode: "BH",
15
+ },
16
+ {
17
+ code: "ar",
18
+ countryCode: "DZ",
19
+ },
20
+ {
21
+ code: "ar",
22
+ countryCode: "EG",
23
+ },
24
+ {
25
+ code: "ar",
26
+ countryCode: "IQ",
27
+ },
28
+ {
29
+ code: "ar",
30
+ countryCode: "JO",
31
+ },
32
+ {
33
+ code: "ar",
34
+ countryCode: "KW",
35
+ },
36
+ {
37
+ code: "ar",
38
+ countryCode: "LB",
39
+ },
40
+ {
41
+ code: "ar",
42
+ countryCode: "LY",
43
+ },
44
+ {
45
+ code: "ar",
46
+ countryCode: "MA",
47
+ },
48
+ {
49
+ code: "ar",
50
+ countryCode: "OM",
51
+ },
52
+ {
53
+ code: "ar",
54
+ countryCode: "QA",
55
+ },
56
+ {
57
+ code: "ar",
58
+ countryCode: "SA",
59
+ },
60
+ {
61
+ code: "ar",
62
+ countryCode: "SY",
63
+ },
64
+ {
65
+ code: "ar",
66
+ countryCode: "TN",
67
+ },
68
+ {
69
+ code: "ar",
70
+ countryCode: "YE",
71
+ },
72
+ {
73
+ code: "az",
74
+ countryCode: "AZ",
75
+ },
76
+ {
77
+ code: "be",
78
+ countryCode: "BY",
79
+ },
80
+ {
81
+ code: "bg",
82
+ countryCode: "BG",
83
+ },
84
+ {
85
+ code: "bs",
86
+ countryCode: "BA",
87
+ },
88
+ {
89
+ code: "ca",
90
+ countryCode: "ES",
91
+ },
92
+ {
93
+ code: "cs",
94
+ countryCode: "CZ",
95
+ },
96
+ {
97
+ code: "cy",
98
+ countryCode: "GB",
99
+ },
100
+ {
101
+ code: "da",
102
+ countryCode: "DK",
103
+ },
104
+ {
105
+ code: "de",
106
+ countryCode: "AT",
107
+ },
108
+ {
109
+ code: "de",
110
+ countryCode: "CH",
111
+ },
112
+ {
113
+ code: "de",
114
+ countryCode: "DE",
115
+ },
116
+ {
117
+ code: "de",
118
+ countryCode: "LI",
119
+ },
120
+ {
121
+ code: "de",
122
+ countryCode: "LU",
123
+ },
124
+ {
125
+ code: "dv",
126
+ countryCode: "MV",
127
+ },
128
+ {
129
+ code: "el",
130
+ countryCode: "GR",
131
+ },
132
+ {
133
+ code: "en",
134
+ countryCode: "AU",
135
+ },
136
+ {
137
+ code: "en",
138
+ countryCode: "BZ",
139
+ },
140
+ {
141
+ code: "en",
142
+ countryCode: "CA",
143
+ },
144
+ {
145
+ code: "en",
146
+ countryCode: "CB",
147
+ },
148
+ {
149
+ code: "en",
150
+ countryCode: "GB",
151
+ },
152
+ {
153
+ code: "en",
154
+ countryCode: "IE",
155
+ },
156
+ {
157
+ code: "en",
158
+ countryCode: "JM",
159
+ },
160
+ {
161
+ code: "en",
162
+ countryCode: "NZ",
163
+ },
164
+ {
165
+ code: "en",
166
+ countryCode: "PH",
167
+ },
168
+ {
169
+ code: "en",
170
+ countryCode: "TT",
171
+ },
172
+ {
173
+ code: "en",
174
+ countryCode: "US",
175
+ },
176
+ {
177
+ code: "en",
178
+ countryCode: "ZA",
179
+ },
180
+ {
181
+ code: "en",
182
+ countryCode: "ZW",
183
+ },
184
+ {
185
+ code: "es",
186
+ countryCode: "AR",
187
+ },
188
+ {
189
+ code: "es",
190
+ countryCode: "BO",
191
+ },
192
+ {
193
+ code: "es",
194
+ countryCode: "CL",
195
+ },
196
+ {
197
+ code: "es",
198
+ countryCode: "CO",
199
+ },
200
+ {
201
+ code: "es",
202
+ countryCode: "CR",
203
+ },
204
+ {
205
+ code: "es",
206
+ countryCode: "DO",
207
+ },
208
+ {
209
+ code: "es",
210
+ countryCode: "EC",
211
+ },
212
+ {
213
+ code: "es",
214
+ countryCode: "ES",
215
+ },
216
+ {
217
+ code: "es",
218
+ countryCode: "GT",
219
+ },
220
+ {
221
+ code: "es",
222
+ countryCode: "HN",
223
+ },
224
+ {
225
+ code: "es",
226
+ countryCode: "MX",
227
+ },
228
+ {
229
+ code: "es",
230
+ countryCode: "NI",
231
+ },
232
+ {
233
+ code: "es",
234
+ countryCode: "PA",
235
+ },
236
+ {
237
+ code: "es",
238
+ countryCode: "PE",
239
+ },
240
+ {
241
+ code: "es",
242
+ countryCode: "PR",
243
+ },
244
+ {
245
+ code: "es",
246
+ countryCode: "PY",
247
+ },
248
+ {
249
+ code: "es",
250
+ countryCode: "SV",
251
+ },
252
+ {
253
+ code: "es",
254
+ countryCode: "UY",
255
+ },
256
+ {
257
+ code: "es",
258
+ countryCode: "VE",
259
+ },
260
+ {
261
+ code: "et",
262
+ countryCode: "EE",
263
+ },
264
+ {
265
+ code: "eu",
266
+ countryCode: "ES",
267
+ },
268
+ {
269
+ code: "fa",
270
+ countryCode: "IR",
271
+ },
272
+ {
273
+ code: "fi",
274
+ countryCode: "FI",
275
+ },
276
+ {
277
+ code: "fo",
278
+ countryCode: "FO",
279
+ },
280
+ {
281
+ code: "fr",
282
+ countryCode: "BE",
283
+ },
284
+ {
285
+ code: "fr",
286
+ countryCode: "CA",
287
+ },
288
+ {
289
+ code: "fr",
290
+ countryCode: "CH",
291
+ },
292
+ {
293
+ code: "fr",
294
+ countryCode: "FR",
295
+ },
296
+ {
297
+ code: "fr",
298
+ countryCode: "LU",
299
+ },
300
+ {
301
+ code: "fr",
302
+ countryCode: "MC",
303
+ },
304
+ {
305
+ code: "gl",
306
+ countryCode: "ES",
307
+ },
308
+ {
309
+ code: "gu",
310
+ countryCode: "IN",
311
+ },
312
+ {
313
+ code: "he",
314
+ countryCode: "IL",
315
+ },
316
+ {
317
+ code: "hi",
318
+ countryCode: "IN",
319
+ },
320
+ {
321
+ code: "hr",
322
+ countryCode: "BA",
323
+ },
324
+ {
325
+ code: "hr",
326
+ countryCode: "HR",
327
+ },
328
+ {
329
+ code: "hu",
330
+ countryCode: "HU",
331
+ },
332
+ {
333
+ code: "hy",
334
+ countryCode: "AM",
335
+ },
336
+ {
337
+ code: "id",
338
+ countryCode: "ID",
339
+ },
340
+ {
341
+ code: "is",
342
+ countryCode: "IS",
343
+ },
344
+ {
345
+ code: "it",
346
+ countryCode: "CH",
347
+ },
348
+ {
349
+ code: "it",
350
+ countryCode: "IT",
351
+ },
352
+ {
353
+ code: "ja",
354
+ countryCode: "JP",
355
+ },
356
+ {
357
+ code: "ka",
358
+ countryCode: "GE",
359
+ },
360
+ {
361
+ code: "kk",
362
+ countryCode: "KZ",
363
+ },
364
+ {
365
+ code: "kn",
366
+ countryCode: "IN",
367
+ },
368
+ {
369
+ code: "ko",
370
+ countryCode: "KR",
371
+ },
372
+ {
373
+ code: "kok",
374
+ countryCode: "IN",
375
+ },
376
+ {
377
+ code: "ky",
378
+ countryCode: "KG",
379
+ },
380
+ {
381
+ code: "lt",
382
+ countryCode: "LT",
383
+ },
384
+ {
385
+ code: "lv",
386
+ countryCode: "LV",
387
+ },
388
+ {
389
+ code: "mi",
390
+ countryCode: "NZ",
391
+ },
392
+ {
393
+ code: "mk",
394
+ countryCode: "MK",
395
+ },
396
+ {
397
+ code: "mn",
398
+ countryCode: "MN",
399
+ },
400
+ {
401
+ code: "mr",
402
+ countryCode: "IN",
403
+ },
404
+ {
405
+ code: "ms",
406
+ countryCode: "BN",
407
+ },
408
+ {
409
+ code: "ms",
410
+ countryCode: "MY",
411
+ },
412
+ {
413
+ code: "mt",
414
+ countryCode: "MT",
415
+ },
416
+ {
417
+ code: "nb",
418
+ countryCode: "NO",
419
+ },
420
+ {
421
+ code: "nl",
422
+ countryCode: "BE",
423
+ },
424
+ {
425
+ code: "nl",
426
+ countryCode: "NL",
427
+ },
428
+ {
429
+ code: "nn",
430
+ countryCode: "NO",
431
+ },
432
+ {
433
+ code: "ns",
434
+ countryCode: "ZA",
435
+ },
436
+ {
437
+ code: "pa",
438
+ countryCode: "IN",
439
+ },
440
+ {
441
+ code: "pl",
442
+ countryCode: "PL",
443
+ },
444
+ {
445
+ code: "ps",
446
+ countryCode: "AR",
447
+ },
448
+ {
449
+ code: "pt",
450
+ countryCode: "BR",
451
+ },
452
+ {
453
+ code: "pt",
454
+ countryCode: "PT",
455
+ },
456
+ {
457
+ code: "qu",
458
+ countryCode: "BO",
459
+ },
460
+ {
461
+ code: "qu",
462
+ countryCode: "EC",
463
+ },
464
+ {
465
+ code: "qu",
466
+ countryCode: "PE",
467
+ },
468
+ {
469
+ code: "ro",
470
+ countryCode: "RO",
471
+ },
472
+ {
473
+ code: "ru",
474
+ countryCode: "RU",
475
+ },
476
+ {
477
+ code: "sa",
478
+ countryCode: "IN",
479
+ },
480
+ {
481
+ code: "se",
482
+ countryCode: "FI",
483
+ },
484
+ {
485
+ code: "se",
486
+ countryCode: "NO",
487
+ },
488
+ {
489
+ code: "se",
490
+ countryCode: "SE",
491
+ },
492
+ {
493
+ code: "sk",
494
+ countryCode: "SK",
495
+ },
496
+ {
497
+ code: "sl",
498
+ countryCode: "SI",
499
+ },
500
+ {
501
+ code: "sq",
502
+ countryCode: "AL",
503
+ },
504
+ {
505
+ code: "sr",
506
+ countryCode: "BA",
507
+ },
508
+ {
509
+ code: "sr",
510
+ countryCode: "SP",
511
+ },
512
+ {
513
+ code: "sv",
514
+ countryCode: "FI",
515
+ },
516
+ {
517
+ code: "sv",
518
+ countryCode: "SE",
519
+ },
520
+ {
521
+ code: "sw",
522
+ countryCode: "KE",
523
+ },
524
+ {
525
+ code: "syr",
526
+ countryCode: "SY",
527
+ },
528
+ {
529
+ code: "ta",
530
+ countryCode: "IN",
531
+ },
532
+ {
533
+ code: "te",
534
+ countryCode: "IN",
535
+ },
536
+ {
537
+ code: "th",
538
+ countryCode: "TH",
539
+ },
540
+ {
541
+ code: "tl",
542
+ countryCode: "PH",
543
+ },
544
+ {
545
+ code: "tn",
546
+ countryCode: "ZA",
547
+ },
548
+ {
549
+ code: "tr",
550
+ countryCode: "TR",
551
+ },
552
+ {
553
+ code: "tt",
554
+ countryCode: "RU",
555
+ },
556
+ {
557
+ code: "uk",
558
+ countryCode: "UA",
559
+ },
560
+ {
561
+ code: "ur",
562
+ countryCode: "PK",
563
+ },
564
+ {
565
+ code: "uz",
566
+ countryCode: "UZ",
567
+ },
568
+ {
569
+ code: "vi",
570
+ countryCode: "VN",
571
+ },
572
+ {
573
+ code: "xh",
574
+ countryCode: "ZA",
575
+ },
576
+ {
577
+ code: "zh",
578
+ countryCode: "CN",
579
+ },
580
+ {
581
+ code: "zh",
582
+ countryCode: "HK",
583
+ },
584
+ {
585
+ code: "zh",
586
+ countryCode: "MO",
587
+ },
588
+ {
589
+ code: "zh",
590
+ countryCode: "SG",
591
+ },
592
+ {
593
+ code: "zh",
594
+ countryCode: "TW",
595
+ },
596
+ {
597
+ code: "zu",
598
+ countryCode: "ZA",
599
+ },
600
+ ] as const;
@@ -0,0 +1,4 @@
1
+ export enum LanguageStatus {
2
+ ENABLED = "ENABLED",
3
+ DISABLED = "DISABLED",
4
+ }