From 66357162f8e1227495f09bd4f68446aad7071c6d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 12 Aug 2020 10:40:04 +0200 Subject: 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 --- .../shared/i18n-primeng-calendar.service.ts | 102 ++++++++++----------- .../+video-edit/shared/video-edit.component.ts | 10 +- .../video-import-torrent.component.ts | 10 +- .../video-import-url.component.ts | 10 +- .../video-add-components/video-upload.component.ts | 48 +++++----- .../+videos/+video-edit/video-update.component.ts | 10 +- .../comment/video-comment.component.ts | 4 +- .../comment/video-comments.component.ts | 8 +- .../recommended-videos.component.ts | 6 +- .../+video-watch/video-duration-formatter.pipe.ts | 11 +-- .../+video-watch/video-watch-playlist.component.ts | 12 +-- .../+videos/+video-watch/video-watch.component.ts | 55 +++++------ .../+videos/video-list/video-local.component.ts | 4 +- .../video-list/video-most-liked.component.ts | 6 +- .../video-list/video-recently-added.component.ts | 4 +- .../+videos/video-list/video-trending.component.ts | 13 +-- .../video-user-subscriptions.component.ts | 8 +- 17 files changed, 135 insertions(+), 186 deletions(-) (limited to 'client/src/app/+videos') diff --git a/client/src/app/+videos/+video-edit/shared/i18n-primeng-calendar.service.ts b/client/src/app/+videos/+video-edit/shared/i18n-primeng-calendar.service.ts index b05852ff8..2acbace48 100644 --- a/client/src/app/+videos/+video-edit/shared/i18n-primeng-calendar.service.ts +++ b/client/src/app/+videos/+video-edit/shared/i18n-primeng-calendar.service.ts @@ -1,76 +1,75 @@ -import { I18n } from '@ngx-translate/i18n-polyfill' import { Injectable } from '@angular/core' @Injectable() export class I18nPrimengCalendarService { private readonly calendarLocale: any = {} - constructor (private i18n: I18n) { + constructor () { this.calendarLocale = { firstDayOfWeek: 0, dayNames: [ - this.i18n('Sunday'), - this.i18n('Monday'), - this.i18n('Tuesday'), - this.i18n('Wednesday'), - this.i18n('Thursday'), - this.i18n('Friday'), - this.i18n('Saturday') + $localize`Sunday`, + $localize`Monday`, + $localize`Tuesday`, + $localize`Wednesday`, + $localize`Thursday`, + $localize`Friday`, + $localize`Saturday` ], dayNamesShort: [ - this.i18n({ value: 'Sun', description: 'Day name short' }), - this.i18n({ value: 'Mon', description: 'Day name short' }), - this.i18n({ value: 'Tue', description: 'Day name short' }), - this.i18n({ value: 'Wed', description: 'Day name short' }), - this.i18n({ value: 'Thu', description: 'Day name short' }), - this.i18n({ value: 'Fri', description: 'Day name short' }), - this.i18n({ value: 'Sat', description: 'Day name short' }) + $localize`:Day name short:Sun`, + $localize`:Day name short:Mon`, + $localize`:Day name short:Tue`, + $localize`:Day name short:Wed`, + $localize`:Day name short:Thu`, + $localize`:Day name short:Fri`, + $localize`:Day name short:Sat` ], dayNamesMin: [ - this.i18n({ value: 'Su', description: 'Day name min' }), - this.i18n({ value: 'Mo', description: 'Day name min' }), - this.i18n({ value: 'Tu', description: 'Day name min' }), - this.i18n({ value: 'We', description: 'Day name min' }), - this.i18n({ value: 'Th', description: 'Day name min' }), - this.i18n({ value: 'Fr', description: 'Day name min' }), - this.i18n({ value: 'Sa', description: 'Day name min' }) + $localize`:Day name min:Su`, + $localize`:Day name min:Mo`, + $localize`:Day name min:Tu`, + $localize`:Day name min:We`, + $localize`:Day name min:Th`, + $localize`:Day name min:Fr`, + $localize`:Day name min:Sa` ], monthNames: [ - this.i18n('January'), - this.i18n('February'), - this.i18n('March'), - this.i18n('April'), - this.i18n('May'), - this.i18n('June'), - this.i18n('July'), - this.i18n('August'), - this.i18n('September'), - this.i18n('October'), - this.i18n('November'), - this.i18n('December') + $localize`January`, + $localize`February`, + $localize`March`, + $localize`April`, + $localize`May`, + $localize`June`, + $localize`July`, + $localize`August`, + $localize`September`, + $localize`October`, + $localize`November`, + $localize`December` ], monthNamesShort: [ - this.i18n({ value: 'Jan', description: 'Month name short' }), - this.i18n({ value: 'Feb', description: 'Month name short' }), - this.i18n({ value: 'Mar', description: 'Month name short' }), - this.i18n({ value: 'Apr', description: 'Month name short' }), - this.i18n({ value: 'May', description: 'Month name short' }), - this.i18n({ value: 'Jun', description: 'Month name short' }), - this.i18n({ value: 'Jul', description: 'Month name short' }), - this.i18n({ value: 'Aug', description: 'Month name short' }), - this.i18n({ value: 'Sep', description: 'Month name short' }), - this.i18n({ value: 'Oct', description: 'Month name short' }), - this.i18n({ value: 'Nov', description: 'Month name short' }), - this.i18n({ value: 'Dec', description: 'Month name short' }) + $localize`:Month name short:Jan`, + $localize`:Month name short:Feb`, + $localize`:Month name short:Mar`, + $localize`:Month name short:Apr`, + $localize`:Month name short:May`, + $localize`:Month name short:Jun`, + $localize`:Month name short:Jul`, + $localize`:Month name short:Aug`, + $localize`:Month name short:Sep`, + $localize`:Month name short:Oct`, + $localize`:Month name short:Nov`, + $localize`:Month name short:Dec` ], - today: this.i18n('Today'), + today: $localize`Today`, - clear: this.i18n('Clear') + clear: $localize`Clear` } } @@ -86,9 +85,6 @@ export class I18nPrimengCalendarService { } getDateFormat () { - return this.i18n({ - value: 'yy-mm-dd ', - description: 'Date format in this locale.' - }) + return $localize`:Date format in this locale.:yy-mm-dd` } } diff --git a/client/src/app/+videos/+video-edit/shared/video-edit.component.ts b/client/src/app/+videos/+video-edit/shared/video-edit.component.ts index ba3b7c96a..050b6d931 100644 --- a/client/src/app/+videos/+video-edit/shared/video-edit.component.ts +++ b/client/src/app/+videos/+video-edit/shared/video-edit.component.ts @@ -7,7 +7,6 @@ import { removeElementFromArray } from '@app/helpers' import { FormReactiveValidationMessages, FormValidatorService, SelectChannelItem, VideoValidatorsService } from '@app/shared/shared-forms' import { InstanceService } from '@app/shared/shared-instance' import { VideoCaptionEdit, VideoEdit, VideoService } from '@app/shared/shared-main' -import { I18n } from '@ngx-translate/i18n-polyfill' import { ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models' import { I18nPrimengCalendarService } from './i18n-primeng-calendar.service' import { VideoCaptionAddModalComponent } from './video-caption-add-modal.component' @@ -63,7 +62,6 @@ export class VideoEditComponent implements OnInit, OnDestroy { private serverService: ServerService, private instanceService: InstanceService, private i18nPrimengCalendarService: I18nPrimengCalendarService, - private i18n: I18n, private ngZone: NgZone ) { this.calendarLocale = this.i18nPrimengCalendarService.getCalendarLocale() @@ -137,8 +135,8 @@ export class VideoEditComponent implements OnInit, OnDestroy { .subscribe(res => { this.videoLanguages = res.languages .map(l => res.about.instance.languages.includes(l.id) - ? { ...l, group: this.i18n('Instance languages'), groupOrder: 0 } - : { ...l, group: this.i18n('All languages'), groupOrder: 1 }) + ? { ...l, group: $localize`Instance languages`, groupOrder: 0 } + : { ...l, group: $localize`All languages`, groupOrder: 1 }) .sort((a, b) => a.groupOrder - b.groupOrder) }) @@ -148,8 +146,8 @@ export class VideoEditComponent implements OnInit, OnDestroy { if (this.schedulePublicationPossible) { this.videoPrivacies.push({ id: this.SPECIAL_SCHEDULED_PRIVACY, - label: this.i18n('Scheduled'), - description: this.i18n('Hide the video until a specific date') + label: $localize`Scheduled`, + description: $localize`Hide the video until a specific date` }) } }) diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts index 3a8e6eecc..e9ad8af7a 100644 --- a/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts +++ b/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.ts @@ -4,10 +4,9 @@ import { AuthService, CanComponentDeactivate, Notifier, ServerService } from '@a import { scrollToTop } from '@app/helpers' import { FormValidatorService } from '@app/shared/shared-forms' import { VideoCaptionService, VideoEdit, VideoImportService, VideoService } from '@app/shared/shared-main' -import { VideoSend } from './video-send' import { LoadingBarService } from '@ngx-loading-bar/core' -import { I18n } from '@ngx-translate/i18n-polyfill' import { VideoPrivacy, VideoUpdate } from '@shared/models' +import { VideoSend } from './video-send' @Component({ selector: 'my-video-import-torrent', @@ -43,9 +42,8 @@ export class VideoImportTorrentComponent extends VideoSend implements OnInit, Ca protected videoService: VideoService, protected videoCaptionService: VideoCaptionService, private router: Router, - private videoImportService: VideoImportService, - private i18n: I18n - ) { + private videoImportService: VideoImportService + ) { super() } @@ -127,7 +125,7 @@ export class VideoImportTorrentComponent extends VideoSend implements OnInit, Ca .subscribe( () => { this.isUpdatingVideo = false - this.notifier.success(this.i18n('Video to import updated.')) + this.notifier.success($localize`Video to import updated.`) this.router.navigate([ '/my-account', 'video-imports' ]) }, diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-import-url.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-import-url.component.ts index da25663d7..8bad81097 100644 --- a/client/src/app/+videos/+video-edit/video-add-components/video-import-url.component.ts +++ b/client/src/app/+videos/+video-edit/video-add-components/video-import-url.component.ts @@ -5,10 +5,9 @@ import { AuthService, CanComponentDeactivate, Notifier, ServerService } from '@a import { getAbsoluteAPIUrl, scrollToTop } from '@app/helpers' import { FormValidatorService } from '@app/shared/shared-forms' import { VideoCaptionService, VideoEdit, VideoImportService, VideoService } from '@app/shared/shared-main' -import { VideoSend } from './video-send' import { LoadingBarService } from '@ngx-loading-bar/core' -import { I18n } from '@ngx-translate/i18n-polyfill' import { VideoPrivacy, VideoUpdate } from '@shared/models' +import { VideoSend } from './video-send' @Component({ selector: 'my-video-import-url', @@ -42,9 +41,8 @@ export class VideoImportUrlComponent extends VideoSend implements OnInit, CanCom protected videoService: VideoService, protected videoCaptionService: VideoCaptionService, private router: Router, - private videoImportService: VideoImportService, - private i18n: I18n - ) { + private videoImportService: VideoImportService + ) { super() } @@ -137,7 +135,7 @@ export class VideoImportUrlComponent extends VideoSend implements OnInit, CanCom .subscribe( () => { this.isUpdatingVideo = false - this.notifier.success(this.i18n('Video to import updated.')) + this.notifier.success($localize`Video to import updated.`) this.router.navigate([ '/my-account', 'video-imports' ]) }, diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts index e18e3c9a7..416b655a4 100644 --- a/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts +++ b/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts @@ -7,7 +7,6 @@ import { scrollToTop } from '@app/helpers' import { FormValidatorService } from '@app/shared/shared-forms' import { BytesPipe, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main' import { LoadingBarService } from '@ngx-loading-bar/core' -import { I18n } from '@ngx-translate/i18n-polyfill' import { VideoPrivacy } from '@shared/models' import { VideoSend } from './video-send' @@ -59,9 +58,8 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy protected videoService: VideoService, protected videoCaptionService: VideoCaptionService, private userService: UserService, - private router: Router, - private i18n: I18n - ) { + private router: Router + ) { super() } @@ -88,10 +86,10 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy if (this.videoUploaded === true) { // FIXME: cannot concatenate strings inside i18n service :/ - text = this.i18n('Your video was uploaded to your account and is private.') + ' ' + - this.i18n('But associated data (tags, description...) will be lost, are you sure you want to leave this page?') + text = $localize`Your video was uploaded to your account and is private.` + ' ' + + $localize`But associated data (tags, description...) will be lost, are you sure you want to leave this page?` } else { - text = this.i18n('Your video is not uploaded yet, are you sure you want to leave this page?') + text = $localize`Your video is not uploaded yet, are you sure you want to leave this page?` } return { @@ -111,9 +109,9 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy getAudioUploadLabel () { const videofile = this.getVideoFile() - if (!videofile) return this.i18n('Upload') + if (!videofile) return $localize`Upload` - return this.i18n('Upload {{videofileName}}', { videofileName: videofile.name }) + return $localize`Upload ${videofile.name}` } fileChange () { @@ -130,7 +128,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy this.firstStepError.emit() - this.notifier.info(this.i18n('Upload cancelled')) + this.notifier.info($localize`Upload cancelled`) } } @@ -242,7 +240,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy this.isUpdatingVideo = false this.isUploadingVideo = false - this.notifier.success(this.i18n('Video published.')) + this.notifier.success($localize`Video published.`) this.router.navigate([ '/videos/watch', video.uuid ]) }, @@ -260,14 +258,12 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy // Check global user quota const videoQuota = this.authService.getUser().videoQuota if (videoQuota !== -1 && (this.userVideoQuotaUsed + videofile.size) > videoQuota) { - const msg = this.i18n( - 'Your video quota is exceeded with this video (video size: {{videoSize}}, used: {{videoQuotaUsed}}, quota: {{videoQuota}})', - { - videoSize: bytePipes.transform(videofile.size, 0), - videoQuotaUsed: bytePipes.transform(this.userVideoQuotaUsed, 0), - videoQuota: bytePipes.transform(videoQuota, 0) - } - ) + const videoSizeBytes = bytePipes.transform(videofile.size, 0) + const videoQuotaUsedBytes = bytePipes.transform(this.userVideoQuotaUsed, 0) + const videoQuotaBytes = bytePipes.transform(videoQuota, 0) + + const msg = $localize`Your video quota is exceeded with this video ( +video size: ${videoSizeBytes}, used: ${videoQuotaUsedBytes}, quota: ${videoQuotaBytes})` this.notifier.error(msg) return false @@ -282,14 +278,12 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy // Check daily user quota const videoQuotaDaily = this.authService.getUser().videoQuotaDaily if (videoQuotaDaily !== -1 && (this.userVideoQuotaUsedDaily + videofile.size) > videoQuotaDaily) { - const msg = this.i18n( - 'Your daily video quota is exceeded with this video (video size: {{videoSize}}, used: {{quotaUsedDaily}}, quota: {{quotaDaily}})', - { - videoSize: bytePipes.transform(videofile.size, 0), - quotaUsedDaily: bytePipes.transform(this.userVideoQuotaUsedDaily, 0), - quotaDaily: bytePipes.transform(videoQuotaDaily, 0) - } - ) + const videoSizeBytes = bytePipes.transform(videofile.size, 0) + const quotaUsedDailyBytes = bytePipes.transform(this.userVideoQuotaUsedDaily, 0) + const quotaDailyBytes = bytePipes.transform(videoQuotaDaily, 0) + + const msg = $localize`Your daily video quota is exceeded with this video ( +video size: ${videoSizeBytes}, used: ${quotaUsedDailyBytes}, quota: ${quotaDailyBytes})` this.notifier.error(msg) return false diff --git a/client/src/app/+videos/+video-edit/video-update.component.ts b/client/src/app/+videos/+video-edit/video-update.component.ts index abd08f05c..2e1d0f89d 100644 --- a/client/src/app/+videos/+video-edit/video-update.component.ts +++ b/client/src/app/+videos/+video-edit/video-update.component.ts @@ -5,7 +5,6 @@ import { Notifier } from '@app/core' import { FormReactive, FormValidatorService, SelectChannelItem } from '@app/shared/shared-forms' import { VideoCaptionEdit, VideoCaptionService, VideoDetails, VideoEdit, VideoService } from '@app/shared/shared-main' import { LoadingBarService } from '@ngx-loading-bar/core' -import { I18n } from '@ngx-translate/i18n-polyfill' import { VideoPrivacy } from '@shared/models' @Component({ @@ -31,9 +30,8 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { private notifier: Notifier, private videoService: VideoService, private loadingBar: LoadingBarService, - private videoCaptionService: VideoCaptionService, - private i18n: I18n - ) { + private videoCaptionService: VideoCaptionService + ) { super() } @@ -78,7 +76,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { canDeactivate (): { canDeactivate: boolean, text?: string } { if (this.updateDone === true) return { canDeactivate: true } - const text = this.i18n('You have unsaved changes! If you leave, your changes will be lost.') + const text = $localize`You have unsaved changes! If you leave, your changes will be lost.` for (const caption of this.videoCaptions) { if (caption.action) return { canDeactivate: false, text } @@ -115,7 +113,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { this.updateDone = true this.isUpdatingVideo = false this.loadingBar.useRef().complete() - this.notifier.success(this.i18n('Video updated.')) + this.notifier.success($localize`Video updated.`) this.router.navigate([ '/videos/watch', this.video.uuid ]) }, diff --git a/client/src/app/+videos/+video-watch/comment/video-comment.component.ts b/client/src/app/+videos/+video-watch/comment/video-comment.component.ts index 36ec6e9f9..a84e91fd3 100644 --- a/client/src/app/+videos/+video-watch/comment/video-comment.component.ts +++ b/client/src/app/+videos/+video-watch/comment/video-comment.component.ts @@ -5,7 +5,6 @@ import { AuthService } from '@app/core/auth' import { Account, Actor, DropdownAction, Video } from '@app/shared/shared-main' import { CommentReportComponent } from '@app/shared/shared-moderation/report-modals/comment-report.component' import { VideoComment, VideoCommentThreadTree } from '@app/shared/shared-video-comment' -import { I18n } from '@ngx-translate/i18n-polyfill' import { User, UserRight } from '@shared/models' @Component({ @@ -39,7 +38,6 @@ export class VideoCommentComponent implements OnInit, OnChanges { commentUser: User constructor ( - private i18n: I18n, private markdownService: MarkdownService, private authService: AuthService, private userService: UserService, @@ -138,7 +136,7 @@ export class VideoCommentComponent implements OnInit, OnChanges { if (this.isUserLoggedIn() && this.comment.isDeleted === false && this.authService.getUser().account.id !== this.comment.account.id) { this.prependModerationActions = [ { - label: this.i18n('Report comment'), + label: $localize`Report comment`, handler: () => this.showReportModal() } ] diff --git a/client/src/app/+videos/+video-watch/comment/video-comments.component.ts b/client/src/app/+videos/+video-watch/comment/video-comments.component.ts index 66494a20a..517844ab2 100644 --- a/client/src/app/+videos/+video-watch/comment/video-comments.component.ts +++ b/client/src/app/+videos/+video-watch/comment/video-comments.component.ts @@ -5,7 +5,6 @@ import { AuthService, ComponentPagination, ConfirmService, hasMoreItems, Notifie import { HooksService } from '@app/core/plugins/hooks.service' import { Syndication, VideoDetails } from '@app/shared/shared-main' import { VideoComment, VideoCommentService, VideoCommentThreadTree } from '@app/shared/shared-video-comment' -import { I18n } from '@ngx-translate/i18n-polyfill' @Component({ selector: 'my-video-comments', @@ -43,7 +42,6 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { private confirmService: ConfirmService, private videoCommentService: VideoCommentService, private activatedRoute: ActivatedRoute, - private i18n: I18n, private hooks: HooksService ) {} @@ -162,12 +160,12 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy { let message = 'Do you really want to delete this comment?' if (commentToDelete.isLocal || this.video.isLocal) { - message += this.i18n(' The deletion will be sent to remote instances so they can reflect the change.') + message += $localize` The deletion will be sent to remote instances so they can reflect the change.` } else { - message += this.i18n(' It is a remote comment, so the deletion will only be effective on your instance.') + message += $localize` It is a remote comment, so the deletion will only be effective on your instance.` } - const res = await this.confirmService.confirm(message, this.i18n('Delete')) + const res = await this.confirmService.confirm(message, $localize`Delete`) if (res === false) return this.videoCommentService.deleteVideoComment(commentToDelete.videoId, commentToDelete.id) diff --git a/client/src/app/+videos/+video-watch/recommendations/recommended-videos.component.ts b/client/src/app/+videos/+video-watch/recommendations/recommended-videos.component.ts index d2372023f..a1c8e0661 100644 --- a/client/src/app/+videos/+video-watch/recommendations/recommended-videos.component.ts +++ b/client/src/app/+videos/+video-watch/recommendations/recommended-videos.component.ts @@ -4,10 +4,9 @@ import { AuthService, Notifier, SessionStorageService, User, UserService } from import { Video } from '@app/shared/shared-main' import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature' import { VideoPlaylist } from '@app/shared/shared-video-playlist' -import { I18n } from '@ngx-translate/i18n-polyfill' +import { UserLocalStorageKeys } from '@root-helpers/users' import { RecommendationInfo } from './recommendation-info.model' import { RecommendedVideosStore } from './recommended-videos.store' -import { UserLocalStorageKeys } from '@root-helpers/users' @Component({ selector: 'my-recommended-videos', @@ -38,7 +37,6 @@ export class RecommendedVideosComponent implements OnInit, OnChanges { private userService: UserService, private authService: AuthService, private notifier: Notifier, - private i18n: I18n, private store: RecommendedVideosStore, private sessionStorageService: SessionStorageService ) { @@ -58,7 +56,7 @@ export class RecommendedVideosComponent implements OnInit, OnChanges { ) } - this.autoPlayNextVideoTooltip = this.i18n('When active, the next video is automatically played after the current one.') + this.autoPlayNextVideoTooltip = $localize`When active, the next video is automatically played after the current one.` } ngOnInit () { diff --git a/client/src/app/+videos/+video-watch/video-duration-formatter.pipe.ts b/client/src/app/+videos/+video-watch/video-duration-formatter.pipe.ts index 4b6767415..19b34f984 100644 --- a/client/src/app/+videos/+video-watch/video-duration-formatter.pipe.ts +++ b/client/src/app/+videos/+video-watch/video-duration-formatter.pipe.ts @@ -1,28 +1,23 @@ import { Pipe, PipeTransform } from '@angular/core' -import { I18n } from '@ngx-translate/i18n-polyfill' @Pipe({ name: 'myVideoDurationFormatter' }) export class VideoDurationPipe implements PipeTransform { - constructor (private i18n: I18n) { - - } - transform (value: number): string { const hours = Math.floor(value / 3600) const minutes = Math.floor((value % 3600) / 60) const seconds = value % 60 if (hours > 0) { - return this.i18n('{{hours}} h {{minutes}} min {{seconds}} sec', { hours, minutes, seconds }) + return $localize`${hours} h ${minutes} min ${seconds} sec` } if (minutes > 0) { - return this.i18n('{{minutes}} min {{seconds}} sec', { minutes, seconds }) + return $localize`${minutes} min ${seconds} sec` } - return this.i18n('{{seconds}} sec', { seconds }) + return $localize`${seconds} sec` } } diff --git a/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts b/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts index 519ce2974..c60ca4671 100644 --- a/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts +++ b/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts @@ -1,9 +1,8 @@ import { Component, Input } from '@angular/core' import { Router } from '@angular/router' import { AuthService, ComponentPagination, LocalStorageService, Notifier, SessionStorageService, UserService } from '@app/core' -import { peertubeLocalStorage, peertubeSessionStorage } from '@root-helpers/peertube-web-storage' import { VideoPlaylist, VideoPlaylistElement, VideoPlaylistService } from '@app/shared/shared-video-playlist' -import { I18n } from '@ngx-translate/i18n-polyfill' +import { peertubeLocalStorage, peertubeSessionStorage } from '@root-helpers/peertube-web-storage' import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models' @Component({ @@ -36,7 +35,6 @@ export class VideoWatchPlaylistComponent { private userService: UserService, private auth: AuthService, private notifier: Notifier, - private i18n: I18n, private videoPlaylist: VideoPlaylistService, private localStorageService: LocalStorageService, private sessionStorageService: SessionStorageService, @@ -189,13 +187,13 @@ export class VideoWatchPlaylistComponent { private setAutoPlayNextVideoPlaylistSwitchText () { this.autoPlayNextVideoPlaylistSwitchText = this.autoPlayNextVideoPlaylist - ? this.i18n('Stop autoplaying next video') - : this.i18n('Autoplay next video') + ? $localize`Stop autoplaying next video` + : $localize`Autoplay next video` } private setLoopPlaylistSwitchText () { this.loopPlaylistSwitchText = this.loopPlaylist - ? this.i18n('Stop looping playlist videos') - : this.i18n('Loop playlist videos') + ? $localize`Stop looping playlist videos` + : $localize`Loop playlist videos` } } diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts index a53af210a..fb89bf6cd 100644 --- a/client/src/app/+videos/+video-watch/video-watch.component.ts +++ b/client/src/app/+videos/+video-watch/video-watch.component.ts @@ -14,7 +14,6 @@ import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription' import { VideoDownloadComponent } from '@app/shared/shared-video-miniature' import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' import { MetaService } from '@ngx-meta/core' -import { I18n } from '@ngx-translate/i18n-polyfill' import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' import { ServerConfig, UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '@shared/models' import { getStoredP2PEnabled, getStoredTheater } from '../../../assets/player/peertube-player-local-storage' @@ -97,16 +96,15 @@ export class VideoWatchComponent implements OnInit, OnDestroy { private zone: NgZone, private redirectService: RedirectService, private videoCaptionService: VideoCaptionService, - private i18n: I18n, private hotkeysService: HotkeysService, private hooks: HooksService, private location: PlatformLocation, @Inject(LOCALE_ID) private localeId: string ) { - this.tooltipLike = this.i18n('Like this video') - this.tooltipDislike = this.i18n('Dislike this video') - this.tooltipSupport = this.i18n('Support options for this video') - this.tooltipSaveToPlaylist = this.i18n('Save to playlist') + this.tooltipLike = $localize`Like this video` + this.tooltipDislike = $localize`Dislike this video` + this.tooltipSupport = $localize`Support options for this video` + this.tooltipSaveToPlaylist = $localize`Save to playlist` } get user () { @@ -188,7 +186,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { getRatePopoverText () { if (this.isUserLoggedIn()) return undefined - return this.i18n('You need to be connected to rate this content.') + return $localize`You need to be connected to rate this content.` } showMoreDescription () { @@ -409,10 +407,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { } private setVideoLikesBarTooltipText () { - this.likesBarTooltipText = this.i18n('{{likesNumber}} likes / {{dislikesNumber}} dislikes', { - likesNumber: this.video.likes, - dislikesNumber: this.video.dislikes - }) + this.likesBarTooltipText = `${this.video.likes} likes / ${this.video.dislikes} dislikes` } private handleError (err: any) { @@ -465,8 +460,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy { if (this.isVideoBlur(this.video)) { const res = await this.confirmService.confirm( - this.i18n('This video contains mature or explicit content. Are you sure you want to watch it?'), - this.i18n('Mature or explicit content') + $localize`This video contains mature or explicit content. Are you sure you want to watch it?`, + $localize`Mature or explicit content` ) if (res === false) return this.location.back() } @@ -515,9 +510,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy { */ this.player.upnext({ timeout: 10000, // 10s - headText: this.i18n('Up Next'), - cancelText: this.i18n('Cancel'), - suspendedText: this.i18n('Autoplay is suspended'), + headText: $localize`Up Next`, + cancelText: $localize`Cancel`, + suspendedText: $localize`Autoplay is suspended`, getTitle: () => this.nextVideoTitle, next: () => this.zone.run(() => this.autoplayNext()), condition: () => { @@ -781,22 +776,22 @@ export class VideoWatchComponent implements OnInit, OnDestroy { private initHotkeys () { this.hotkeys = [ // These hotkeys are managed by the player - new Hotkey('f', e => e, undefined, this.i18n('Enter/exit fullscreen (requires player focus)')), - new Hotkey('space', e => e, undefined, this.i18n('Play/Pause the video (requires player focus)')), - new Hotkey('m', e => e, undefined, this.i18n('Mute/unmute the video (requires player focus)')), + new Hotkey('f', e => e, undefined, $localize`Enter/exit fullscreen (requires player focus)`), + new Hotkey('space', e => e, undefined, $localize`Play/Pause the video (requires player focus)`), + new Hotkey('m', e => e, undefined, $localize`Mute/unmute the video (requires player focus)`), - new Hotkey('0-9', e => e, undefined, this.i18n('Skip to a percentage of the video: 0 is 0% and 9 is 90% (requires player focus)')), + new Hotkey('0-9', e => e, undefined, $localize`Skip to a percentage of the video: 0 is 0% and 9 is 90% (requires player focus)`), - new Hotkey('up', e => e, undefined, this.i18n('Increase the volume (requires player focus)')), - new Hotkey('down', e => e, undefined, this.i18n('Decrease the volume (requires player focus)')), + new Hotkey('up', e => e, undefined, $localize`Increase the volume (requires player focus)`), + new Hotkey('down', e => e, undefined, $localize`Decrease the volume (requires player focus)`), - new Hotkey('right', e => e, undefined, this.i18n('Seek the video forward (requires player focus)')), - new Hotkey('left', e => e, undefined, this.i18n('Seek the video backward (requires player focus)')), + new Hotkey('right', e => e, undefined, $localize`Seek the video forward (requires player focus)`), + new Hotkey('left', e => e, undefined, $localize`Seek the video backward (requires player focus)`), - new Hotkey('>', e => e, undefined, this.i18n('Increase playback rate (requires player focus)')), - new Hotkey('<', e => e, undefined, this.i18n('Decrease playback rate (requires player focus)')), + new Hotkey('>', e => e, undefined, $localize`Increase playback rate (requires player focus)`), + new Hotkey('<', e => e, undefined, $localize`Decrease playback rate (requires player focus)`), - new Hotkey('.', e => e, undefined, this.i18n('Navigate in the video frame by frame (requires player focus)')) + new Hotkey('.', e => e, undefined, $localize`Navigate in the video frame by frame (requires player focus)`) ] if (this.isUserLoggedIn()) { @@ -804,17 +799,17 @@ export class VideoWatchComponent implements OnInit, OnDestroy { new Hotkey('shift+l', () => { this.setLike() return false - }, undefined, this.i18n('Like the video')), + }, undefined, $localize`Like the video`), new Hotkey('shift+d', () => { this.setDislike() return false - }, undefined, this.i18n('Dislike the video')), + }, undefined, $localize`Dislike the video`), new Hotkey('shift+s', () => { this.subscribeButton.subscribed ? this.subscribeButton.unsubscribe() : this.subscribeButton.subscribe() return false - }, undefined, this.i18n('Subscribe to the account')) + }, undefined, $localize`Subscribe to the account`) ]) } diff --git a/client/src/app/+videos/video-list/video-local.component.ts b/client/src/app/+videos/video-list/video-local.component.ts index b4c71ac49..07063d4d4 100644 --- a/client/src/app/+videos/video-list/video-local.component.ts +++ b/client/src/app/+videos/video-list/video-local.component.ts @@ -5,7 +5,6 @@ import { HooksService } from '@app/core/plugins/hooks.service' import { immutableAssign } from '@app/helpers' import { VideoService } from '@app/shared/shared-main' import { AbstractVideoList } from '@app/shared/shared-video-miniature' -import { I18n } from '@ngx-translate/i18n-polyfill' import { UserRight, VideoFilter, VideoSortField } from '@shared/models' @Component({ @@ -21,7 +20,6 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On useUserVideoPreferences = true constructor ( - protected i18n: I18n, protected router: Router, protected serverService: ServerService, protected route: ActivatedRoute, @@ -35,7 +33,7 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On ) { super() - this.titlePage = i18n('Local videos') + this.titlePage = $localize`Local videos` } ngOnInit () { diff --git a/client/src/app/+videos/video-list/video-most-liked.component.ts b/client/src/app/+videos/video-list/video-most-liked.component.ts index ca14851bb..e5f7bd152 100644 --- a/client/src/app/+videos/video-list/video-most-liked.component.ts +++ b/client/src/app/+videos/video-list/video-most-liked.component.ts @@ -5,7 +5,6 @@ import { HooksService } from '@app/core/plugins/hooks.service' import { immutableAssign } from '@app/helpers' import { VideoService } from '@app/shared/shared-main' import { AbstractVideoList } from '@app/shared/shared-video-miniature' -import { I18n } from '@ngx-translate/i18n-polyfill' import { VideoSortField } from '@shared/models' @Component({ @@ -20,7 +19,6 @@ export class VideoMostLikedComponent extends AbstractVideoList implements OnInit useUserVideoPreferences = true constructor ( - protected i18n: I18n, protected router: Router, protected serverService: ServerService, protected route: ActivatedRoute, @@ -40,8 +38,8 @@ export class VideoMostLikedComponent extends AbstractVideoList implements OnInit this.generateSyndicationList() - this.titlePage = this.i18n('Most liked videos') - this.titleTooltip = this.i18n('Videos that have the higher number of likes.') + this.titlePage = $localize`Most liked videos` + this.titleTooltip = $localize`Videos that have the higher number of likes.` } getVideosObservable (page: number) { diff --git a/client/src/app/+videos/video-list/video-recently-added.component.ts b/client/src/app/+videos/video-list/video-recently-added.component.ts index c9395133f..34db6aabd 100644 --- a/client/src/app/+videos/video-list/video-recently-added.component.ts +++ b/client/src/app/+videos/video-list/video-recently-added.component.ts @@ -5,7 +5,6 @@ import { HooksService } from '@app/core/plugins/hooks.service' import { immutableAssign } from '@app/helpers' import { VideoService } from '@app/shared/shared-main' import { AbstractVideoList } from '@app/shared/shared-video-miniature' -import { I18n } from '@ngx-translate/i18n-polyfill' import { VideoSortField } from '@shared/models' @Component({ @@ -21,7 +20,6 @@ export class VideoRecentlyAddedComponent extends AbstractVideoList implements On useUserVideoPreferences = true constructor ( - protected i18n: I18n, protected route: ActivatedRoute, protected serverService: ServerService, protected router: Router, @@ -35,7 +33,7 @@ export class VideoRecentlyAddedComponent extends AbstractVideoList implements On ) { super() - this.titlePage = i18n('Recently added') + this.titlePage = $localize`Recently added` } ngOnInit () { diff --git a/client/src/app/+videos/video-list/video-trending.component.ts b/client/src/app/+videos/video-list/video-trending.component.ts index 10eab18de..babcb9067 100644 --- a/client/src/app/+videos/video-list/video-trending.component.ts +++ b/client/src/app/+videos/video-list/video-trending.component.ts @@ -5,7 +5,6 @@ import { HooksService } from '@app/core/plugins/hooks.service' import { immutableAssign } from '@app/helpers' import { VideoService } from '@app/shared/shared-main' import { AbstractVideoList } from '@app/shared/shared-video-miniature' -import { I18n } from '@ngx-translate/i18n-polyfill' import { VideoSortField } from '@shared/models' @Component({ @@ -20,7 +19,6 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit, useUserVideoPreferences = true constructor ( - protected i18n: I18n, protected router: Router, protected serverService: ServerService, protected route: ActivatedRoute, @@ -45,14 +43,11 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit, const trendingDays = config.trending.videos.intervalDays if (trendingDays === 1) { - this.titlePage = this.i18n('Trending for the last 24 hours') - this.titleTooltip = this.i18n('Trending videos are those totalizing the greatest number of views during the last 24 hours') + this.titlePage = $localize`Trending for the last 24 hours` + this.titleTooltip = $localize`Trending videos are those totalizing the greatest number of views during the last 24 hours` } else { - this.titlePage = this.i18n('Trending for the last {{days}} days', { days: trendingDays }) - this.titleTooltip = this.i18n( - 'Trending videos are those totalizing the greatest number of views during the last {{days}} days', - { days: trendingDays } - ) + this.titlePage = `Trending for the last ${trendingDays} days` + this.titleTooltip = `Trending videos are those totalizing the greatest number of views during the last ${trendingDays} days` } }) } diff --git a/client/src/app/+videos/video-list/video-user-subscriptions.component.ts b/client/src/app/+videos/video-list/video-user-subscriptions.component.ts index 41ad9b277..b02988169 100644 --- a/client/src/app/+videos/video-list/video-user-subscriptions.component.ts +++ b/client/src/app/+videos/video-list/video-user-subscriptions.component.ts @@ -3,10 +3,8 @@ import { ActivatedRoute, Router } from '@angular/router' import { AuthService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' import { HooksService } from '@app/core/plugins/hooks.service' import { immutableAssign } from '@app/helpers' -import { VideoService } from '@app/shared/shared-main' import { UserSubscriptionService } from '@app/shared/shared-user-subscription' import { AbstractVideoList, OwnerDisplayType } from '@app/shared/shared-video-miniature' -import { I18n } from '@ngx-translate/i18n-polyfill' import { VideoSortField } from '@shared/models' @Component({ @@ -21,7 +19,6 @@ export class VideoUserSubscriptionsComponent extends AbstractVideoList implement groupByDate = true constructor ( - protected i18n: I18n, protected router: Router, protected serverService: ServerService, protected route: ActivatedRoute, @@ -31,15 +28,14 @@ export class VideoUserSubscriptionsComponent extends AbstractVideoList implement protected screenService: ScreenService, protected storageService: LocalStorageService, private userSubscription: UserSubscriptionService, - private videoService: VideoService, private hooks: HooksService ) { super() - this.titlePage = i18n('Videos from your subscriptions') + this.titlePage = $localize`Videos from your subscriptions` this.actions.push({ routerLink: '/my-account/subscriptions', - label: i18n('Subscriptions'), + label: $localize`Subscriptions`, iconName: 'cog' }) } -- cgit v1.2.3