Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Angular 7 how to load CSS of Arabic language (RTL) from English language (LTR)

I am developing an application in Angular 7 using ngx-translate for internationalization and bootstrap based AdminLTE 3. I have two css:

  1. One for LTR based languages
  2. another for RTL based languages.

When I select Arabic language which is a RTL direction, how to load the bootstrap_rtl.css and unload the bootstrap_ltr.css.

<div class="dropdown-menu dropdown-menu-sm dropdown-menu-right">
    <a class="dropdown-item" (click)="useLanguage('en')">
      English
    </a>
    <div class="dropdown-divider"></div>
    <a class="dropdown-item" (click)="useLanguage('ar')">
      Arabic
    </a>
    <div class="dropdown-divider"></div>
    <a class="dropdown-item" (click)="useLanguage('ta')">
      Russian
    </a>
</div>

export class NavbarComponent implements OnInit {
  constructor(private translate: TranslateService) { }
  ngOnInit() {
  }

  useLanguage(language: string) {
    this.translate.use(language);
  }
}
like image 248
MOHAMMED SADULLAH Avatar asked Jan 06 '20 07:01

MOHAMMED SADULLAH


People also ask

How do I use rtl in CSS?

The direction CSS property sets the direction of text, table columns, and horizontal overflow. Use rtl for languages written from right to left (like Hebrew or Arabic), and ltr for those written from left to right (like English and most other languages).

How do you convert rtl to LTR?

Shortcuts: Ctrl+Shift+J -- switch to RTL Ctrl+Shift+E -- switch to LTR Note 1: If one or both of the shortcuts don't work, it means that something else is mapped to them.

How do you rtl?

Quick answer. If the overall document direction is right-to-left, add dir="rtl" to the html tag. Below the html tag, only use the dir attribute on structural elements on the rare occasions when the base direction needs to change in order for the text to display correctly. Never use CSS to apply the base direction.

What is rtl JavaScript?

JavaScript Data Grid: RTL - Right To Left. RTL is used for displaying languages that go from Right to Left, eg Hebrew and Arabic. To get AG Grid to display in RTL format, set the property enableRtl=true .


1 Answers

you can create a key in the translation file as flage of the current theme if it's rtl or ltr and this value will change base of the language that you have select

style.scss

.ltr {
  @import 'themes/_en';
}

.rtl {
    @import 'themes/_ar';
}

_ar.json

{
  "currentTheme":"rtl"
}

_en.json

{
  "currentTheme":"ltr"
}

app.template

<div  [ngClass]="'currentTheme' | translate">  // 👈
{{'currentTheme' | translate}}
<p class="base-align">
<hello name="{{ name }}"></hello>
  Start editing to see some magic happen :)
</p>

theme <button (click)="useLanguage('en')">English</button>
<button (click)="useLanguage('ar')">Arabic</button>
</div>

when the languae change the value of currentTheme will chnage and the style will change

stackblitz demo 🚀

like image 136
Muhammed Albarmavi Avatar answered Sep 29 '22 00:09

Muhammed Albarmavi