diff options
author | Chocobozzz <me@florianbigard.com> | 2021-04-09 13:21:33 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-04-09 13:23:25 +0200 |
commit | c713017f3cd2d617da22c24c579342ec4121cfcd (patch) | |
tree | 4f23d24442a177f5e71e7b2c9e66b5cd5fba121c /client/src/app/+admin | |
parent | 32d13b203b3abf756e751994836c28ddd1f4ebd9 (diff) | |
download | PeerTube-c713017f3cd2d617da22c24c579342ec4121cfcd.tar.gz PeerTube-c713017f3cd2d617da22c24c579342ec4121cfcd.tar.zst PeerTube-c713017f3cd2d617da22c24c579342ec4121cfcd.zip |
Translate plugin options
Diffstat (limited to 'client/src/app/+admin')
3 files changed, 39 insertions, 25 deletions
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 @@ | |||
7 | 7 | ||
8 | <form *ngIf="hasRegisteredSettings()" role="form" (ngSubmit)="formValidated()" [formGroup]="form"> | 8 | <form *ngIf="hasRegisteredSettings()" role="form" (ngSubmit)="formValidated()" [formGroup]="form"> |
9 | <div class="form-group" *ngFor="let setting of registeredSettings"> | 9 | <div class="form-group" *ngFor="let setting of registeredSettings"> |
10 | <my-dynamic-form-field [form]="form" [setting]="setting" [formErrors]="formErrors"></my-dynamic-form-field> | 10 | <my-dynamic-form-field [hidden]="isSettingHidden(setting)" [form]="form" [setting]="setting" [formErrors]="formErrors"></my-dynamic-form-field> |
11 | </div> | 11 | </div> |
12 | 12 | ||
13 | <input type="submit" i18n value="Update plugin settings" [disabled]="!form.valid"> | 13 | <input type="submit" i18n value="Update plugin settings" [disabled]="!form.valid"> |
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' | |||
2 | import { map, switchMap } from 'rxjs/operators' | 2 | import { map, switchMap } from 'rxjs/operators' |
3 | import { Component, OnDestroy, OnInit } from '@angular/core' | 3 | import { Component, OnDestroy, OnInit } from '@angular/core' |
4 | import { ActivatedRoute } from '@angular/router' | 4 | import { ActivatedRoute } from '@angular/router' |
5 | import { Notifier } from '@app/core' | 5 | import { Notifier, PluginService } from '@app/core' |
6 | import { BuildFormArgument } from '@app/shared/form-validators' | 6 | import { BuildFormArgument } from '@app/shared/form-validators' |
7 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' | 7 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' |
8 | import { PeerTubePlugin, RegisterServerSettingOptions } from '@shared/models' | 8 | import { PeerTubePlugin, RegisterServerSettingOptions } from '@shared/models' |
@@ -22,7 +22,8 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit | |||
22 | 22 | ||
23 | constructor ( | 23 | constructor ( |
24 | protected formValidatorService: FormValidatorService, | 24 | protected formValidatorService: FormValidatorService, |
25 | private pluginService: PluginApiService, | 25 | private pluginService: PluginService, |
26 | private pluginAPIService: PluginApiService, | ||
26 | private notifier: Notifier, | 27 | private notifier: Notifier, |
27 | private route: ActivatedRoute | 28 | private route: ActivatedRoute |
28 | ) { | 29 | ) { |
@@ -46,7 +47,7 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit | |||
46 | formValidated () { | 47 | formValidated () { |
47 | const settings = this.form.value | 48 | const settings = this.form.value |
48 | 49 | ||
49 | this.pluginService.updatePluginSettings(this.plugin.name, this.plugin.type, settings) | 50 | this.pluginAPIService.updatePluginSettings(this.plugin.name, this.plugin.type, settings) |
50 | .subscribe( | 51 | .subscribe( |
51 | () => { | 52 | () => { |
52 | this.notifier.success($localize`Settings updated.`) | 53 | this.notifier.success($localize`Settings updated.`) |
@@ -60,18 +61,22 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit | |||
60 | return Array.isArray(this.registeredSettings) && this.registeredSettings.length !== 0 | 61 | return Array.isArray(this.registeredSettings) && this.registeredSettings.length !== 0 |
61 | } | 62 | } |
62 | 63 | ||
64 | isSettingHidden (setting: RegisterServerSettingOptions) { | ||
65 | return false | ||
66 | } | ||
67 | |||
63 | private loadPlugin (npmName: string) { | 68 | private loadPlugin (npmName: string) { |
64 | this.pluginService.getPlugin(npmName) | 69 | this.pluginAPIService.getPlugin(npmName) |
65 | .pipe(switchMap(plugin => { | 70 | .pipe(switchMap(plugin => { |
66 | return this.pluginService.getPluginRegisteredSettings(plugin.name, plugin.type) | 71 | return this.pluginAPIService.getPluginRegisteredSettings(plugin.name, plugin.type) |
67 | .pipe(map(data => ({ plugin, registeredSettings: data.registeredSettings }))) | 72 | .pipe(map(data => ({ plugin, registeredSettings: data.registeredSettings }))) |
68 | })) | 73 | })) |
69 | .subscribe( | 74 | .subscribe( |
70 | ({ plugin, registeredSettings }) => { | 75 | async ({ plugin, registeredSettings }) => { |
71 | this.plugin = plugin | 76 | this.plugin = plugin |
72 | this.registeredSettings = registeredSettings | 77 | this.registeredSettings = await this.translateSettings(registeredSettings) |
73 | 78 | ||
74 | this.pluginTypeLabel = this.pluginService.getPluginTypeLabel(this.plugin.type) | 79 | this.pluginTypeLabel = this.pluginAPIService.getPluginTypeLabel(this.plugin.type) |
75 | 80 | ||
76 | this.buildSettingsForm() | 81 | this.buildSettingsForm() |
77 | }, | 82 | }, |
@@ -104,4 +109,29 @@ export class PluginShowInstalledComponent extends FormReactive implements OnInit | |||
104 | return registered.default | 109 | return registered.default |
105 | } | 110 | } |
106 | 111 | ||
112 | private async translateSettings (settings: RegisterServerSettingOptions[]) { | ||
113 | const npmName = this.pluginService.nameToNpmName(this.plugin.name, this.plugin.type) | ||
114 | |||
115 | for (const setting of settings) { | ||
116 | for (const key of [ 'label', 'html', 'descriptionHTML' ]) { | ||
117 | if (setting[key]) setting[key] = await this.pluginService.translateBy(npmName, setting[key]) | ||
118 | } | ||
119 | |||
120 | if (Array.isArray(setting.options)) { | ||
121 | const newOptions = [] | ||
122 | |||
123 | for (const o of setting.options) { | ||
124 | newOptions.push({ | ||
125 | value: o.value, | ||
126 | label: await this.pluginService.translateBy(npmName, o.label) | ||
127 | }) | ||
128 | } | ||
129 | |||
130 | setting.options = newOptions | ||
131 | } | ||
132 | } | ||
133 | |||
134 | return settings | ||
135 | } | ||
136 | |||
107 | } | 137 | } |
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 { | |||
94 | 94 | ||
95 | return this.authHttp.get<RegisteredServerSettings>(path) | 95 | return this.authHttp.get<RegisteredServerSettings>(path) |
96 | .pipe( | 96 | .pipe( |
97 | switchMap(res => this.translateSettingsLabel(npmName, res)), | ||
98 | catchError(res => this.restExtractor.handleError(res)) | 97 | catchError(res => this.restExtractor.handleError(res)) |
99 | ) | 98 | ) |
100 | } | 99 | } |
@@ -141,19 +140,4 @@ export class PluginApiService { | |||
141 | 140 | ||
142 | return `https://www.npmjs.com/package/peertube-${typeString}-${name}` | 141 | return `https://www.npmjs.com/package/peertube-${typeString}-${name}` |
143 | } | 142 | } |
144 | |||
145 | private translateSettingsLabel (npmName: string, res: RegisteredServerSettings): Observable<RegisteredServerSettings> { | ||
146 | return this.pluginService.translationsObservable | ||
147 | .pipe( | ||
148 | map(allTranslations => allTranslations[npmName]), | ||
149 | map(translations => { | ||
150 | const registeredSettings = res.registeredSettings | ||
151 | .map(r => { | ||
152 | return Object.assign({}, r, { label: peertubeTranslate(r.label, translations) }) | ||
153 | }) | ||
154 | |||
155 | return { registeredSettings } | ||
156 | }) | ||
157 | ) | ||
158 | } | ||
159 | } | 143 | } |