Skip to content

Commit

Permalink
#2702 Allow retrieval from languageHashes using environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Mahnke committed Dec 7, 2023
1 parent 8ba14aa commit af30d20
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ngx-translate-loaders/translate-browser.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class TranslateBrowserLoader implements TranslateLoader {
if (hasValue(messages)) {
return observableOf(messages);
} else {
const translationHash: string = environment.production ? `.${(process.env.languageHashes as any)[lang + '.json5']}` : '';
const translationHash: string = environment.production ? `.${(environment["languageHashes"] !== undefined ? environment["languageHashes"] : process.env.languageHashes as any)[lang + '.json5']}` : '';

Check failure on line 37 in src/ngx-translate-loaders/translate-browser.loader.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

["languageHashes"] is better written in dot notation

Check failure on line 37 in src/ngx-translate-loaders/translate-browser.loader.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

Strings must use singlequote

Check failure on line 37 in src/ngx-translate-loaders/translate-browser.loader.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

["languageHashes"] is better written in dot notation

Check failure on line 37 in src/ngx-translate-loaders/translate-browser.loader.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

Strings must use singlequote

Check failure on line 37 in src/ngx-translate-loaders/translate-browser.loader.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

["languageHashes"] is better written in dot notation

Check failure on line 37 in src/ngx-translate-loaders/translate-browser.loader.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Strings must use singlequote

Check failure on line 37 in src/ngx-translate-loaders/translate-browser.loader.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

["languageHashes"] is better written in dot notation

Check failure on line 37 in src/ngx-translate-loaders/translate-browser.loader.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Strings must use singlequote
// 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}${translationHash}${this.suffix}`, { responseType: 'text' }).pipe(
Expand Down
3 changes: 2 additions & 1 deletion src/ngx-translate-loaders/translate-server.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Observable, of as observableOf } from 'rxjs';
import { readFileSync } from 'fs';
import { TransferState } from '@angular/platform-browser';
import { NGX_TRANSLATE_STATE, NgxTranslateState } from './ngx-translate-state';
import { environment } from "../environments/environment";

Check failure on line 6 in src/ngx-translate-loaders/translate-server.loader.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

Strings must use singlequote

Check failure on line 6 in src/ngx-translate-loaders/translate-server.loader.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Strings must use singlequote

/**
* A TranslateLoader for ngx-translate to parse json5 files server-side, and store them in the
Expand All @@ -23,7 +24,7 @@ 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'];
const translationHash: string = (environment["languageHashes"] !== undefined ? environment["languageHashes"] : process.env.languageHashes as any)[lang + '.json5'];

Check failure on line 27 in src/ngx-translate-loaders/translate-server.loader.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

["languageHashes"] is better written in dot notation

Check failure on line 27 in src/ngx-translate-loaders/translate-server.loader.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

Strings must use singlequote

Check failure on line 27 in src/ngx-translate-loaders/translate-server.loader.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

["languageHashes"] is better written in dot notation

Check failure on line 27 in src/ngx-translate-loaders/translate-server.loader.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

Strings must use singlequote

Check failure on line 27 in src/ngx-translate-loaders/translate-server.loader.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

["languageHashes"] is better written in dot notation

Check failure on line 27 in src/ngx-translate-loaders/translate-server.loader.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Strings must use singlequote

Check failure on line 27 in src/ngx-translate-loaders/translate-server.loader.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

["languageHashes"] is better written in dot notation

Check failure on line 27 in src/ngx-translate-loaders/translate-server.loader.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Strings must use singlequote
// Retrieve the file for the given language, and parse it
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
Expand Down

0 comments on commit af30d20

Please sign in to comment.