diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-26 14:44:50 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-07-26 15:18:30 +0200 |
commit | d75db01f14138ea660c4c519e37ab05228b39d13 (patch) | |
tree | 85a3da315ea6e1501fec5b70790482504dd64793 /client/src/app/+admin | |
parent | ee286591a5b740702bad66c55cc900740f749e9a (diff) | |
download | PeerTube-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.ts | 25 |
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 @@ | |||
1 | import { catchError } from 'rxjs/operators' | 1 | import { catchError, map, switchMap } from 'rxjs/operators' |
2 | import { HttpClient, HttpParams } from '@angular/common/http' | 2 | import { HttpClient, HttpParams } from '@angular/common/http' |
3 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
4 | import { environment } from '../../../../environments/environment' | 4 | import { environment } from '../../../../environments/environment' |
@@ -6,13 +6,14 @@ import { RestExtractor, RestService } from '../../../shared' | |||
6 | import { I18n } from '@ngx-translate/i18n-polyfill' | 6 | import { I18n } from '@ngx-translate/i18n-polyfill' |
7 | import { PluginType } from '@shared/models/plugins/plugin.type' | 7 | import { PluginType } from '@shared/models/plugins/plugin.type' |
8 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | 8 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' |
9 | import { ResultList } from '@shared/models' | 9 | import { peertubeTranslate, ResultList } from '@shared/models' |
10 | import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model' | 10 | import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model' |
11 | import { ManagePlugin } from '@shared/models/plugins/manage-plugin.model' | 11 | import { ManagePlugin } from '@shared/models/plugins/manage-plugin.model' |
12 | import { InstallOrUpdatePlugin } from '@shared/models/plugins/install-plugin.model' | 12 | import { InstallOrUpdatePlugin } from '@shared/models/plugins/install-plugin.model' |
13 | import { PeerTubePluginIndex } from '@shared/models/plugins/peertube-plugin-index.model' | 13 | import { PeerTubePluginIndex } from '@shared/models/plugins/peertube-plugin-index.model' |
14 | import { RegisteredServerSettings, RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' | 14 | import { RegisteredServerSettings, RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' |
15 | import { PluginService } from '@app/core/plugins/plugin.service' | 15 | import { PluginService } from '@app/core/plugins/plugin.service' |
16 | import { Observable } from 'rxjs' | ||
16 | 17 | ||
17 | @Injectable() | 18 | @Injectable() |
18 | export class PluginApiService { | 19 | export 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 | } |