mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
Implemented i18n cache busting
This commit is contained in:
@@ -5,6 +5,7 @@ import { NGX_TRANSLATE_STATE, NgxTranslateState } from './ngx-translate-state';
|
||||
import { hasValue } from '../app/shared/empty.util';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { of as observableOf, Observable } from 'rxjs';
|
||||
import { environment } from '../environments/environment';
|
||||
|
||||
/**
|
||||
* A TranslateLoader for ngx-translate to retrieve i18n messages from the TransferState, or download
|
||||
@@ -33,9 +34,10 @@ export class TranslateBrowserLoader implements TranslateLoader {
|
||||
if (hasValue(messages)) {
|
||||
return observableOf(messages);
|
||||
} else {
|
||||
const translationHash: string = environment.production ? `.${(process.env.languageHashes as any)[lang + '.json5']}` : '';
|
||||
// If they're not available on the transfer state (e.g. when running in dev mode), retrieve
|
||||
// them using HttpClient
|
||||
return this.http.get('' + this.prefix + lang + this.suffix, { responseType: 'text' }).pipe(
|
||||
return this.http.get(`${this.prefix}${lang}${translationHash}${this.suffix}`, { responseType: 'text' }).pipe(
|
||||
map((json: any) => JSON.parse(json))
|
||||
);
|
||||
}
|
||||
|
@@ -23,8 +23,9 @@ export class TranslateServerLoader implements TranslateLoader {
|
||||
* @param lang the language code
|
||||
*/
|
||||
public getTranslation(lang: string): Observable<any> {
|
||||
const translationHash: string = (process.env.languageHashes as any)[lang + '.json5'];
|
||||
// Retrieve the file for the given language, and parse it
|
||||
const messages = JSON.parse(readFileSync(`${this.prefix}${lang}${this.suffix}`, 'utf8'));
|
||||
const messages = JSON.parse(readFileSync(`${this.prefix}${lang}.${translationHash}${this.suffix}`, 'utf8'));
|
||||
// Store the parsed messages in the transfer state so they'll be available immediately when the
|
||||
// app loads on the client
|
||||
this.storeInTransferState(lang, messages);
|
||||
|
Reference in New Issue
Block a user