forked from verdaccio/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload-dayjs-locale.ts
More file actions
80 lines (73 loc) · 1.53 KB
/
load-dayjs-locale.ts
File metadata and controls
80 lines (73 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import dayjs from 'dayjs';
import i18n from 'i18next';
function getFallFackLanguage(): string | undefined {
const fallbackLanguage = i18n.options.fallbackLng;
if (Array.isArray(fallbackLanguage)) {
return fallbackLanguage[0];
}
if (typeof fallbackLanguage === 'string') {
return fallbackLanguage;
}
return undefined;
}
function loadDayJSLocale() {
const fallbackLanguage = getFallFackLanguage();
const locale = i18n.language || fallbackLanguage;
switch (locale?.toLowerCase()) {
case 'pt-br':
{
require('dayjs/locale/pt-br');
dayjs.locale('pt-br');
}
break;
case 'de-de':
{
require('dayjs/locale/de');
dayjs.locale('de');
}
break;
case 'es-es':
{
require('dayjs/locale/es');
dayjs.locale('es');
}
break;
case 'fr-fr':
{
require('dayjs/locale/fr');
dayjs.locale('fr');
}
break;
case 'zh-cn':
{
require('dayjs/locale/zh-cn');
dayjs.locale('zh-cn');
}
break;
case 'ja-jp':
{
require('dayjs/locale/ja');
dayjs.locale('ja');
}
break;
case 'uk-ua':
{
require('dayjs/locale/uk');
dayjs.locale('uk');
}
break;
case 'zh-tw':
{
require('dayjs/locale/zh-tw');
dayjs.locale('zh-tw');
}
break;
default:
{
require('dayjs/locale/en');
dayjs.locale('en');
}
break;
}
}
export default loadDayJSLocale;