From 5c2560d618791bd5ef85d49befb34f8f57e30ecc Mon Sep 17 00:00:00 2001 From: Florian Eisenmenger Date: Thu, 18 Jan 2024 17:07:43 +0100 Subject: [PATCH] translate --- README.md | 3 + matsen-tool/package.json | 2 + matsen-tool/src/app/app.component.html | 13 ++- matsen-tool/src/app/app.component.ts | 5 +- matsen-tool/src/app/app.module.ts | 21 ++++- matsen-tool/src/assets/i18n/de.json | 7 ++ .../assets/images/specific/matsen_logo.svg | 88 +++++++++++++++++++ 7 files changed, 132 insertions(+), 7 deletions(-) create mode 100644 matsen-tool/src/assets/i18n/de.json create mode 100644 matsen-tool/src/assets/images/specific/matsen_logo.svg diff --git a/README.md b/README.md index 38434b6..4f6a59f 100644 --- a/README.md +++ b/README.md @@ -44,3 +44,6 @@ - https://openapi-generator.tech/docs/installation - https://www.kevinboosten.dev/how-i-use-an-openapi-spec-in-my-angular-projects +- https://material.angular.io/ +- https://ng-bootstrap.github.io/#/home + diff --git a/matsen-tool/package.json b/matsen-tool/package.json index f2fd7c3..0c94b3e 100644 --- a/matsen-tool/package.json +++ b/matsen-tool/package.json @@ -22,6 +22,8 @@ "@angular/platform-browser-dynamic": "^17.0.0", "@angular/router": "^17.0.0", "@ng-bootstrap/ng-bootstrap": "^16.0.0-rc.2", + "@ngx-translate/core": "^15.0.0", + "@ngx-translate/http-loader": "^8.0.0", "@popperjs/core": "^2.11.8", "bootstrap": "^5.3.2", "bootstrap-icons": "^1.11.2", diff --git a/matsen-tool/src/app/app.component.html b/matsen-tool/src/app/app.component.html index 970b494..84b7411 100644 --- a/matsen-tool/src/app/app.component.html +++ b/matsen-tool/src/app/app.component.html @@ -1,9 +1,14 @@  diff --git a/matsen-tool/src/app/app.component.ts b/matsen-tool/src/app/app.component.ts index b8b2901..39c4c4b 100644 --- a/matsen-tool/src/app/app.component.ts +++ b/matsen-tool/src/app/app.component.ts @@ -4,6 +4,7 @@ import {AccountService} from './_services'; import {User} from './_models'; import {Subscription} from "rxjs"; import {PostJsonld, PostService} from "@app/core/api/v1"; +import {TranslateService} from "@ngx-translate/core"; @Component({ selector: 'app-root', @@ -14,7 +15,9 @@ export class AppComponent implements OnInit { user?: User | null; - constructor(private postService: PostService, private accountService: AccountService) { + constructor(private postService: PostService, private accountService: AccountService, translate: TranslateService) { + translate.setDefaultLang('de'); + translate.use('de'); this.accountService.user.subscribe(x => this.user = x); } diff --git a/matsen-tool/src/app/app.module.ts b/matsen-tool/src/app/app.module.ts index 54b059e..92402ff 100644 --- a/matsen-tool/src/app/app.module.ts +++ b/matsen-tool/src/app/app.module.ts @@ -1,7 +1,7 @@ import {NgModule} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {ReactiveFormsModule} from '@angular/forms'; -import {HttpClientModule, HTTP_INTERCEPTORS} from '@angular/common/http'; +import {HttpClientModule, HTTP_INTERCEPTORS, HttpClient} from '@angular/common/http'; // used to create fake backend import {fakeBackendProvider} from './_helpers'; @@ -15,6 +15,9 @@ import {NgbModule} from "@ng-bootstrap/ng-bootstrap"; import {ApiModule, Configuration, ConfigurationParameters} from "@app/core/api/v1"; import {environment} from "@environments/environment"; import {MatCardModule} from "@angular/material/card"; +import {TranslateLoader, TranslateModule} from "@ngx-translate/core"; +import {TranslateHttpLoader} from "@ngx-translate/http-loader"; +import {NgOptimizedImage} from "@angular/common"; export function apiConfigFactory(): Configuration { const params: ConfigurationParameters = { @@ -24,15 +27,29 @@ export function apiConfigFactory(): Configuration { return new Configuration(params); } +// AoT requires an exported function for factories +export function HttpLoaderFactory(http: HttpClient) { + return new TranslateHttpLoader(http); +} + @NgModule({ imports: [ ApiModule.forRoot(apiConfigFactory), BrowserModule, + TranslateModule.forRoot({ + defaultLanguage: 'de', + loader: { + provide: TranslateLoader, + useFactory: HttpLoaderFactory, + deps: [HttpClient] + } + }), ReactiveFormsModule, HttpClientModule, NgbModule, AppRoutingModule, - MatCardModule + MatCardModule, + NgOptimizedImage ], declarations: [ AppComponent, diff --git a/matsen-tool/src/assets/i18n/de.json b/matsen-tool/src/assets/i18n/de.json new file mode 100644 index 0000000..a40f8f7 --- /dev/null +++ b/matsen-tool/src/assets/i18n/de.json @@ -0,0 +1,7 @@ +{ + "basic": + { + "logout": "Logout", + "company-name": "MATSEN CHEMIE AG" + } +} \ No newline at end of file diff --git a/matsen-tool/src/assets/images/specific/matsen_logo.svg b/matsen-tool/src/assets/images/specific/matsen_logo.svg new file mode 100644 index 0000000..93cbf07 --- /dev/null +++ b/matsen-tool/src/assets/images/specific/matsen_logo.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +