X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-user-settings%2Fuser-video-settings.component.ts;h=2497e001c8872944ff87a2bd6746709aeef0bdf7;hb=a800dbf345e856ab790e7b3ab9a97e8c5dfa0a32;hp=eb340e24dfcb904638723f12079a9ccaf96b4631;hpb=52c4976fcf4ee255a3af68ff9778e4f5c4f84bd4;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-user-settings/user-video-settings.component.ts b/client/src/app/shared/shared-user-settings/user-video-settings.component.ts index eb340e24d..2497e001c 100644 --- a/client/src/app/shared/shared-user-settings/user-video-settings.component.ts +++ b/client/src/app/shared/shared-user-settings/user-video-settings.component.ts @@ -4,7 +4,6 @@ import { first } from 'rxjs/operators' import { Component, Input, OnDestroy, OnInit } from '@angular/core' import { AuthService, Notifier, ServerService, User, UserService } from '@app/core' import { FormReactive, FormValidatorService, ItemSelectCheckboxValue, SelectOptionsItem } from '@app/shared/shared-forms' -import { I18n } from '@ngx-translate/i18n-polyfill' import { UserUpdateMe } from '@shared/models' import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' @@ -30,14 +29,13 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, private authService: AuthService, private notifier: Notifier, private userService: UserService, - private serverService: ServerService, - private i18n: I18n + private serverService: ServerService ) { super() } ngOnInit () { - this.allLanguagesGroup = this.i18n('All languages') + this.allLanguagesGroup = $localize`All languages` let oldForm: any @@ -56,7 +54,7 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, ]).subscribe(([ languages, config ]) => { const group = this.allLanguagesGroup - this.languageItems = [ { label: this.i18n('Unknown language'), id: '_unknown', group } ] + this.languageItems = [ { label: $localize`Unknown language`, id: '_unknown', group } ] this.languageItems = this.languageItems .concat(languages.map(l => ({ label: l.label, id: l.id, group }))) @@ -97,27 +95,22 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, const autoPlayVideo = this.form.value['autoPlayVideo'] const autoPlayNextVideo = this.form.value['autoPlayNextVideo'] - let videoLanguages: string[] = this.form.value['videoLanguages'] + const videoLanguagesForm = this.form.value['videoLanguages'] - if (Array.isArray(videoLanguages)) { - if (videoLanguages.length > 20) { - this.notifier.error(this.i18n('Too many languages are enabled. Please enable them all or stay below 20 enabled languages.')) + if (Array.isArray(videoLanguagesForm)) { + if (videoLanguagesForm.length > 20) { + this.notifier.error($localize`Too many languages are enabled. Please enable them all or stay below 20 enabled languages.`) return } - if (videoLanguages.length === 0) { - this.notifier.error(this.i18n('You need to enable at least 1 video language.')) + if (videoLanguagesForm.length === 0) { + this.notifier.error($localize`You need to enable at least 1 video language.`) return } - - if ( - videoLanguages.length === this.languageItems.length || - (videoLanguages.length === 1 && videoLanguages[0] === this.allLanguagesGroup) - ) { - videoLanguages = null // null means "All" - } } + const videoLanguages = this.getVideoLanguages(videoLanguagesForm) + let details: UserUpdateMe = { nsfwPolicy, webTorrentEnabled, @@ -126,6 +119,10 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, videoLanguages } + if (videoLanguages) { + details = Object.assign(details, videoLanguages) + } + if (onlyKeys) details = pick(details, onlyKeys) if (this.authService.isLoggedIn()) { @@ -133,22 +130,39 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, () => { this.authService.refreshUserInformation() - if (this.notifyOnUpdate) this.notifier.success(this.i18n('Video settings updated.')) + if (this.notifyOnUpdate) this.notifier.success($localize`Video settings updated.`) }, err => this.notifier.error(err.message) ) } else { this.userService.updateMyAnonymousProfile(details) - if (this.notifyOnUpdate) this.notifier.success(this.i18n('Display/Video settings updated.')) + if (this.notifyOnUpdate) this.notifier.success($localize`Display/Video settings updated.`) } } - getDefaultVideoLanguageLabel () { - return this.i18n('No language') - } + private getVideoLanguages (videoLanguages: ItemSelectCheckboxValue[]) { + if (!Array.isArray(videoLanguages)) return undefined + + // null means "All" + if (videoLanguages.length === this.languageItems.length) return null - getSelectedVideoLanguageLabel () { - return this.i18n('{{\'{0} languages selected') + if (videoLanguages.length === 1) { + const videoLanguage = videoLanguages[0] + + if (typeof videoLanguage === 'string') { + if (videoLanguage === this.allLanguagesGroup) return null + } else { + if (videoLanguage.group === this.allLanguagesGroup) return null + } + } + + return videoLanguages.map(l => { + if (typeof l === 'string') return l + + if (l.group) return l.group + + return l.id + '' + }) } }