Skip to content

Commit

Permalink
UI: Transloco configuration is missing a fallback language
Browse files Browse the repository at this point in the history
The solution to fix that is issue is to return an empty translation list in case of an error. In this way, Transloco will not translate anything (the UI will be in english), but it will not fail either.

Fixes: https://github.com/aquarist-labs/s3gw/issues/846

Signed-off-by: Volker Theile <[email protected]>
  • Loading branch information
votdev committed Nov 29, 2023
1 parent 1eeb0f3 commit 24a56d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Do not escape object key in page title (aquarist-labs/s3gw#839).
- Make sure a missing translation file does not crash the app (aquarist-labs/s3gw#846).

## [0.23.0]

Expand Down
11 changes: 9 additions & 2 deletions src/frontend/src/app/transloco-root.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
TranslocoModule
} from '@ngneat/transloco';
import * as _ from 'lodash';
import { Observable } from 'rxjs';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';

import { supportedLanguages } from '~/app/i18n.helper';
import { environment } from '~/environments/environment';
Expand All @@ -21,7 +22,13 @@ class CustomLoader implements TranslocoLoader {
constructor(private http: HttpClient) {}

public getTranslation(lang: string): Observable<Translation> {
return this.http.get<Translation>(`assets/i18n/${lang}.json`);
return this.http.get<Translation>(`assets/i18n/${lang}.json`).pipe(
catchError((err) => {
// Return an empty translation list. In this way, Transloco will
// not translate anything, but it will not fail either.
return of({});
})
);
}
}

Expand Down

0 comments on commit 24a56d1

Please sign in to comment.