Print this page

Language issues in error messages with multi language Site

Knowledge Article Number 000176834
Description Scenario -
User is building a site that must support English and some other language, say French.
User is using the "language" tag on the login Visualforce page to switch between English and French for Guest User.
User sets this language tag to "fr".

When user enters an invalid username and password in the login page, following error message appears in the page in English -
"Your login attempt has failed. Make sure the username and password are correct."
The rest of the page is translated to French successfully.
If the Guest User switches the site language to French and then an exception occurs, the user is redirected to an "Authorization Required page" instead of the exception page, and this page is in English instead of French.

Issue -
Is there a way to redirect the user to a general exception page in French
to redirect the user to the standard Authorization Required page in French?
Resolution When the guest user changes his language and an exception occurs, pass the language parameter in the exception page redirect in the catch block if you need to display the error message in language other than English.

In general, you can use custom labels, translation workbench and the laguage attribute to control the displayed languages in your error messages.
Link -

Here is an example of registerUser use case -

However, for the site.login() method, you will need to adjust your VF markup/apex code to not use apex:messages as site.login() returned errors does not currently support language localization.

// CODE SNIPPET ... using a custom label called LoginFailed -
The label has been created and translated to French.
The particular page that loads this has the language parameter set to French.
public Boolean loginError{get;set;}
global PageReference login() {
	PageReference result = null;
	result = Site.login(username, password, startUrl);
	if (result == null){
		loginError = True;
		loginError = false;
	return result;

<apex:outputPanel id="theError" rendered="{!loginError}">
	{!$}: {!$Label.LoginFailed}


The out of the box labels available can be found for the VF global variable: $Label.Site
At this time, we do not have any specific standard label for "Login failed".

Workaround -
Add error messages to ApexPages

site.login() method does not return anything other than null if there is an issue.
You can go through the ApexPages.messages() after the login call if the result is null, and then build as many custom error messages as you need.
You could use customSettings to store the string/error messages you wish to compare against items in ApexPages.getMessages().
That way, if anything does change in the returned error text, you can update the comparison string in the custom settings.
Note: There is no documentation of all the possible error messages from site.login.
The 3 primary situations to address for possible login errors from site.login() will be -
1. Unsuccessful login with a bad username or password - Use workaround suggested.
2. Blank username - handle before site.login().
3. Blank password - handle before site.login().

promote demote