Print this page

Language issues in error messages with multi language Force.com Site

Knowledge Article Number 000176834
Description Scenario -
User is building a force.com 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
OR 
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 - http://wiki.developerforce.com/page/An_Introduction_to_Force.com_Sites#Multi_Language_Support

Here is an example of registerUser use case -
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_sites.htm

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.
///////////
Apex:
public Boolean loginError{get;set;}
global PageReference login() {
	PageReference result = null;
	result = Site.login(username, password, startUrl);
	if (result == null){
		loginError = True;
	}else{
		loginError = false;
	}
	return result;
}


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


///////////

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".
http://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global.htm

Workaround -
Add error messages to ApexPages
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_apexpages.htm

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