From b1d40cff89f7cff565a98cdbcea9a624196a169a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 4 Jun 2018 16:21:17 +0200 Subject: Add i18n attributes --- .../src/app/shared/misc/edit-button.component.html | 2 +- client/src/app/shared/misc/from-now.pipe.ts | 25 ++++++++++++---------- client/src/app/shared/misc/help.component.html | 1 + 3 files changed, 16 insertions(+), 12 deletions(-) (limited to 'client/src/app/shared/misc') diff --git a/client/src/app/shared/misc/edit-button.component.html b/client/src/app/shared/misc/edit-button.component.html index 632d6bba2..78fbc326e 100644 --- a/client/src/app/shared/misc/edit-button.component.html +++ b/client/src/app/shared/misc/edit-button.component.html @@ -1,4 +1,4 @@ - Edit + Edit diff --git a/client/src/app/shared/misc/from-now.pipe.ts b/client/src/app/shared/misc/from-now.pipe.ts index fac02af0b..3a64a4077 100644 --- a/client/src/app/shared/misc/from-now.pipe.ts +++ b/client/src/app/shared/misc/from-now.pipe.ts @@ -1,36 +1,39 @@ import { Pipe, PipeTransform } from '@angular/core' +import { I18n } from '@ngx-translate/i18n-polyfill' // Thanks: https://stackoverflow.com/questions/3177836/how-to-format-time-since-xxx-e-g-4-minutes-ago-similar-to-stack-exchange-site @Pipe({ name: 'myFromNow' }) export class FromNowPipe implements PipeTransform { + constructor (private i18n: I18n) { } + transform (value: number) { const seconds = Math.floor((Date.now() - value) / 1000) let interval = Math.floor(seconds / 31536000) if (interval > 1) { - return interval + ' years ago' + return this.i18n('{{ interval }} years ago', { interval }) } interval = Math.floor(seconds / 2592000) - if (interval > 1) return interval + ' months ago' - if (interval === 1) return interval + ' month ago' + if (interval > 1) return this.i18n('{{ interval }} months ago', { interval }) + if (interval === 1) return this.i18n('{{ interval }} month ago', { interval }) interval = Math.floor(seconds / 604800) - if (interval > 1) return interval + ' weeks ago' - if (interval === 1) return interval + ' week ago' + if (interval > 1) return this.i18n('{{ interval }} weeks ago', { interval }) + if (interval === 1) return this.i18n('{{ interval }} week ago', { interval }) interval = Math.floor(seconds / 86400) - if (interval > 1) return interval + ' days ago' - if (interval === 1) return interval + ' day ago' + if (interval > 1) return this.i18n('{{ interval }} days ago', { interval }) + if (interval === 1) return this.i18n('{{ interval }} day ago', { interval }) interval = Math.floor(seconds / 3600) - if (interval > 1) return interval + ' hours ago' - if (interval === 1) return interval + ' hour ago' + if (interval > 1) return this.i18n('{{ interval }} hours ago', { interval }) + if (interval === 1) return this.i18n('{{ interval }} hour ago', { interval }) interval = Math.floor(seconds / 60) - if (interval >= 1) return interval + ' min ago' + if (interval >= 1) return this.i18n('{{ interval }} min ago', { interval }) - return Math.floor(seconds) + ' sec ago' + return this.i18n('{{ interval }} sec ago', { interval: Math.floor(seconds) }) } } diff --git a/client/src/app/shared/misc/help.component.html b/client/src/app/shared/misc/help.component.html index 3da5701a0..f2b6eca33 100644 --- a/client/src/app/shared/misc/help.component.html +++ b/client/src/app/shared/misc/help.component.html @@ -15,6 +15,7 @@