Skip to content

Commit

Permalink
Improve translation functionality (#4521)
Browse files Browse the repository at this point in the history
  • Loading branch information
luisa-beerboom authored Jan 9, 2025
1 parent 43cd095 commit 21aabc6
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 13 deletions.
5 changes: 5 additions & 0 deletions client/src/app/domain/definitions/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ export const availableTranslations = {
es: `Español`,
ru: `русский`
};

export const allAvailableTranslations = {
...availableTranslations,
[`1337`]: `1337`
};
8 changes: 6 additions & 2 deletions client/src/app/gateways/repositories/base-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export function canPerformListUpdates(repo: any): repo is CanPerformListUpdates<
return repo.listUpdate && typeof repo.listUpdate === `function`;
}

export function getIntlCollatorForLang(lang: string): Intl.Collator {
return new Intl.Collator(lang === `1337` ? `en` : lang);
}

enum PipelineActionType {
General = `general`,
Resort = `resort`,
Expand Down Expand Up @@ -185,7 +189,7 @@ export abstract class BaseRepository<V extends BaseViewModel, M extends BaseMode
}
});

this.languageCollator = new Intl.Collator(this.translate.currentLang);
this.languageCollator = getIntlCollatorForLang(this.translate.currentLang);
}

public onAfterAppsLoaded(): void {
Expand All @@ -200,7 +204,7 @@ export abstract class BaseRepository<V extends BaseViewModel, M extends BaseMode
}
});
this.translate.onLangChange.subscribe(change => {
this.languageCollator = new Intl.Collator(change.lang);
this.languageCollator = getIntlCollatorForLang(change.lang);
if (this.unsafeViewModelListSubject.value) {
this.updateViewModelListSubject(this.unsafeViewModelListSubject.value);
}
Expand Down
1 change: 1 addition & 0 deletions client/src/app/infrastructure/utils/lang-to-locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Locale } from 'date-fns';
*/
export function langToLocale(lang: string): string {
switch (lang) {
case `1337`:
case `en`: {
return `en-GB`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Router } from '@angular/router';
import { LangChangeEvent, TranslateService } from '@ngx-translate/core';
import { DateFnsConfigurationService } from 'ngx-date-fns';
import { first, firstValueFrom, tap } from 'rxjs';
import { availableTranslations } from 'src/app/domain/definitions/languages';
import { allAvailableTranslations } from 'src/app/domain/definitions/languages';
import { HasSequentialNumber } from 'src/app/domain/interfaces';
import { StorageService } from 'src/app/gateways/storage.service';
import { langToTimeLocale } from 'src/app/infrastructure/utils';
Expand Down Expand Up @@ -58,7 +58,7 @@ export class OpenSlidesMainComponent implements OnInit {

private loadTranslation(): void {
// manually add the supported languages
this.translate.addLangs(Object.keys(availableTranslations));
this.translate.addLangs(Object.keys(allAvailableTranslations));
// get the browsers default language
const browserLang = this.translate.getBrowserLang() as string;
let currentLang = `en`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

<!-- select language -->
<button #languageTrigger mat-menu-item [matMenuTriggerFor]="languageMenu">
<mat-icon class="menu-icon">language</mat-icon>
<mat-icon class="menu-icon" (click)="onLangIconClick()">language</mat-icon>
<span class="menu-text">{{ getCurrentLanguageName() }}</span>
</button>

Expand Down Expand Up @@ -110,5 +110,11 @@
<span>{{ lang.value }}</span>
</button>
}
@if (show1337 >= 0 || getCurrentLanguageName() === '1337') {
<button mat-menu-item (click)="selectLanguage('1337')">
<mat-icon>{{ getCurrentLanguageName() === '1337' ? 'check' : '' }}</mat-icon>
<span>1337</span>
</button>
}
</ng-template>
</mat-menu>
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { MatMenuTrigger } from '@angular/material/menu';
import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Observable } from 'rxjs';
import { Observable, Subscription } from 'rxjs';
import { Id } from 'src/app/domain/definitions/key-types';
import { availableTranslations } from 'src/app/domain/definitions/languages';
import { allAvailableTranslations, availableTranslations } from 'src/app/domain/definitions/languages';
import { getOmlVerboseName } from 'src/app/domain/definitions/organization-permission';
import { largeDialogSettings } from 'src/app/infrastructure/utils/dialog-settings';
import { mediumDialogSettings } from 'src/app/infrastructure/utils/dialog-settings';
Expand Down Expand Up @@ -33,8 +33,16 @@ export class AccountButtonComponent extends BaseUiComponent implements OnInit {
@ViewChild(`languageTrigger`, { read: MatMenuTrigger })
public set languageTrigger(trigger: MatMenuTrigger | undefined) {
this._languageTrigger = trigger;
this._langTriggerSubscription?.unsubscribe();
this._langTriggerSubscription = this._languageTrigger?.menuClosed.subscribe(() => {
if (this.show1337 < 0) {
this.show1337 = -20;
}
});
}

private _langTriggerSubscription: Subscription;

public get isPresent(): boolean {
return this.hasActiveMeeting && this.operator.isInMeeting(this.activeMeetingId) && !this.operator.isAnonymous
? this.user.isPresentInMeeting()
Expand Down Expand Up @@ -64,6 +72,8 @@ export class AccountButtonComponent extends BaseUiComponent implements OnInit {
public username = ``;
public isLoggedIn = false;

public show1337 = -20;

private get activeMeetingId(): Id | null {
return this.activeMeetingIdService.meetingId;
}
Expand Down Expand Up @@ -110,7 +120,7 @@ export class AccountButtonComponent extends BaseUiComponent implements OnInit {
* language should be used.
*/
public getLanguageName(abbreviation: string): string {
return availableTranslations[abbreviation] || `No language`;
return allAvailableTranslations[abbreviation] || `No language`;
}

public selectLanguage(abbreviation: string): void {
Expand Down Expand Up @@ -184,6 +194,15 @@ export class AccountButtonComponent extends BaseUiComponent implements OnInit {
return ``;
}

public onLangIconClick(): void {
this.show1337++;
}

protected override cleanSubscriptions(): void {
this._langTriggerSubscription.unsubscribe();
super.cleanSubscriptions();
}

private onOperatorUpdate(): void {
this.isLoggedIn = !this.operator.isAnonymous;
this.username = this.operator.shortName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export class PruningTranslationLoader implements TranslateLoader {
if (lang != this.defaultLanguage) {
return combineLatest([
this.http
.get(`${this.prefix}${lang}${this.suffix}`, { responseType: `text` })
.pipe(map((content: string) => this.parse(content))),
.get(`${this.prefix}${lang !== `1337` ? lang : `de`}${this.suffix}`, { responseType: `text` })
.pipe(map((content: string) => this.parse(content, lang === `1337`))),
this.ctService.customTranslationSubject
]).pipe(
map(([t, ct]) => {
Expand All @@ -66,17 +66,45 @@ export class PruningTranslationLoader implements TranslateLoader {
);
}

private parse(content: string): any {
private parse(content: string, t1337: boolean): any {
const translations: { [key: string]: string } = {};

const po = pofile.parse(content);
for (const item of po.items) {
const translation: string = item.msgstr.pop();
const translation: string = t1337 ? this.t1337(item.msgid) : item.msgstr.pop();
if (item.msgid.length > 0 && translation.length > 0) {
translations[item.msgid] = translation;
}
}

return translations;
}

private dict1337: { [char: string]: string } = {
a: `4`,
b: `8`,
c: `(`,
e: `3`,
f: `PH`,
g: `6`,
h: `#`,
i: `!`,
k: `|<`,
l: `1`,
o: `°`,
q: `0`,
s: `5`,
t: `7`,
v: `\\/`,
w: `VV`,
y: `\`/`,
z: `2`
};

private t1337(str: string): string {
return str
.toLowerCase()
.split(``)
.reduce((prev, curr) => prev + (this.dict1337[curr] ?? curr.toUpperCase()), ``);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { TranslateService } from '@ngx-translate/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { Id } from 'src/app/domain/definitions/key-types';
import { Mediafile } from 'src/app/domain/models/mediafiles/mediafile';
import { getIntlCollatorForLang } from 'src/app/gateways/repositories/base-repository';
import { infoDialogSettings } from 'src/app/infrastructure/utils/dialog-settings';
import { ViewMediafile, ViewMeetingMediafile } from 'src/app/site/pages/meetings/pages/mediafiles';
import { MediafileControllerService } from 'src/app/site/pages/meetings/pages/mediafiles/services/mediafile-controller.service';
Expand Down Expand Up @@ -228,7 +229,7 @@ export class FileListComponent extends BaseUiComponent implements OnInit, OnDest
public ngOnInit(): void {
this._languageCollator = new Intl.Collator(this.translate.currentLang);
this.translate.onLangChange.subscribe(changeEvent => {
this._languageCollator = new Intl.Collator(changeEvent.lang);
this._languageCollator = getIntlCollatorForLang(changeEvent.lang);
this.updateView();
});
if (this.sourceFiles instanceof Observable) {
Expand Down

0 comments on commit 21aabc6

Please sign in to comment.