aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-main
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-06-06 14:32:47 +0200
committerChocobozzz <me@florianbigard.com>2023-06-29 09:49:06 +0200
commit866c5f667da9fc09f3b093ff0a6f89d4af0ce5af (patch)
tree7a42f7974cec400f9cf09e86de00e69e36b2136d /client/src/app/shared/shared-main
parent40346ead2b0b7afa475aef057d3673b6c7574b7a (diff)
downloadPeerTube-866c5f667da9fc09f3b093ff0a6f89d4af0ce5af.tar.gz
PeerTube-866c5f667da9fc09f3b093ff0a6f89d4af0ce5af.tar.zst
PeerTube-866c5f667da9fc09f3b093ff0a6f89d4af0ce5af.zip
Simplify ICU in components
Diffstat (limited to 'client/src/app/shared/shared-main')
-rw-r--r--client/src/app/shared/shared-main/angular/from-now.pipe.ts17
-rw-r--r--client/src/app/shared/shared-main/video/video.model.ts9
2 files changed, 9 insertions, 17 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 dc6a25e83..4ff244bbb 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,14 +1,9 @@
1import { Pipe, PipeTransform } from '@angular/core' 1import { Pipe, PipeTransform } from '@angular/core'
2import { prepareIcu } from '@app/helpers' 2import { formatICU } from '@app/helpers'
3 3
4// Thanks: https://stackoverflow.com/questions/3177836/how-to-format-time-since-xxx-e-g-4-minutes-ago-similar-to-stack-exchange-site 4// 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' }) 5@Pipe({ name: 'myFromNow' })
6export class FromNowPipe implements PipeTransform { 6export class FromNowPipe implements PipeTransform {
7 private yearICU = prepareIcu($localize`{interval, plural, =1 {1 year ago} other {{interval} years ago}}`)
8 private monthICU = prepareIcu($localize`{interval, plural, =1 {1 month ago} other {{interval} months ago}}`)
9 private weekICU = prepareIcu($localize`{interval, plural, =1 {1 week ago} other {{interval} weeks ago}}`)
10 private dayICU = prepareIcu($localize`{interval, plural, =1 {1 day ago} other {{interval} days ago}}`)
11 private hourICU = prepareIcu($localize`{interval, plural, =1 {1 hour ago} other {{interval} hours ago}}`)
12 7
13 transform (arg: number | Date | string) { 8 transform (arg: number | Date | string) {
14 const argDate = new Date(arg) 9 const argDate = new Date(arg)
@@ -16,7 +11,7 @@ export class FromNowPipe implements PipeTransform {
16 11
17 let interval = Math.floor(seconds / 31536000) 12 let interval = Math.floor(seconds / 31536000)
18 if (interval >= 1) { 13 if (interval >= 1) {
19 return this.yearICU({ interval }, $localize`${interval} year(s) ago`) 14 return formatICU($localize`{interval, plural, =1 {1 year ago} other {{interval} years ago}}`, { interval })
20 } 15 }
21 16
22 interval = Math.floor(seconds / 2419200) 17 interval = Math.floor(seconds / 2419200)
@@ -25,7 +20,7 @@ export class FromNowPipe implements PipeTransform {
25 if (interval >= 12) return $localize`1 year ago` 20 if (interval >= 12) return $localize`1 year ago`
26 21
27 if (interval >= 1) { 22 if (interval >= 1) {
28 return this.monthICU({ interval }, $localize`${interval} month(s) ago`) 23 return formatICU($localize`{interval, plural, =1 {1 month ago} other {{interval} months ago}}`, { interval })
29 } 24 }
30 25
31 interval = Math.floor(seconds / 604800) 26 interval = Math.floor(seconds / 604800)
@@ -34,17 +29,17 @@ export class FromNowPipe implements PipeTransform {
34 if (interval >= 4) return $localize`1 month ago` 29 if (interval >= 4) return $localize`1 month ago`
35 30
36 if (interval >= 1) { 31 if (interval >= 1) {
37 return this.weekICU({ interval }, $localize`${interval} week(s) ago`) 32 return formatICU($localize`{interval, plural, =1 {1 week ago} other {{interval} weeks ago}}`, { interval })
38 } 33 }
39 34
40 interval = Math.floor(seconds / 86400) 35 interval = Math.floor(seconds / 86400)
41 if (interval >= 1) { 36 if (interval >= 1) {
42 return this.dayICU({ interval }, $localize`${interval} day(s) ago`) 37 return formatICU($localize`{interval, plural, =1 {1 day ago} other {{interval} days ago}}`, { interval })
43 } 38 }
44 39
45 interval = Math.floor(seconds / 3600) 40 interval = Math.floor(seconds / 3600)
46 if (interval >= 1) { 41 if (interval >= 1) {
47 return this.hourICU({ interval }, $localize`${interval} hour(s) ago`) 42 return formatICU($localize`{interval, plural, =1 {1 hour ago} other {{interval} hours ago}}`, { interval })
48 } 43 }
49 44
50 interval = Math.floor(seconds / 60) 45 interval = Math.floor(seconds / 60)
diff --git a/client/src/app/shared/shared-main/video/video.model.ts b/client/src/app/shared/shared-main/video/video.model.ts
index 24c00c3d5..e94087dbe 100644
--- a/client/src/app/shared/shared-main/video/video.model.ts
+++ b/client/src/app/shared/shared-main/video/video.model.ts
@@ -1,6 +1,6 @@
1import { AuthUser } from '@app/core' 1import { AuthUser } from '@app/core'
2import { User } from '@app/core/users/user.model' 2import { User } from '@app/core/users/user.model'
3import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl, prepareIcu } from '@app/helpers' 3import { durationToString, formatICU, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
4import { Actor } from '@app/shared/shared-main/account/actor.model' 4import { Actor } from '@app/shared/shared-main/account/actor.model'
5import { buildVideoWatchPath, getAllFiles } from '@shared/core-utils' 5import { buildVideoWatchPath, getAllFiles } from '@shared/core-utils'
6import { peertubeTranslate } from '@shared/core-utils/i18n' 6import { peertubeTranslate } from '@shared/core-utils/i18n'
@@ -19,9 +19,6 @@ import {
19} from '@shared/models' 19} from '@shared/models'
20 20
21export class Video implements VideoServerModel { 21export class Video implements VideoServerModel {
22 private static readonly viewsICU = prepareIcu($localize`{views, plural, =0 {No view} =1 {1 view} other {{views} views}}`)
23 private static readonly viewersICU = prepareIcu($localize`{viewers, plural, =0 {No viewers} =1 {1 viewer} other {{viewers} viewers}}`)
24
25 byVideoChannel: string 22 byVideoChannel: string
26 byAccount: string 23 byAccount: string
27 24
@@ -290,9 +287,9 @@ export class Video implements VideoServerModel {
290 287
291 getExactNumberOfViews () { 288 getExactNumberOfViews () {
292 if (this.isLive) { 289 if (this.isLive) {
293 return Video.viewersICU({ viewers: this.viewers }, $localize`${this.viewers} viewer(s)`) 290 return formatICU($localize`{viewers, plural, =0 {No viewers} =1 {1 viewer} other {{viewers} viewers}}`, { viewers: this.viewers })
294 } 291 }
295 292
296 return Video.viewsICU({ views: this.views }, $localize`{${this.views} view(s)}`) 293 return formatICU($localize`{views, plural, =0 {No view} =1 {1 view} other {{views} views}}`, { views: this.views })
297 } 294 }
298} 295}