Skip to content

Commit

Permalink
fix title, translate with slot (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
illfixit authored Oct 4, 2024
1 parent 69ad5ab commit 37b40e1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
12 changes: 12 additions & 0 deletions src/app/core/utils/i18n-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export interface AvailableLanguage {
code: string;
name: string;
}

export const supportedLanguages: AvailableLanguage[] = [
{code: 'en', name: 'English'},
{code: 'de', name: 'Deutsch'},
];

export const isLanguageSupported = (value: unknown): value is string =>
supportedLanguages.map((it) => it.code).includes(value as string);
10 changes: 9 additions & 1 deletion src/app/routes/connector-ui/connector-ui.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {map, shareReplay} from 'rxjs/operators';
import {TranslateService} from '@ngx-translate/core';
import {NavItemGroup} from 'src/app/core/services/models/nav-item-group';
import {NavItemsBuilder} from 'src/app/core/services/nav-items-builder';
import {isLanguageSupported} from 'src/app/core/utils/i18n-utils';
import {LocalStoredValue} from 'src/app/core/utils/local-stored-value';
import {APP_CONFIG, AppConfig} from '../../core/config/app-config';
import {LoginPollingService} from '../../core/services/login-polling.service';

Expand All @@ -24,6 +26,12 @@ export class ConnectorUiComponent implements OnInit {

navItemGroups: NavItemGroup[] = [];

selectedLanguage = new LocalStoredValue<string>(
'en',
'selectedLanguage',
isLanguageSupported,
);

constructor(
@Inject(APP_CONFIG) public config: AppConfig,
public titleService: Title,
Expand All @@ -34,7 +42,7 @@ export class ConnectorUiComponent implements OnInit {
) {
this.navItemGroups = this.navItemsBuilder.buildNavItemGroups();
this.translateService.setDefaultLang('en');
this.translateService.use(localStorage.getItem('selectedLanguage') || 'en');
this.translateService.use(this.selectedLanguage.value);
}

ngOnInit() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
import {Component, OnInit} from '@angular/core';
import {TranslateService} from '@ngx-translate/core';
import {
AvailableLanguage,
isLanguageSupported,
supportedLanguages,
} from 'src/app/core/utils/i18n-utils';
import {LocalStoredValue} from '../../../core/utils/local-stored-value';

interface AvailableLanguage {
code: string;
name: string;
}

@Component({
selector: 'app-language-selector',
templateUrl: './language-selector.component.html',
})
export class LanguageSelectorComponent implements OnInit {
supportedLanguages: AvailableLanguage[] = [
{code: 'en', name: 'English'},
{code: 'de', name: 'Deutsch'},
];

selectedLanguage = new LocalStoredValue<string>(
'en',
'selectedLanguage',
(value): value is string =>
this.supportedLanguages.map((it) => it.code).includes(value as string),
isLanguageSupported,
);

supportedLanguages = supportedLanguages;

constructor(private translateService: TranslateService) {}

ngOnInit(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ export class TranslateWithSlotComponent implements OnChanges, OnDestroy {
textAfter = '';

constructor(private translationService: TranslateService) {
this.splitText();
}

splitText() {
this.key$
.pipe(
switchMap(() => this.translationService.get(this.key)),
switchMap(() => this.translationService.stream(this.key)),
takeUntil(this.ngOnDestroy$),
)
.subscribe((text) => {
Expand Down

0 comments on commit 37b40e1

Please sign in to comment.