Obtaining language of the current user
Using different languages on your page is crutial when you have a multilingual company or your partners are located on the other side of the globe. I’ve seen on various forums that some people are struggling with finding an efficient and easy way of getting the language of the current user in Visualforce page, so in today’s quick post I’m going to show you a simple way of doing just that.
So let’s start from the beginning. Each language is given its own special two letter country code, just like in this example:
- French: fr
- German: de
- Italian: it
- Japanese: ja
So the key to figuring out what language the user is using, is finding out these two letter country code. To do that in the quickest in most efficient way just use this line of code in your work:
if(UserInfo.getLanguage() == 'pl'){
//Do something
}
It’s just as simple as that. Sorry that today’s post is rather short. Next time we are going to tackle more complex problems. Stay tuned!