Skip to content

Commit

Permalink
feat(locale): Finnish locale (#3991)
Browse files Browse the repository at this point in the history
* fi locale

* tests

* build fix

* better test coverage
  • Loading branch information
ssuperczynski authored and valorkin committed Apr 5, 2018
1 parent c4c2877 commit a333700
Show file tree
Hide file tree
Showing 4 changed files with 417 additions and 4 deletions.
8 changes: 4 additions & 4 deletions demo/src/app/components/+datepicker/demo-datepicker.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { RouterModule } from '@angular/router';
import { defineLocale, LocaleData } from 'ngx-bootstrap/chronos';
import { BsDatepickerModule, DatepickerModule } from 'ngx-bootstrap/datepicker';
import {
arLocale, csLocale, daLocale, deLocale, enGbLocale, esDoLocale, esLocale, esUsLocale, frLocale, heLocale, hiLocale,
huLocale, idLocale, itLocale, jaLocale, koLocale, nlBeLocale, nlLocale, plLocale, ptBrLocale, ruLocale, svLocale,
thLocale, trLocale, zhCnLocale
arLocale, csLocale, daLocale, deLocale, enGbLocale, esDoLocale, esLocale, esUsLocale, frLocale, fiLocale,
heLocale, hiLocale, huLocale, idLocale, itLocale, jaLocale, koLocale, nlBeLocale, nlLocale, plLocale,
ptBrLocale, ruLocale, svLocale, thLocale, trLocale, zhCnLocale
} from 'ngx-bootstrap/locale';
import { TabsModule } from 'ngx-bootstrap/tabs';

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

const locales = [
arLocale, csLocale, daLocale, deLocale, enGbLocale, esLocale, esDoLocale, esUsLocale,
frLocale, hiLocale, heLocale, huLocale, idLocale, itLocale, jaLocale, koLocale, nlLocale,
frLocale, fiLocale, hiLocale, heLocale, huLocale, idLocale, itLocale, jaLocale, koLocale, nlLocale,
nlBeLocale, plLocale, ptBrLocale, svLocale, ruLocale, zhCnLocale, trLocale, thLocale
];
locales.forEach((locale: LocaleData) => defineLocale(locale.abbr, locale));
Expand Down
107 changes: 107 additions & 0 deletions src/chronos/i18n/fi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// tslint:disable:comment-format binary-expression-operand-order max-line-length
// tslint:disable:no-bitwise prefer-template cyclomatic-complexity
// tslint:disable:no-shadowed-variable switch-default prefer-const
// tslint:disable:one-variable-per-declaration newline-before-return

import { LocaleData } from '../locale/locale.class';

//! moment.js locale configuration
// https://github.com/moment/moment/blob/develop/locale/fi.js

var numbersPast = 'nolla yksi kaksi kolme neljä viisi kuusi seitsemän kahdeksan yhdeksän'.split(' '),
numbersFuture = [
'nolla', 'yhden', 'kahden', 'kolmen', 'neljän', 'viiden', 'kuuden',
numbersPast[7], numbersPast[8], numbersPast[9]
];

function translate(num: number, withoutSuffix: boolean, key: string, isFuture: boolean): string {
var result = '';
switch (key) {
case 's':
return isFuture ? 'muutaman sekunnin' : 'muutama sekunti';
case 'ss':
return isFuture ? 'sekunnin' : 'sekuntia';
case 'm':
return isFuture ? 'minuutin' : 'minuutti';
case 'mm':
result = isFuture ? 'minuutin' : 'minuuttia';
break;
case 'h':
return isFuture ? 'tunnin' : 'tunti';
case 'hh':
result = isFuture ? 'tunnin' : 'tuntia';
break;
case 'd':
return isFuture ? 'päivän' : 'päivä';
case 'dd':
result = isFuture ? 'päivän' : 'päivää';
break;
case 'M':
return isFuture ? 'kuukauden' : 'kuukausi';
case 'MM':
result = isFuture ? 'kuukauden' : 'kuukautta';
break;
case 'y':
return isFuture ? 'vuoden' : 'vuosi';
case 'yy':
result = isFuture ? 'vuoden' : 'vuotta';
break;
}
result = verbalNumber(num, isFuture) + ' ' + result;
return result;
}

function verbalNumber(num: number, isFuture: boolean) {
return num < 10 ? (isFuture ? numbersFuture[num] : numbersPast[num]) : num;
}

export const fiLocale: LocaleData = {
abbr: 'fi',
months: 'tammikuu_helmikuu_maaliskuu_huhtikuu_toukokuu_kesäkuu_heinäkuu_elokuu_syyskuu_lokakuu_marraskuu_joulukuu'.split('_'),
monthsShort: 'tammi_helmi_maalis_huhti_touko_kesä_heinä_elo_syys_loka_marras_joulu'.split('_'),
weekdays: 'sunnuntai_maanantai_tiistai_keskiviikko_torstai_perjantai_lauantai'.split('_'),
weekdaysShort: 'su_ma_ti_ke_to_pe_la'.split('_'),
weekdaysMin: 'su_ma_ti_ke_to_pe_la'.split('_'),
longDateFormat: {
LT: 'HH.mm',
LTS: 'HH.mm.ss',
L: 'DD.MM.YYYY',
LL: 'Do MMMM[ta] YYYY',
LLL: 'Do MMMM[ta] YYYY, [klo] HH.mm',
LLLL: 'dddd, Do MMMM[ta] YYYY, [klo] HH.mm',
l: 'D.M.YYYY',
ll: 'Do MMM YYYY',
lll: 'Do MMM YYYY, [klo] HH.mm',
llll: 'ddd, Do MMM YYYY, [klo] HH.mm'
},
calendar: {
sameDay: '[tänään] [klo] LT',
nextDay: '[huomenna] [klo] LT',
nextWeek: 'dddd [klo] LT',
lastDay: '[eilen] [klo] LT',
lastWeek: '[viime] dddd[na] [klo] LT',
sameElse: 'L'
},
relativeTime: {
future: '%s päästä',
past: '%s sitten',
s: translate,
ss: translate,
m: translate,
mm: translate,
h: translate,
hh: translate,
d: translate,
dd: translate,
M: translate,
MM: translate,
y: translate,
yy: translate
},
dayOfMonthOrdinalParse: /\d{1,2}\./,
ordinal: '%d.',
week: {
dow: 1, // Monday is the first day of the week.
doy: 4 // The week that contains Jan 4th is the first week of the year.
}
};
Loading

0 comments on commit a333700

Please sign in to comment.