When a user's language is set to an RTL language (like Hebrew for example) - we see the dir=rtl set on the tag for a VF page. In this situation we'd also like to load a different CSS file specifically for rtl styles. Is there a way to use the $User variable or some other variable available in the Visual Force page to be able to detect if the user is using an rtl language?

| improve this question | | | | |
  • I don't think you can do this in VF but you can try system.debug(userinfo.getlanguage()+'---------'+userinfo.getlocale()); and based on the value you can set parameter. – Tushar Sharma Oct 10 '16 at 16:33

In this article it is said that:

The orientation of the text is determined by the user language. If you are salesforce in a left-to-right language (i.e English), all text will be left-to-right oriented. If you change your user language to a right-to-left language (i.e Hebrew), that text will also follow this orientation.

Based on this we can conclude that we could create a function in our controller that will check the language and determine if it is right-to-left. Something like this:

public class MyController {

    public Boolean isLanguageRTL {get; set;}

    public MyController(){
         this.isLanguageRTL = checkIsLanguageRTL(UserInfo.getLanguage());

    public Boolean checkIsLanguageRTL(String language){
        if(language == 'iw' ||
          language == 'ar' ||
          language == 'ur'){
            return true;

        return false;

You can then use the isLanguageRTL variable to load the required CSS in your Visualforce page.

| improve this answer | | | | |
  • 1
    Works like a dream - thanks @smukov. For reference here's how I used it in my page to change the CSS: <apex:stylesheet value="{!IF(isLanguageRTL, URLFOR($Resource.slds, '/assets/styles/salesforce-lightning-design-system-vf.rtl.min.css'), URLFOR($Resource.slds, '/assets/styles/salesforce-lightning-design-system-vf.min.css'))}"/> – Matt Goldspink Oct 10 '16 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.