Skip to content

Commit

Permalink
Add italian language support (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienM authored May 19, 2019
1 parent 5fa45e5 commit 40399e9
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions app/time.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
const onesTable: {[k: string]: string[]} = {
const onesTable: { [k: string]: string[] } = {
'en': ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'],
'fr': ['', 'un', 'deux', 'trois', 'quatre', 'cinq', 'six', 'sept', 'huit', 'neuf']
'fr': ['', 'un', 'deux', 'trois', 'quatre', 'cinq', 'six', 'sept', 'huit', 'neuf'],
'it': ['', 'uno', 'due', 'tre', 'quattro', 'cinque', 'sei', 'sette', 'otto', 'nove'],
};
const teensTable: {[k: string]: string[]} = {
const teensTable: { [k: string]: string[] } = {
'en': ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'],
'fr': ['dix', 'onze', 'douze', 'treize', 'quatorze', 'quinze', 'seize', 'dix-sept', 'dix-huit', 'dix-neuf']
'fr': ['dix', 'onze', 'douze', 'treize', 'quatorze', 'quinze', 'seize', 'dix-sept', 'dix-huit', 'dix-neuf'],
'it': ['dieci', 'undici', 'dodici', 'tredici', 'quattordici', 'quindici', 'sedici', 'diciassette', 'diciotto', 'diciannove'],
};
const tensTable: {[k: string]: string[]} = {
const tensTable: { [k: string]: string[] } = {
'en': ['', 'ten', 'twenty', 'thirty', 'forty', 'fifty'],
'fr': ['', 'dix', 'vingt', 'trente', 'quarante', 'cinquante']
'fr': ['', 'dix', 'vingt', 'trente', 'quarante', 'cinquante'],
'it': ['', 'dieci', 'venti', 'trenta', 'quaranta', 'cinquanta'],
};
const weekdaysTable: {[k: string]: string[]} = {
const weekdaysTable: { [k: string]: string[] } = {
'en': ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'],
'fr': ['dim', 'lun', 'mar', 'mer', 'jeu', 'ven', 'sam'],
'it': ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'],
};
const midnightTable: {[k: string]: string} = {
const midnightTable: { [k: string]: string } = {
'en': 'midnight',
'fr': 'minuit'
'fr': 'minuit',
'it': 'mezzanotte',
};
const supportedLanguages: {[k: string]: boolean} = {
const supportedLanguages: { [k: string]: boolean } = {
'en': true,
'fr': true
'fr': true,
'it': true,
};
const defaultLanguage: string = 'en';

Expand All @@ -40,7 +46,7 @@ export class DateTimeInWords12h {
protected date: Date;
protected language: string;

constructor(date: Date, language:string) {
constructor(date: Date, language: string) {
this.date = date;
this.pm = date.getHours() >= 12;
this.language = language;
Expand All @@ -61,6 +67,15 @@ export class DateTimeInWords12h {
if (this.language === 'fr' && units === 1) {
return `${tensTable[this.language][tens]} et ${onesTable[this.language][units]}`;
}
if (this.language === 'it') {
if (units === 3) {
return `${tensTable[this.language][tens]}tré`;
}
if (units === 1 || units === 8) {
return `${tensTable[this.language][tens].slice(0, -1)}${onesTable[this.language][units]}`;
}
return `${tensTable[this.language][tens]}${onesTable[this.language][units]}`;
}
return `${tensTable[this.language][tens]} ${onesTable[this.language][units]}`;
}

Expand All @@ -69,7 +84,7 @@ export class DateTimeInWords12h {
}

formatMinutes(): string {
if(this.date.getMinutes() === 0) {
if (this.date.getMinutes() === 0) {
return " ";
}
return this.formatNumber(this.date.getMinutes());
Expand All @@ -87,8 +102,10 @@ export class DateTimeInWords12h {
}

formatDate(): string {
if (this.language == 'fr') {
return `${zeroPad(this.date.getDate())}/${zeroPad(this.date.getMonth() + 1)}`;
switch (this.language) {
case 'fr':
case 'it':
return `${zeroPad(this.date.getDate())}/${zeroPad(this.date.getMonth() + 1)}`;
}
return `${this.date.getMonth() + 1}.${this.date.getDate()}`;
}
Expand Down

0 comments on commit 40399e9

Please sign in to comment.