I am developing an application in Angular 7 using ngx-translate for internationalization and bootstrap based AdminLTE 3. I have two css:
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);
}
}
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).
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.
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.
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 .
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 🚀
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With