Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTL support #374

Open
djabif opened this issue Dec 22, 2016 · 8 comments
Open

RTL support #374

djabif opened this issue Dec 22, 2016 · 8 comments

Comments

@djabif
Copy link

djabif commented Dec 22, 2016

Are you planning to support RTL so we can determine if the text direction is RTL or LTR depending on the selected language?
Thanks.

@ocombe
Copy link
Member

ocombe commented Dec 22, 2016

Well I was just talking about it with @ceolter.
I've never worked on RTL support before, so I have no idea what it implies, do you have some experience on the question ?
I don't mind adding it, it would be a great feature to add.

@djabif
Copy link
Author

djabif commented Dec 22, 2016

It implies that texts should go from right to left and aligned to the right 😉
There is a html attribute dir that allows the values "rtl" or "ltr" and aligns its content accordingly.

I'm working on an Ionic2 app and currently we found a workaround by listening to the onLangChange event from the TranslateService in the app.component.ts and inside that we check if the default Lang is Arabic and then set an attribute to "rtl":

//this is to determine the text direction depending on the selected language
     this.translate.onLangChange.subscribe((event: LangChangeEvent) =>
     {
       if(event.lang == 'ar')
       {
         this.textDir = 'rtl';
       }
       else
       {
         this.textDir = 'ltr';
       }
     });

Then in the container of the app (app.html file) we set the dir="{{textDir}}":
<ion-nav [root]="rootPage" dir="{{textDir}}"></ion-nav>

It works fine, but it would be great if this awesome library could support this 😃

Hope I have been of some help.
Please let me know if you need more details.

@emoralesb05
Copy link

Just my 2 cents but to me that seems like a proper solution since you can have an array with the rlt languages

let rtlLangs = ['ar','morelangs'];

this.translate.onLangChange.subscribe((event: LangChangeEvent) => { 
  this.dir = rtlLangs.indexOf(event.lang) > -1 ? 'rtl' : 'lrt';
});

This way ngx-translate stays agnostic of what dir is but you can still use leverage it.

@shangab
Copy link

shangab commented Jan 10, 2019

@djabif Thanks for the tips: I modified your solution to cope with Angular 6+ web applications:
Put the below code in the constructor of app.component.ts:

this.translate.onLangChange.subscribe((event) => {
this.lang=event.lang;
if (event.lang == 'ar') {
this.ltrrtl = 'rtl';
}
else {
this.ltrrtl = 'ltr';
}
document.getElementsByTagName("html")[0].setAttribute('lang', this.lang);
document.getElementsByTagName("body")[0].setAttribute('dir', this.ltrrtl);
});

@MedHassona
Copy link

thank you very much @djabif this really hilped me and made the way much shorter for this "Text direction stuff", god bless you always.

@orhanbhr
Copy link

Thanks @djabif Good works.

@shalini-github
Copy link

shalini-github commented Apr 10, 2019

@djabif hi how to use these lines ngx translate latest version. it gives Cannot find name LangChangeEvent error in editor.

@viveksai26
Copy link

<div [dir]="'direction' | translate">
Code to be inverted
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants