diff options
author | Chocobozzz <me@florianbigard.com> | 2020-08-12 10:40:04 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-08-14 10:28:30 +0200 |
commit | 66357162f8e1227495f09bd4f68446aad7071c6d (patch) | |
tree | 7d4429506deb512b2fe1d0267f38a28cda20af55 /client/src/app/shared/shared-main/angular | |
parent | 8c360747995e17eb5520e22fc3d7bd4c3d26eeee (diff) | |
download | PeerTube-66357162f8e1227495f09bd4f68446aad7071c6d.tar.gz PeerTube-66357162f8e1227495f09bd4f68446aad7071c6d.tar.zst PeerTube-66357162f8e1227495f09bd4f68446aad7071c6d.zip |
Migrate to $localize
* Remove i18n polyfill to translate things in components
* Reduce bundle sizes
* Improve runtime perf
* Reduce a lot the time to make a full client build
* Reduce client build complexity
* We don't need a service to translate things anymore (so we will be able to translate title pages etc)
Unfortunately we may loose some translations in the migration process.
I'll put a message on weblate to notify translators
Diffstat (limited to 'client/src/app/shared/shared-main/angular')
-rw-r--r-- | client/src/app/shared/shared-main/angular/from-now.pipe.ts | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/client/src/app/shared/shared-main/angular/from-now.pipe.ts b/client/src/app/shared/shared-main/angular/from-now.pipe.ts index 9851468ee..5d85590bb 100644 --- a/client/src/app/shared/shared-main/angular/from-now.pipe.ts +++ b/client/src/app/shared/shared-main/angular/from-now.pipe.ts | |||
@@ -1,39 +1,36 @@ | |||
1 | import { Pipe, PipeTransform } from '@angular/core' | 1 | import { Pipe, PipeTransform } from '@angular/core' |
2 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
3 | 2 | ||
4 | // Thanks: https://stackoverflow.com/questions/3177836/how-to-format-time-since-xxx-e-g-4-minutes-ago-similar-to-stack-exchange-site | 3 | // Thanks: https://stackoverflow.com/questions/3177836/how-to-format-time-since-xxx-e-g-4-minutes-ago-similar-to-stack-exchange-site |
5 | @Pipe({ name: 'myFromNow' }) | 4 | @Pipe({ name: 'myFromNow' }) |
6 | export class FromNowPipe implements PipeTransform { | 5 | export class FromNowPipe implements PipeTransform { |
7 | 6 | ||
8 | constructor (private i18n: I18n) { } | ||
9 | |||
10 | transform (arg: number | Date | string) { | 7 | transform (arg: number | Date | string) { |
11 | const argDate = new Date(arg) | 8 | const argDate = new Date(arg) |
12 | const seconds = Math.floor((Date.now() - argDate.getTime()) / 1000) | 9 | const seconds = Math.floor((Date.now() - argDate.getTime()) / 1000) |
13 | 10 | ||
14 | let interval = Math.floor(seconds / 31536000) | 11 | let interval = Math.floor(seconds / 31536000) |
15 | if (interval > 1) return this.i18n('{{interval}} years ago', { interval }) | 12 | if (interval > 1) return $localize`${interval} years ago` |
16 | if (interval === 1) return this.i18n('{{interval}} year ago', { interval }) | 13 | if (interval === 1) return $localize`${interval} year ago` |
17 | 14 | ||
18 | interval = Math.floor(seconds / 2592000) | 15 | interval = Math.floor(seconds / 2592000) |
19 | if (interval > 1) return this.i18n('{{interval}} months ago', { interval }) | 16 | if (interval > 1) return $localize`${interval} months ago` |
20 | if (interval === 1) return this.i18n('{{interval}} month ago', { interval }) | 17 | if (interval === 1) return $localize`${interval} month ago` |
21 | 18 | ||
22 | interval = Math.floor(seconds / 604800) | 19 | interval = Math.floor(seconds / 604800) |
23 | if (interval > 1) return this.i18n('{{interval}} weeks ago', { interval }) | 20 | if (interval > 1) return $localize`${interval} weeks ago` |
24 | if (interval === 1) return this.i18n('{{interval}} week ago', { interval }) | 21 | if (interval === 1) return $localize`${interval} week ago` |
25 | 22 | ||
26 | interval = Math.floor(seconds / 86400) | 23 | interval = Math.floor(seconds / 86400) |
27 | if (interval > 1) return this.i18n('{{interval}} days ago', { interval }) | 24 | if (interval > 1) return $localize`${interval} days ago` |
28 | if (interval === 1) return this.i18n('{{interval}} day ago', { interval }) | 25 | if (interval === 1) return $localize`${interval} day ago` |
29 | 26 | ||
30 | interval = Math.floor(seconds / 3600) | 27 | interval = Math.floor(seconds / 3600) |
31 | if (interval > 1) return this.i18n('{{interval}} hours ago', { interval }) | 28 | if (interval > 1) return $localize`${interval} hours ago` |
32 | if (interval === 1) return this.i18n('{{interval}} hour ago', { interval }) | 29 | if (interval === 1) return $localize`${interval} hour ago` |
33 | 30 | ||
34 | interval = Math.floor(seconds / 60) | 31 | interval = Math.floor(seconds / 60) |
35 | if (interval >= 1) return this.i18n('{{interval}} min ago', { interval }) | 32 | if (interval >= 1) return $localize`${interval} min ago` |
36 | 33 | ||
37 | return this.i18n('just now') | 34 | return $localize`just now` |
38 | } | 35 | } |
39 | } | 36 | } |