32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { Pipe, PipeTransform } from '@angular/core';
|
|
|
|
@Pipe({ name: 'translate' })
|
|
export class TranslatePipe implements PipeTransform {
|
|
private readonly translations: Map<string, string> = new Map([
|
|
// wspólne
|
|
["tooLong", "Numer jest zbyt długi."],
|
|
["tooShort", "Numer jest zbyt krótki."],
|
|
["invalidPattern", "Wprowadzono znak niebędący cyfrą."],
|
|
["invalidControlDigit", "Cyfra kontrolna jest niepoprawna."],
|
|
|
|
// PESEL
|
|
["peselInvalidBirthMonth", "Miesiąc w dacie urodzenia jest niepoprawny."],
|
|
["peselInvalidBirthDay", "Dzień w dacie urodzenia jest niepoprawny."],
|
|
|
|
// NIP
|
|
["nipInvalidOfficeCode", "Kod urzędu skarbowego jest niepoprawny."],
|
|
|
|
// REGON
|
|
["regonInvalidProvinceCode", "Kod województwa jest nieprawidłowy."]
|
|
]);
|
|
|
|
transform(code: string): string {
|
|
const translated: string | undefined = this.translations.get(code);
|
|
|
|
if (translated === undefined) {
|
|
return 'Translation undefined for code: ' + code;
|
|
}
|
|
|
|
return translated;
|
|
}
|
|
} |