changes and optimisations

This commit is contained in:
sdarbinyan
2026-03-06 17:45:34 +04:00
parent c112aded47
commit c3e4e695eb
9 changed files with 129 additions and 69 deletions

View File

@@ -7,19 +7,30 @@ import { LanguageService } from '../services/language.service';
})
export class LangRoutePipe implements PipeTransform {
private langService = inject(LanguageService);
private lastLang = '';
private lastInput: unknown = null;
private lastResult: string | (string | number)[] = '';
transform(value: string | (string | number)[]): string | (string | number)[] {
const lang = this.langService.currentLanguage();
// Short-circuit if nothing changed
if (lang === this.lastLang && value === this.lastInput) {
return this.lastResult;
}
this.lastLang = lang;
this.lastInput = value;
if (typeof value === 'string') {
return value === '/' ? `/${lang}` : `/${lang}${value}`;
}
if (Array.isArray(value) && value.length > 0) {
this.lastResult = value === '/' ? `/${lang}` : `/${lang}${value}`;
} else if (Array.isArray(value) && value.length > 0) {
const [first, ...rest] = value;
return [`/${lang}${first}`, ...rest];
this.lastResult = [`/${lang}${first}`, ...rest];
} else {
this.lastResult = value;
}
return value;
return this.lastResult;
}
}