diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-29 14:08:07 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-29 14:08:07 +0100 |
commit | fb3c9e2bf5b45d6d283cea4d55cc0d49eb58e3cb (patch) | |
tree | 251e39490e83b6a0e40c25871188628e62819fa8 /client/src/app/core/plugins | |
parent | 2accfdd8ecd092de7e8c71fbd1235e139ad29832 (diff) | |
download | PeerTube-fb3c9e2bf5b45d6d283cea4d55cc0d49eb58e3cb.tar.gz PeerTube-fb3c9e2bf5b45d6d283cea4d55cc0d49eb58e3cb.tar.zst PeerTube-fb3c9e2bf5b45d6d283cea4d55cc0d49eb58e3cb.zip |
Translate plugin settings
Diffstat (limited to 'client/src/app/core/plugins')
-rw-r--r-- | client/src/app/core/plugins/plugin.service.ts | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index fdbbd2d56..bb9125fe1 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts | |||
@@ -20,8 +20,8 @@ import { | |||
20 | PluginType, | 20 | PluginType, |
21 | PublicServerSetting, | 21 | PublicServerSetting, |
22 | RegisterClientFormFieldOptions, | 22 | RegisterClientFormFieldOptions, |
23 | RegisterClientSettingsScriptOptions, | ||
24 | RegisterClientRouteOptions, | 23 | RegisterClientRouteOptions, |
24 | RegisterClientSettingsScriptOptions, | ||
25 | RegisterClientVideoFieldOptions, | 25 | RegisterClientVideoFieldOptions, |
26 | ServerConfigPlugin | 26 | ServerConfigPlugin |
27 | } from '@shared/models' | 27 | } from '@shared/models' |
@@ -30,6 +30,7 @@ import { RegisterClientHelpers } from '../../../types/register-client-option.mod | |||
30 | 30 | ||
31 | type FormFields = { | 31 | type FormFields = { |
32 | video: { | 32 | video: { |
33 | pluginInfo: PluginInfo | ||
33 | commonOptions: RegisterClientFormFieldOptions | 34 | commonOptions: RegisterClientFormFieldOptions |
34 | videoFormOptions: RegisterClientVideoFieldOptions | 35 | videoFormOptions: RegisterClientVideoFieldOptions |
35 | }[] | 36 | }[] |
@@ -44,8 +45,6 @@ export class PluginService implements ClientHook { | |||
44 | 45 | ||
45 | customModal: CustomModalComponent | 46 | customModal: CustomModalComponent |
46 | 47 | ||
47 | private helpers: { [ npmName: string ]: RegisterClientHelpers } = {} | ||
48 | |||
49 | private formFields: FormFields = { | 48 | private formFields: FormFields = { |
50 | video: [] | 49 | video: [] |
51 | } | 50 | } |
@@ -134,27 +133,49 @@ export class PluginService implements ClientHook { | |||
134 | return Object.keys(this.clientRoutes) | 133 | return Object.keys(this.clientRoutes) |
135 | } | 134 | } |
136 | 135 | ||
137 | translateBy (npmName: string, toTranslate: string) { | 136 | async translateSetting (npmName: string, setting: RegisterClientFormFieldOptions) { |
138 | const helpers = this.helpers[npmName] | 137 | for (const key of [ 'label', 'html', 'descriptionHTML' ]) { |
139 | if (!helpers) { | 138 | if (setting[key]) setting[key] = await this.translateBy(npmName, setting[key]) |
140 | console.error('Unknown helpers to translate %s from %s.', toTranslate, npmName) | ||
141 | return toTranslate | ||
142 | } | 139 | } |
143 | 140 | ||
144 | return helpers.translate(toTranslate) | 141 | if (Array.isArray(setting.options)) { |
142 | const newOptions = [] | ||
143 | |||
144 | for (const o of setting.options) { | ||
145 | newOptions.push({ | ||
146 | value: o.value, | ||
147 | label: await this.translateBy(npmName, o.label) | ||
148 | }) | ||
149 | } | ||
150 | |||
151 | setting.options = newOptions | ||
152 | } | ||
145 | } | 153 | } |
146 | 154 | ||
147 | private onFormFields (commonOptions: RegisterClientFormFieldOptions, videoFormOptions: RegisterClientVideoFieldOptions) { | 155 | translateBy (npmName: string, toTranslate: string) { |
156 | const obs = this.translationsObservable | ||
157 | .pipe( | ||
158 | map(allTranslations => allTranslations[npmName]), | ||
159 | map(translations => peertubeTranslate(toTranslate, translations)) | ||
160 | ) | ||
161 | |||
162 | return firstValueFrom(obs) | ||
163 | } | ||
164 | |||
165 | private onFormFields ( | ||
166 | pluginInfo: PluginInfo, | ||
167 | commonOptions: RegisterClientFormFieldOptions, | ||
168 | videoFormOptions: RegisterClientVideoFieldOptions | ||
169 | ) { | ||
148 | this.formFields.video.push({ | 170 | this.formFields.video.push({ |
171 | pluginInfo, | ||
149 | commonOptions, | 172 | commonOptions, |
150 | videoFormOptions | 173 | videoFormOptions |
151 | }) | 174 | }) |
152 | } | 175 | } |
153 | 176 | ||
154 | private onSettingsScripts (pluginInfo: PluginInfo, options: RegisterClientSettingsScriptOptions) { | 177 | private onSettingsScripts (pluginInfo: PluginInfo, options: RegisterClientSettingsScriptOptions) { |
155 | const npmName = this.nameToNpmName(pluginInfo.plugin.name, pluginInfo.pluginType) | 178 | this.settingsScripts[pluginInfo.plugin.npmName] = options |
156 | |||
157 | this.settingsScripts[npmName] = options | ||
158 | } | 179 | } |
159 | 180 | ||
160 | private onClientRoute (options: RegisterClientRouteOptions) { | 181 | private onClientRoute (options: RegisterClientRouteOptions) { |
@@ -167,7 +188,7 @@ export class PluginService implements ClientHook { | |||
167 | 188 | ||
168 | private buildPeerTubeHelpers (pluginInfo: PluginInfo): RegisterClientHelpers { | 189 | private buildPeerTubeHelpers (pluginInfo: PluginInfo): RegisterClientHelpers { |
169 | const { plugin } = pluginInfo | 190 | const { plugin } = pluginInfo |
170 | const npmName = this.nameToNpmName(pluginInfo.plugin.name, pluginInfo.pluginType) | 191 | const npmName = pluginInfo.plugin.npmName |
171 | 192 | ||
172 | return { | 193 | return { |
173 | getBaseStaticRoute: () => { | 194 | getBaseStaticRoute: () => { |
@@ -241,11 +262,7 @@ export class PluginService implements ClientHook { | |||
241 | }, | 262 | }, |
242 | 263 | ||
243 | translate: (value: string) => { | 264 | translate: (value: string) => { |
244 | const obs = this.translationsObservable | 265 | return this.translateBy(npmName, value) |
245 | .pipe(map(allTranslations => allTranslations[npmName])) | ||
246 | .pipe(map(translations => peertubeTranslate(value, translations))) | ||
247 | |||
248 | return firstValueFrom(obs) | ||
249 | } | 266 | } |
250 | } | 267 | } |
251 | } | 268 | } |