Monday 14 August 2017

Language Translation in VisualForce Page | Translation Workbench

Salesforce offer functionality through that we'll be able to create single VF page which can be translated in several languages based on language/locale preference of current logged in user. We just need to upload the translation of all custom fields that you're going to use in VF page . To render the VF page in particular language, use Language attribute on <apex:page> tag.

Please follow below step to achieve the same. 
Step 1) Enable Translation Workbench and all Translation   Please follow below post to enable Translation Workbench
URL :-Translation Workbench - Salesforce ( Multilingual picklist values )

Step 2) You Can use the "Language" attribute of the VF page.

Step 3) Try to use Salesforce standard way to is to use apex:inputField tag with assigned sobject field. In this case a field will be generated automatically with respect to the current user language. 
Apex Class:-

public with sharing class TranslationWorkbenchController {
    public string selectedLang{get;set;}
    public List<selectoption> listOfLang {get;set;}
    public TranslationWorkbenchController(ApexPages.StandardController controller) {

        listOfLang = new List<selectOption>();
        listOfLang.add(new selectOption('en','English'));
        listOfLang.add(new selectOption('it','Italian'));
        listOfLang.add(new selectOption('es','Spanish'));
        listOfLang.add(new selectOption('de','German'));
        listOfLang.add(new selectOption('fr','French'));

VF Page :-

<apex:page standardcontroller="Account" extensions="TranslationWorkbenchController" language="{!selectedLang}" >
<apex:form >

        <apex:selectList value="{!selectedLang}" size="1">
            <apex:selectoptions value="{!listOfLang}"/>
            <apex:actionsupport event="onchange"/>
        <apex:pageblock >
            <apex:pageblocksection >
                <apex:inputfield value="{!Account.Name}"/>
                <apex:inputfield value="{!Account.Type}"/>
                <apex:inputfield value="{!Account.Industry}"/>
                <apex:inputfield value="{!Account.BillingCountry}"/>

Screen shot :-

English :-


Amit Chaudhary

1 comment:

  1. Hi Amit,
    it is very helpful.
    I am facing issue with custom fields, I am unable to translate custom fields on VF page but I am tranlating standard fields exactly as you shown above.
    it is not showing custom fields label when I am doing it for arabic.

    Thanks in advance