Skip to content

Commit a333700

Browse files
ssuperczynskivalorkin
authored andcommitted
feat(locale): Finnish locale (#3991)
* fi locale * tests * build fix * better test coverage
1 parent c4c2877 commit a333700

File tree

4 files changed

+417
-4
lines changed

4 files changed

+417
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { RouterModule } from '@angular/router';
66
import { defineLocale, LocaleData } from 'ngx-bootstrap/chronos';
77
import { BsDatepickerModule, DatepickerModule } from 'ngx-bootstrap/datepicker';
88
import {
9-
arLocale, csLocale, daLocale, deLocale, enGbLocale, esDoLocale, esLocale, esUsLocale, frLocale, heLocale, hiLocale,
10-
huLocale, idLocale, itLocale, jaLocale, koLocale, nlBeLocale, nlLocale, plLocale, ptBrLocale, ruLocale, svLocale,
11-
thLocale, trLocale, zhCnLocale
9+
arLocale, csLocale, daLocale, deLocale, enGbLocale, esDoLocale, esLocale, esUsLocale, frLocale, fiLocale,
10+
heLocale, hiLocale, huLocale, idLocale, itLocale, jaLocale, koLocale, nlBeLocale, nlLocale, plLocale,
11+
ptBrLocale, ruLocale, svLocale, thLocale, trLocale, zhCnLocale
1212
} from 'ngx-bootstrap/locale';
1313
import { TabsModule } from 'ngx-bootstrap/tabs';
1414

@@ -19,7 +19,7 @@ import { DEMO_COMPONENTS } from './demos';
1919

2020
const locales = [
2121
arLocale, csLocale, daLocale, deLocale, enGbLocale, esLocale, esDoLocale, esUsLocale,
22-
frLocale, hiLocale, heLocale, huLocale, idLocale, itLocale, jaLocale, koLocale, nlLocale,
22+
frLocale, fiLocale, hiLocale, heLocale, huLocale, idLocale, itLocale, jaLocale, koLocale, nlLocale,
2323
nlBeLocale, plLocale, ptBrLocale, svLocale, ruLocale, zhCnLocale, trLocale, thLocale
2424
];
2525
locales.forEach((locale: LocaleData) => defineLocale(locale.abbr, locale));

src/chronos/i18n/fi.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// tslint:disable:comment-format binary-expression-operand-order max-line-length
2+
// tslint:disable:no-bitwise prefer-template cyclomatic-complexity
3+
// tslint:disable:no-shadowed-variable switch-default prefer-const
4+
// tslint:disable:one-variable-per-declaration newline-before-return
5+
6+
import { LocaleData } from '../locale/locale.class';
7+
8+
//! moment.js locale configuration
9+
// https://github.com/moment/moment/blob/develop/locale/fi.js
10+
11+
var numbersPast = 'nolla yksi kaksi kolme neljä viisi kuusi seitsemän kahdeksan yhdeksän'.split(' '),
12+
numbersFuture = [
13+
'nolla', 'yhden', 'kahden', 'kolmen', 'neljän', 'viiden', 'kuuden',
14+
numbersPast[7], numbersPast[8], numbersPast[9]
15+
];
16+
17+
function translate(num: number, withoutSuffix: boolean, key: string, isFuture: boolean): string {
18+
var result = '';
19+
switch (key) {
20+
case 's':
21+
return isFuture ? 'muutaman sekunnin' : 'muutama sekunti';
22+
case 'ss':
23+
return isFuture ? 'sekunnin' : 'sekuntia';
24+
case 'm':
25+
return isFuture ? 'minuutin' : 'minuutti';
26+
case 'mm':
27+
result = isFuture ? 'minuutin' : 'minuuttia';
28+
break;
29+
case 'h':
30+
return isFuture ? 'tunnin' : 'tunti';
31+
case 'hh':
32+
result = isFuture ? 'tunnin' : 'tuntia';
33+
break;
34+
case 'd':
35+
return isFuture ? 'päivän' : 'päivä';
36+
case 'dd':
37+
result = isFuture ? 'päivän' : 'päivää';
38+
break;
39+
case 'M':
40+
return isFuture ? 'kuukauden' : 'kuukausi';
41+
case 'MM':
42+
result = isFuture ? 'kuukauden' : 'kuukautta';
43+
break;
44+
case 'y':
45+
return isFuture ? 'vuoden' : 'vuosi';
46+
case 'yy':
47+
result = isFuture ? 'vuoden' : 'vuotta';
48+
break;
49+
}
50+
result = verbalNumber(num, isFuture) + ' ' + result;
51+
return result;
52+
}
53+
54+
function verbalNumber(num: number, isFuture: boolean) {
55+
return num < 10 ? (isFuture ? numbersFuture[num] : numbersPast[num]) : num;
56+
}
57+
58+
export const fiLocale: LocaleData = {
59+
abbr: 'fi',
60+
months: 'tammikuu_helmikuu_maaliskuu_huhtikuu_toukokuu_kesäkuu_heinäkuu_elokuu_syyskuu_lokakuu_marraskuu_joulukuu'.split('_'),
61+
monthsShort: 'tammi_helmi_maalis_huhti_touko_kesä_heinä_elo_syys_loka_marras_joulu'.split('_'),
62+
weekdays: 'sunnuntai_maanantai_tiistai_keskiviikko_torstai_perjantai_lauantai'.split('_'),
63+
weekdaysShort: 'su_ma_ti_ke_to_pe_la'.split('_'),
64+
weekdaysMin: 'su_ma_ti_ke_to_pe_la'.split('_'),
65+
longDateFormat: {
66+
LT: 'HH.mm',
67+
LTS: 'HH.mm.ss',
68+
L: 'DD.MM.YYYY',
69+
LL: 'Do MMMM[ta] YYYY',
70+
LLL: 'Do MMMM[ta] YYYY, [klo] HH.mm',
71+
LLLL: 'dddd, Do MMMM[ta] YYYY, [klo] HH.mm',
72+
l: 'D.M.YYYY',
73+
ll: 'Do MMM YYYY',
74+
lll: 'Do MMM YYYY, [klo] HH.mm',
75+
llll: 'ddd, Do MMM YYYY, [klo] HH.mm'
76+
},
77+
calendar: {
78+
sameDay: '[tänään] [klo] LT',
79+
nextDay: '[huomenna] [klo] LT',
80+
nextWeek: 'dddd [klo] LT',
81+
lastDay: '[eilen] [klo] LT',
82+
lastWeek: '[viime] dddd[na] [klo] LT',
83+
sameElse: 'L'
84+
},
85+
relativeTime: {
86+
future: '%s päästä',
87+
past: '%s sitten',
88+
s: translate,
89+
ss: translate,
90+
m: translate,
91+
mm: translate,
92+
h: translate,
93+
hh: translate,
94+
d: translate,
95+
dd: translate,
96+
M: translate,
97+
MM: translate,
98+
y: translate,
99+
yy: translate
100+
},
101+
dayOfMonthOrdinalParse: /\d{1,2}\./,
102+
ordinal: '%d.',
103+
week: {
104+
dow: 1, // Monday is the first day of the week.
105+
doy: 4 // The week that contains Jan 4th is the first week of the year.
106+
}
107+
};

0 commit comments

Comments
 (0)