diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-06 17:37:13 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-06 17:37:13 +0200 |
commit | 74b7c6d48e9ca377fe938c8134ed74b612e62ba0 (patch) | |
tree | cb848dec054a71669fef5ea3986bdd0d2c354248 /client/src/app/core/server/server.service.ts | |
parent | 7ce44a74a3b052190cfacd4bd5ee6b92cfc620ac (diff) | |
download | PeerTube-74b7c6d48e9ca377fe938c8134ed74b612e62ba0.tar.gz PeerTube-74b7c6d48e9ca377fe938c8134ed74b612e62ba0.tar.zst PeerTube-74b7c6d48e9ca377fe938c8134ed74b612e62ba0.zip |
Little i18n refractoring
Diffstat (limited to 'client/src/app/core/server/server.service.ts')
-rw-r--r-- | client/src/app/core/server/server.service.ts | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index 56d33339e..74363e6a1 100644 --- a/client/src/app/core/server/server.service.ts +++ b/client/src/app/core/server/server.service.ts | |||
@@ -2,13 +2,13 @@ import { map, share, switchMap, tap } from 'rxjs/operators' | |||
2 | import { HttpClient } from '@angular/common/http' | 2 | import { HttpClient } from '@angular/common/http' |
3 | import { Inject, Injectable, LOCALE_ID } from '@angular/core' | 3 | import { Inject, Injectable, LOCALE_ID } from '@angular/core' |
4 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' | 4 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' |
5 | import { Observable, ReplaySubject } from 'rxjs' | 5 | import { Observable, ReplaySubject, of } from 'rxjs' |
6 | import { ServerConfig } from '../../../../../shared' | 6 | import { getCompleteLocale, ServerConfig } from '../../../../../shared' |
7 | import { About } from '../../../../../shared/models/server/about.model' | 7 | import { About } from '../../../../../shared/models/server/about.model' |
8 | import { environment } from '../../../environments/environment' | 8 | import { environment } from '../../../environments/environment' |
9 | import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos' | 9 | import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos' |
10 | import { buildFileLocale, getDefaultLocale } from '../../../../../shared/models/i18n' | 10 | import { isDefaultLocale } from '../../../../../shared/models/i18n' |
11 | import { peertubeTranslate } from '@app/shared/i18n/i18n-utils' | 11 | import { getDevLocale, isOnDevLocale, peertubeTranslate } from '@app/shared/i18n/i18n-utils' |
12 | 12 | ||
13 | @Injectable() | 13 | @Injectable() |
14 | export class ServerService { | 14 | export class ServerService { |
@@ -72,8 +72,8 @@ export class ServerService { | |||
72 | private http: HttpClient, | 72 | private http: HttpClient, |
73 | @Inject(LOCALE_ID) private localeId: string | 73 | @Inject(LOCALE_ID) private localeId: string |
74 | ) { | 74 | ) { |
75 | this.loadConfigLocally() | ||
76 | this.loadServerLocale() | 75 | this.loadServerLocale() |
76 | this.loadConfigLocally() | ||
77 | } | 77 | } |
78 | 78 | ||
79 | loadConfig () { | 79 | loadConfig () { |
@@ -163,14 +163,16 @@ export class ServerService { | |||
163 | } | 163 | } |
164 | 164 | ||
165 | private loadServerLocale () { | 165 | private loadServerLocale () { |
166 | const fileLocale = buildFileLocale(environment.production === true ? this.localeId : 'fr') | 166 | const completeLocale = isOnDevLocale() ? getDevLocale() : getCompleteLocale(this.localeId) |
167 | 167 | ||
168 | // Default locale, nothing to translate | 168 | // Default locale, nothing to translate |
169 | const defaultFileLocale = buildFileLocale(getDefaultLocale()) | 169 | if (isDefaultLocale(completeLocale)) { |
170 | if (fileLocale === defaultFileLocale) return {} | 170 | this.localeObservable = of({}).pipe(share()) |
171 | return | ||
172 | } | ||
171 | 173 | ||
172 | this.localeObservable = this.http | 174 | this.localeObservable = this.http |
173 | .get(ServerService.BASE_LOCALE_URL + fileLocale + '/server.json') | 175 | .get(ServerService.BASE_LOCALE_URL + completeLocale + '/server.json') |
174 | .pipe(share()) | 176 | .pipe(share()) |
175 | } | 177 | } |
176 | 178 | ||