aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-26 14:44:50 +0200
committerChocobozzz <me@florianbigard.com>2019-07-26 15:18:30 +0200
commitd75db01f14138ea660c4c519e37ab05228b39d13 (patch)
tree85a3da315ea6e1501fec5b70790482504dd64793 /client/src/app/+admin
parentee286591a5b740702bad66c55cc900740f749e9a (diff)
downloadPeerTube-d75db01f14138ea660c4c519e37ab05228b39d13.tar.gz
PeerTube-d75db01f14138ea660c4c519e37ab05228b39d13.tar.zst
PeerTube-d75db01f14138ea660c4c519e37ab05228b39d13.zip
Add plugin translation system
Diffstat (limited to 'client/src/app/+admin')
-rw-r--r--client/src/app/+admin/plugins/shared/plugin-api.service.ts25
1 files changed, 22 insertions, 3 deletions
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 c360fc1b3..f6ef68e9c 100644
--- a/client/src/app/+admin/plugins/shared/plugin-api.service.ts
+++ b/client/src/app/+admin/plugins/shared/plugin-api.service.ts
@@ -1,4 +1,4 @@
1import { catchError } from 'rxjs/operators' 1import { catchError, map, switchMap } from 'rxjs/operators'
2import { HttpClient, HttpParams } from '@angular/common/http' 2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Injectable } from '@angular/core' 3import { Injectable } from '@angular/core'
4import { environment } from '../../../../environments/environment' 4import { environment } from '../../../../environments/environment'
@@ -6,13 +6,14 @@ import { RestExtractor, RestService } from '../../../shared'
6import { I18n } from '@ngx-translate/i18n-polyfill' 6import { I18n } from '@ngx-translate/i18n-polyfill'
7import { PluginType } from '@shared/models/plugins/plugin.type' 7import { PluginType } from '@shared/models/plugins/plugin.type'
8import { ComponentPagination } from '@app/shared/rest/component-pagination.model' 8import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
9import { ResultList } from '@shared/models' 9import { peertubeTranslate, ResultList } from '@shared/models'
10import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model' 10import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model'
11import { ManagePlugin } from '@shared/models/plugins/manage-plugin.model' 11import { ManagePlugin } from '@shared/models/plugins/manage-plugin.model'
12import { InstallOrUpdatePlugin } from '@shared/models/plugins/install-plugin.model' 12import { InstallOrUpdatePlugin } from '@shared/models/plugins/install-plugin.model'
13import { PeerTubePluginIndex } from '@shared/models/plugins/peertube-plugin-index.model' 13import { PeerTubePluginIndex } from '@shared/models/plugins/peertube-plugin-index.model'
14import { RegisteredServerSettings, RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' 14import { RegisteredServerSettings, RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model'
15import { PluginService } from '@app/core/plugins/plugin.service' 15import { PluginService } from '@app/core/plugins/plugin.service'
16import { Observable } from 'rxjs'
16 17
17@Injectable() 18@Injectable()
18export class PluginApiService { 19export class PluginApiService {
@@ -92,7 +93,10 @@ export class PluginApiService {
92 const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName + '/registered-settings' 93 const path = PluginApiService.BASE_PLUGIN_URL + '/' + npmName + '/registered-settings'
93 94
94 return this.authHttp.get<RegisteredServerSettings>(path) 95 return this.authHttp.get<RegisteredServerSettings>(path)
95 .pipe(catchError(res => this.restExtractor.handleError(res))) 96 .pipe(
97 switchMap(res => this.translateSettingsLabel(npmName, res)),
98 catchError(res => this.restExtractor.handleError(res))
99 )
96 } 100 }
97 101
98 updatePluginSettings (pluginName: string, pluginType: PluginType, settings: any) { 102 updatePluginSettings (pluginName: string, pluginType: PluginType, settings: any) {
@@ -129,4 +133,19 @@ export class PluginApiService {
129 return this.authHttp.post(PluginApiService.BASE_PLUGIN_URL + '/install', body) 133 return this.authHttp.post(PluginApiService.BASE_PLUGIN_URL + '/install', body)
130 .pipe(catchError(res => this.restExtractor.handleError(res))) 134 .pipe(catchError(res => this.restExtractor.handleError(res)))
131 } 135 }
136
137 private translateSettingsLabel (npmName: string, res: RegisteredServerSettings): Observable<RegisteredServerSettings> {
138 return this.pluginService.translationsObservable
139 .pipe(
140 map(allTranslations => allTranslations[npmName]),
141 map(translations => {
142 const registeredSettings = res.registeredSettings
143 .map(r => {
144 return Object.assign({}, r, { label: peertubeTranslate(r.label, translations) })
145 })
146
147 return { registeredSettings }
148 })
149 )
150 }
132} 151}