UNPKG

@pepperi/core

Version:

This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 10.0.5.

57 lines (49 loc) 1.95 kB
import {Directive, Renderer2, ElementRef, OnInit} from '@angular/core'; // Const BIDI_RTL_LANGS Array // BIDI_RTL_LANGS ref: http://en.wikipedia.org/wiki/Right-to-left // Table of scripts in Unicode: https://en.wikipedia.org/wiki/Script_(Unicode) const _BIDI_RTL_LANGS = [ 'ae', /* Avestan */ 'ar', /* 'العربية', Arabic */ 'arc', /* Aramaic */ 'bcc', /* 'بلوچی مکرانی', Southern Balochi */ 'bqi', /* 'بختياري', Bakthiari */ 'ckb', /* 'Soranî / کوردی', Sorani */ 'dv', /* Dhivehi */ 'fa', /* 'فارسی', Persian */ 'glk', /* 'گیلکی', Gilaki */ 'he', /* 'עברית', Hebrew */ 'ku', /* 'Kurdî / كوردی', Kurdish */ 'mzn', /* 'مازِرونی', Mazanderani */ 'nqo', /* N'Ko */ 'pnb', /* 'پنجابی', Western Punjabi */ 'ps', /* 'پښتو', Pashto, */ 'sd', /* 'سنڌي', Sindhi */ 'ug', /* 'Uyghurche / ئۇيغۇرچە', Uyghur */ 'ur', /* 'اردو', Urdu */ 'yi' /* 'ייִדיש', Yiddish */ ]; @Directive({ selector: '[pepperiRtlClass]', }) export class RtlClassDirective implements OnInit { constructor(private renderer: Renderer2, private hostElement: ElementRef) {} ngOnInit(): void { const userLang = navigator.language; const isRtl = userLang.indexOf(userLang) >= 0; if (isRtl) { this.renderer.addClass(this.hostElement.nativeElement, 'rtl'); } } } @Directive({ selector: '[pepperiRtlDirection]', }) export class RtlDirectionDirective implements OnInit { constructor(private renderer: Renderer2, private hostElement: ElementRef) {} ngOnInit(): void { const userLang = navigator.language; const isRtl = userLang.indexOf(userLang) >= 0; this.renderer.setAttribute(this.hostElement.nativeElement, 'dir', isRtl ? 'rtl' : 'ltr'); } }