mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-9119] Fixed textOrientation getting reset on arabic after browser refresh (#10591)
* [ACS-9119] Fixed issue where hitting browser refresh on arabic language changes the direction from rtl to ltr * [ACS-9119] Added unit test * [ACS-9119] Fixed UI issue in sidenav where incorrect margin-right was set when switching window sizes * [ACS-9119] Addressed PR comments * [ACS-9119] Fixed sonar issue * [ACS-9119] Added margin-right 0 to mat-sidenav-content
This commit is contained in:
@@ -30,6 +30,7 @@ export * from './services/url.service';
|
|||||||
|
|
||||||
export * from './models/log-levels.model';
|
export * from './models/log-levels.model';
|
||||||
export * from './models/user-info-mode.enum';
|
export * from './models/user-info-mode.enum';
|
||||||
|
export * from './models/default-languages.model';
|
||||||
|
|
||||||
export * from './interface/search-component.interface';
|
export * from './interface/search-component.interface';
|
||||||
|
|
||||||
|
38
lib/core/src/lib/common/models/default-languages.model.ts
Normal file
38
lib/core/src/lib/common/models/default-languages.model.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { LanguageItem } from '../services/language-item.interface';
|
||||||
|
|
||||||
|
export const DEFAULT_LANGUAGE_LIST: LanguageItem[] = [
|
||||||
|
{ key: 'de', label: 'Deutsch' },
|
||||||
|
{ key: 'en', label: 'English' },
|
||||||
|
{ key: 'es', label: 'Español' },
|
||||||
|
{ key: 'fr', label: 'Français' },
|
||||||
|
{ key: 'it', label: 'Italiano' },
|
||||||
|
{ key: 'ja', label: '日本語' },
|
||||||
|
{ key: 'nb', label: 'Bokmål' },
|
||||||
|
{ key: 'nl', label: 'Nederlands' },
|
||||||
|
{ key: 'pt-BR', label: 'Português (Brasil)' },
|
||||||
|
{ key: 'ru', label: 'Русский' },
|
||||||
|
{ key: 'zh-CN', label: '中文简体' },
|
||||||
|
{ key: 'cs', label: 'Čeština' },
|
||||||
|
{ key: 'da', label: 'Dansk' },
|
||||||
|
{ key: 'fi', label: 'Suomi' },
|
||||||
|
{ key: 'pl', label: 'Polski' },
|
||||||
|
{ key: 'sv', label: 'Svenska' },
|
||||||
|
{ key: 'ar', label: 'العربية', direction: 'rtl' }
|
||||||
|
];
|
@@ -193,6 +193,19 @@ describe('UserPreferencesService', () => {
|
|||||||
expect(storage.getItem(textOrientation)).toBe('rtl');
|
expect(storage.getItem(textOrientation)).toBe('rtl');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should set direction from default languages when language config is not present', () => {
|
||||||
|
appConfig.config.languages = [
|
||||||
|
{
|
||||||
|
key: 'fake-locale-config',
|
||||||
|
direction: 'ltr'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
appConfig.config.locale = 'ar';
|
||||||
|
appConfig.load();
|
||||||
|
const textOrientation = preferences.getPropertyKey('textOrientation');
|
||||||
|
expect(storage.getItem(textOrientation)).toBe('rtl');
|
||||||
|
});
|
||||||
|
|
||||||
it('should not store textOrientation based on language ', () => {
|
it('should not store textOrientation based on language ', () => {
|
||||||
appConfig.config.languages = [
|
appConfig.config.languages = [
|
||||||
{
|
{
|
||||||
|
@@ -24,6 +24,7 @@ import { distinctUntilChanged, map } from 'rxjs/operators';
|
|||||||
import { LanguageItem } from './language-item.interface';
|
import { LanguageItem } from './language-item.interface';
|
||||||
import { DOCUMENT } from '@angular/common';
|
import { DOCUMENT } from '@angular/common';
|
||||||
import { Directionality, Direction } from '@angular/cdk/bidi';
|
import { Directionality, Direction } from '@angular/cdk/bidi';
|
||||||
|
import { DEFAULT_LANGUAGE_LIST } from '../models/default-languages.model';
|
||||||
|
|
||||||
// eslint-disable-next-line no-shadow
|
// eslint-disable-next-line no-shadow
|
||||||
export enum UserPreferenceValues {
|
export enum UserPreferenceValues {
|
||||||
@@ -246,11 +247,13 @@ export class UserPreferencesService {
|
|||||||
|
|
||||||
private getLanguageByKey(key: string): LanguageItem {
|
private getLanguageByKey(key: string): LanguageItem {
|
||||||
const defaultLanguage = { key: 'en' } as LanguageItem;
|
const defaultLanguage = { key: 'en' } as LanguageItem;
|
||||||
|
let language: LanguageItem;
|
||||||
|
|
||||||
const registeredLanguages = this.appConfig.get<Array<LanguageItem>>(AppConfigValues.APP_CONFIG_LANGUAGES_KEY);
|
const customLanguages = this.appConfig.get<Array<LanguageItem>>(AppConfigValues.APP_CONFIG_LANGUAGES_KEY);
|
||||||
if (registeredLanguages && Array.isArray(registeredLanguages)) {
|
if (Array.isArray(customLanguages)) {
|
||||||
return registeredLanguages.find((language) => key.includes(language.key)) || defaultLanguage;
|
language = customLanguages.find((customLanguage) => key.includes(customLanguage.key));
|
||||||
}
|
}
|
||||||
return defaultLanguage;
|
language ??= DEFAULT_LANGUAGE_LIST.find((defaultLang) => defaultLang.key === key) ?? defaultLanguage;
|
||||||
|
return language;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,36 +21,15 @@ import { BehaviorSubject } from 'rxjs';
|
|||||||
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
|
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
|
||||||
import { LanguageItem } from '../../common/services/language-item.interface';
|
import { LanguageItem } from '../../common/services/language-item.interface';
|
||||||
import { UserPreferencesService } from '../../common/services/user-preferences.service';
|
import { UserPreferencesService } from '../../common/services/user-preferences.service';
|
||||||
|
import { DEFAULT_LANGUAGE_LIST } from '../../common/models/default-languages.model';
|
||||||
|
|
||||||
@Injectable({providedIn: 'root'})
|
@Injectable({ providedIn: 'root' })
|
||||||
export class LanguageService implements LanguageServiceInterface {
|
export class LanguageService implements LanguageServiceInterface {
|
||||||
|
private languages = new BehaviorSubject<LanguageItem[]>(DEFAULT_LANGUAGE_LIST);
|
||||||
private languages = new BehaviorSubject<LanguageItem[]>([
|
|
||||||
{key: 'de', label: 'Deutsch'},
|
|
||||||
{key: 'en', label: 'English'},
|
|
||||||
{key: 'es', label: 'Español'},
|
|
||||||
{key: 'fr', label: 'Français'},
|
|
||||||
{key: 'it', label: 'Italiano'},
|
|
||||||
{key: 'ja', label: '日本語'},
|
|
||||||
{key: 'nb', label: 'Bokmål'},
|
|
||||||
{key: 'nl', label: 'Nederlands'},
|
|
||||||
{key: 'pt-BR', label: 'Português (Brasil)'},
|
|
||||||
{key: 'ru', label: 'Русский'},
|
|
||||||
{key: 'zh-CN', label: '中文简体'},
|
|
||||||
{key: 'cs', label: 'Čeština'},
|
|
||||||
{key: 'da', label: 'Dansk'},
|
|
||||||
{key: 'fi', label: 'Suomi'},
|
|
||||||
{key: 'pl', label: 'Polski'},
|
|
||||||
{key: 'sv', label: 'Svenska'},
|
|
||||||
{key: 'ar', label: 'العربية', direction: 'rtl'}
|
|
||||||
]);
|
|
||||||
|
|
||||||
languages$ = this.languages.asObservable();
|
languages$ = this.languages.asObservable();
|
||||||
|
|
||||||
constructor(
|
constructor(appConfigService: AppConfigService, private readonly userPreferencesService: UserPreferencesService) {
|
||||||
appConfigService: AppConfigService,
|
|
||||||
private userPreferencesService: UserPreferencesService) {
|
|
||||||
|
|
||||||
const customLanguages = appConfigService.get<Array<LanguageItem>>(AppConfigValues.APP_CONFIG_LANGUAGES_KEY);
|
const customLanguages = appConfigService.get<Array<LanguageItem>>(AppConfigValues.APP_CONFIG_LANGUAGES_KEY);
|
||||||
this.setLanguages(customLanguages);
|
this.setLanguages(customLanguages);
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<mat-sidenav-container class="adf-layout-container">
|
<mat-sidenav-container class="adf-layout-container" autosize>
|
||||||
<mat-sidenav
|
<mat-sidenav
|
||||||
class="adf-layout-container-sidenav"
|
class="adf-layout-container-sidenav"
|
||||||
[position]="position"
|
[position]="position"
|
||||||
|
@@ -37,6 +37,7 @@ adf-layout-container {
|
|||||||
#{$mat-sidenav-content},
|
#{$mat-sidenav-content},
|
||||||
#{$mat-drawer-transition} #{$mat-drawer-content} {
|
#{$mat-drawer-transition} #{$mat-drawer-content} {
|
||||||
margin-left: 0 !important;
|
margin-left: 0 !important;
|
||||||
|
margin-right: 0 !important;
|
||||||
transform: unset !important;
|
transform: unset !important;
|
||||||
transition-property: unset !important;
|
transition-property: unset !important;
|
||||||
transition-duration: unset !important;
|
transition-duration: unset !important;
|
||||||
|
Reference in New Issue
Block a user