Implement auto RTL support for i18n locales like Arabic, Persian, etc.

Fixes #255
This commit is contained in:
wiz 2020-12-04 05:56:40 +09:00
parent ea521651fd
commit e49ecd9368
No known key found for this signature in database
GPG Key ID: A394E332255A6173

View File

@ -1,4 +1,4 @@
import { Component, HostListener, OnInit } from '@angular/core';
import { Component, HostListener, OnInit, Inject, LOCALE_ID, HostBinding } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { WebsocketService } from '../../services/websocket.service';
import { StateService } from 'src/app/services/state.service';
@ -15,7 +15,14 @@ export class AppComponent implements OnInit {
public router: Router,
private websocketService: WebsocketService,
private stateService: StateService,
) { }
@Inject(LOCALE_ID) private locale: string,
) {
if (this.locale.startsWith('ar') || this.locale.startsWith('fa')) {
this.dir = 'rtl';
}
}
@HostBinding('attr.dir') dir = 'ltr';
@HostListener('document:keydown', ['$event'])
handleKeyboardEvents(event: KeyboardEvent) {