Skip to content

Commit 61e6ed9

Browse files
frantisekjandosvalorkin
authored andcommitted
feat(moment-ts): added czech locale (#2642)
1 parent 31c5f62 commit 61e6ed9

File tree

3 files changed

+104
-36
lines changed

3 files changed

+104
-36
lines changed

demo/src/app/components/+datepicker/demo-datepicker.module.ts

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,11 @@ import { routes } from './demo-datepicker.routes';
1212

1313
import { defineLocale } from 'ngx-bootstrap/bs-moment';
1414
import {
15-
ar,
16-
de,
17-
enGb,
18-
es,
19-
esDo,
20-
esUs,
21-
fr,
22-
hi,
23-
it,
24-
ja,
25-
ko,
26-
nl,
27-
nlBe,
28-
pl,
29-
ptBr,
30-
ru,
31-
zhCn
15+
16+
ar, cs, de, enGb, es, esDo, esUs, fr, hi, it, ja, ko, nl, nlBe, pl, ptBr, ru, zhCn
3217
} from 'ngx-bootstrap/locale';
3318

34-
const locales = [
35-
ar,
36-
de,
37-
enGb,
38-
es,
39-
esDo,
40-
esUs,
41-
fr,
42-
hi,
43-
it,
44-
ja,
45-
ko,
46-
nl,
47-
nlBe,
48-
pl,
49-
ptBr,
50-
ru,
51-
zhCn
52-
];
19+
const locales = [ar, cs, de, enGb, es, esDo, esUs, fr, hi, it, ja, ko, nl, nlBe, pl, ptBr, ru, zhCn];
5320

5421
locales.forEach(locale => defineLocale(locale.abbr, locale));
5522

src/bs-moment/i18n/cs.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// moment.js locale configuration
2+
// locale : Czech [cs]
3+
// author : petrbela : https://github.com/petrbela
4+
// ported by: Frantisek Jandos : https://github.com/frantisekjandos
5+
6+
import { LocaleData } from '../locale/locale.class';
7+
8+
function plural(n: number): boolean {
9+
return (n % 10 < 5) && (n % 10 > 1) && ((~~(n / 10) % 10) !== 1);
10+
}
11+
12+
function translate(num: number, withoutSuffix: boolean, key: string, isFuture: boolean): string {
13+
let result = num + ' ';
14+
switch (key) {
15+
case 's': // a few seconds / in a few seconds / a few seconds ago
16+
return (withoutSuffix || isFuture) ? 'pár sekund' : 'pár sekundami';
17+
case 'm': // a minute / in a minute / a minute ago
18+
return withoutSuffix ? 'minuta' : (isFuture ? 'minutu' : 'minutou');
19+
case 'mm': // 9 minutes / in 9 minutes / 9 minutes ago
20+
if (withoutSuffix || isFuture) {
21+
return result + (plural(num) ? 'minuty' : 'minut');
22+
}
23+
return result + 'minutami';
24+
case 'h': // an hour / in an hour / an hour ago
25+
return withoutSuffix ? 'hodina' : (isFuture ? 'hodinu' : 'hodinou');
26+
case 'hh': // 9 hours / in 9 hours / 9 hours ago
27+
if (withoutSuffix || isFuture) {
28+
return result + (plural(num) ? 'hodiny' : 'hodin');
29+
}
30+
return result + 'hodinami';
31+
case 'd': // a day / in a day / a day ago
32+
return (withoutSuffix || isFuture) ? 'den' : 'dnem';
33+
case 'dd': // 9 days / in 9 days / 9 days ago
34+
if (withoutSuffix || isFuture) {
35+
return result + (plural(num) ? 'dny' : 'dní');
36+
}
37+
return result + 'dny';
38+
case 'M': // a month / in a month / a month ago
39+
return (withoutSuffix || isFuture) ? 'měsíc' : 'měsícem';
40+
case 'MM': // 9 months / in 9 months / 9 months ago
41+
if (withoutSuffix || isFuture) {
42+
return result + (plural(num) ? 'měsíce' : 'měsíců');
43+
}
44+
return result + 'měsíci';
45+
case 'y': // a year / in a year / a year ago
46+
return (withoutSuffix || isFuture) ? 'rok' : 'rokem';
47+
case 'yy': // 9 years / in 9 years / 9 years ago
48+
if (withoutSuffix || isFuture) {
49+
return result + (plural(num) ? 'roky' : 'let');
50+
}
51+
return result + 'lety';
52+
}
53+
}
54+
55+
export const cs: LocaleData = {
56+
abbr: 'cs',
57+
months: 'leden_únor_březen_duben_květen_červen_červenec_srpen_září_říjen_listopad_prosinec'.split('_'),
58+
monthsShort: 'led_úno_bře_dub_kvě_čvn_čvc_srp_zář_říj_lis_pro'.split('_'),
59+
weekdays: 'neděle_pondělí_úterý_středa_čtvrtek_pátek_sobota'.split('_'),
60+
weekdaysShort: 'ne_po_út_st_čt_pá_so'.split('_'),
61+
weekdaysMin: 'ne_po_út_st_čt_pá_so'.split('_'),
62+
longDateFormat: {
63+
LT: 'HH:mm',
64+
LTS: 'HH:mm:ss',
65+
L: 'DD.MM.YYYY',
66+
LL: 'D. MMMM YYYY',
67+
LLL: 'D. MMMM YYYY HH:mm',
68+
LLLL: 'dddd, D. MMMM YYYY HH:mm',
69+
l : 'D. M. YYYY'
70+
},
71+
calendar: {
72+
sameDay: '[dnes v] LT',
73+
nextDay: '[zítra v] LT',
74+
nextWeek: '[příští] dddd [v] LT',
75+
lastDay: '[včera v] LT',
76+
lastWeek: '[minulý] dddd [v] LT',
77+
sameElse: 'L'
78+
},
79+
relativeTime: {
80+
future: 'za %s',
81+
past: 'před %s',
82+
s: translate,
83+
m: translate,
84+
mm: translate,
85+
h: translate,
86+
hh: translate,
87+
d: translate,
88+
dd: translate,
89+
M: translate,
90+
MM: translate,
91+
y: translate,
92+
yy: translate
93+
},
94+
dayOfMonthOrdinalParse : /\d{1,2}\./,
95+
ordinal(num: number): string { return `${num}.`; },
96+
week: {
97+
dow: 1, // Monday is the first day of the week.
98+
doy: 4 // The week that contains Jan 4th is the first week of the year.
99+
}
100+
};

src/locale.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { ar } from './bs-moment/i18n/ar';
2+
export { cs } from './bs-moment/i18n/cs';
23
export { de } from './bs-moment/i18n/de';
34
export { enGb } from './bs-moment/i18n/en-gb';
45
export { es } from './bs-moment/i18n/es';

0 commit comments

Comments
 (0)