From c713017f3cd2d617da22c24c579342ec4121cfcd Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Apr 2021 13:21:33 +0200 Subject: Translate plugin options --- .../plugin-show-installed.component.html | 2 +- .../plugin-show-installed.component.ts | 46 ++++++++++++++++++---- .../+admin/plugins/shared/plugin-api.service.ts | 16 -------- 3 files changed, 39 insertions(+), 25 deletions(-) (limited to 'client/src/app/+admin') diff --git a/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.html b/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.html index cb2894568..ad65293d4 100644 --- a/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.html +++ b/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.html @@ -7,7 +7,7 @@
- +
diff --git a/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts b/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts index 4e60ca290..2c5dbea95 100644 --- a/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts +++ b/client/src/app/+admin/plugins/plugin-show-installed/plugin-show-installed.component.ts @@ -2,7 +2,7 @@ import { Subscription } from 'rxjs' import { map, switchMap } from 'rxjs/operators' import { Component, OnDestroy, OnInit } from '@angular/core' import { ActivatedRoute } from '@angular/router' -import { Notifier } from '@app/core' +import { Notifier, PluginService } from '@app/core' import { BuildFormArgument } from '@app/shared/form-validators' import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' import { PeerTubePlugin, RegisterServerSettingOptions } from '@shared/models' @@ -22,7 +22,8 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit constructor ( protected formValidatorService: FormValidatorService, - private pluginService: PluginApiService, + private pluginService: PluginService, + private pluginAPIService: PluginApiService, private notifier: Notifier, private route: ActivatedRoute ) { @@ -46,7 +47,7 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit formValidated () { const settings = this.form.value - this.pluginService.updatePluginSettings(this.plugin.name, this.plugin.type, settings) + this.pluginAPIService.updatePluginSettings(this.plugin.name, this.plugin.type, settings) .subscribe( () => { this.notifier.success($localize`Settings updated.`) @@ -60,18 +61,22 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit return Array.isArray(this.registeredSettings) && this.registeredSettings.length !== 0 } + isSettingHidden (setting: RegisterServerSettingOptions) { + return false + } + private loadPlugin (npmName: string) { - this.pluginService.getPlugin(npmName) + this.pluginAPIService.getPlugin(npmName) .pipe(switchMap(plugin => { - return this.pluginService.getPluginRegisteredSettings(plugin.name, plugin.type) + return this.pluginAPIService.getPluginRegisteredSettings(plugin.name, plugin.type) .pipe(map(data => ({ plugin, registeredSettings: data.registeredSettings }))) })) .subscribe( - ({ plugin, registeredSettings }) => { + async ({ plugin, registeredSettings }) => { this.plugin = plugin - this.registeredSettings = registeredSettings + this.registeredSettings = await this.translateSettings(registeredSettings) - this.pluginTypeLabel = this.pluginService.getPluginTypeLabel(this.plugin.type) + this.pluginTypeLabel = this.pluginAPIService.getPluginTypeLabel(this.plugin.type) this.buildSettingsForm() }, @@ -104,4 +109,29 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit return registered.default } + private async translateSettings (settings: RegisterServerSettingOptions[]) { + const npmName = this.pluginService.nameToNpmName(this.plugin.name, this.plugin.type) + + for (const setting of settings) { + for (const key of [ 'label', 'html', 'descriptionHTML' ]) { + if (setting[key]) setting[key] = await this.pluginService.translateBy(npmName, setting[key]) + } + + if (Array.isArray(setting.options)) { + const newOptions = [] + + for (const o of setting.options) { + newOptions.push({ + value: o.value, + label: await this.pluginService.translateBy(npmName, o.label) + }) + } + + setting.options = newOptions + } + } + + return settings + } + } diff --git a/client/src/app/+admin/plugins/shared/plugin-api.service.ts b/client/src/app/+admin/plugins/shared/plugin-api.service.ts index fad30576b..d91fccc09 100644 --- a/client/src/app/+admin/plugins/shared/plugin-api.service.ts +++ b/client/src/app/+admin/plugins/shared/plugin-api.service.ts @@ -94,7 +94,6 @@ export class PluginApiService { return this.authHttp.get(path) .pipe( - switchMap(res => this.translateSettingsLabel(npmName, res)), catchError(res => this.restExtractor.handleError(res)) ) } @@ -141,19 +140,4 @@ export class PluginApiService { return `https://www.npmjs.com/package/peertube-${typeString}-${name}` } - - private translateSettingsLabel (npmName: string, res: RegisteredServerSettings): Observable { - return this.pluginService.translationsObservable - .pipe( - map(allTranslations => allTranslations[npmName]), - map(translations => { - const registeredSettings = res.registeredSettings - .map(r => { - return Object.assign({}, r, { label: peertubeTranslate(r.label, translations) }) - }) - - return { registeredSettings } - }) - ) - } } -- cgit v1.2.3