2

Here i have VF Page code......

<apex:form enctype="multipart/form-data">
  <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file" />
  <apex:commandButton action="{!upload}" value={!$Label.Upload}"/>                                          
</apex:form>

when i am logging as a customer portal as any other language in that "browse" button and "No file selected" in not translated,it is remain as it is in English language....here is the following snapshot of issues...

enter image description here

so here what can i do to translate this button title and No file selected as per language...

please help me to translate rounded things...

4 Answers 4

1

You can overlay a textbox over the browse button and then associate a click event with this textbox so that whenever the user clicks on the textbox, the click() of the "Browse" button gets triggered.

Here are the steps that you need to follow:

  • Create a custom button :

    <input id="CustomChooseFileButton" type="text" size="23" name="CustomChooseFileButton" value="选择文件" class="OverlayButton btn" />

  • Please note that the class of this button "btn" give it the standard salesforce button behaviour (on hover pointer change, on click blue border etc)

  • Note that there is an additional class "Overlay" associated with the input.

Basically you need to put the input text and apex:inputfile in a div container (start tag below is --> div class = "ChooseFileContainer")

<code>
    <div>
        <apex:inputFile fileName="CustomObjectList" value="{!filebody}" fileSize="{!filesize}" style="padding-left:65px" />
        <input id="CustomChooseFileButton"  type="text"  size="23" name="CustomChooseFileButton" value="Upload Object Names File" class="OverlayButton btn" />
    </div> 
</code>

Then you need to apply the styling which would overlay the text box over the standard button. Please note that you may have to adjust these parameters for your application:

<style>

/* Styling for the standard button */

    .ChooseFileContainer {
            position:relative;
            display:inline;
          }

/*Styling for the custom button that would overlay on top of the standard choose file button */

    .OverlayButton {
            position:absolute;
            left:5px;
            right:0;
        }       
</style>

Finally, you write the javascript that would trigger the click() on the standard button when you textbox is clicked.

 $(function(){

                    // script that triggers the click of the standard
                    // choose file button 
                    $('#CustomChooseFileButton').click( 
                    function(e) {
                                    $('input[type="file"]').click(); 

                                });

                   // script to hide the blinking cursor 
                    $('input[type="text"]').mousedown(
                    function(e) { 
                                    e.preventDefault();
                                    $(this).blur();
                                    return false;
                    });         

    });

Note that we also added an event that would get rid of the blinking cursor on the textbox.

Let me know if you face any issues in implementing this solution.

1

I was facing the same issue and realized there is no way to change/translate "Choose File" label unless you change the browser language itself however in Salesforce mostly we prefer to use Labels and picklist translations to make Salesforce UI user friendly so that unexpected translation doesn't spoils the user experience.

Here is the way we can translate, create a div (or any other html component), override the div on top of input file and bind both input file and div in a label. Giving slds classes will make the div look alike button only.

Simply copy the below sample code in HTML/VisualForce Page/Lightning component and translate the label on the div:

<div>
<label  class="slds-button slds-button_neutral" for="fileInput">{!$Label.CLSPR20SEACANChooseFile}</label>                                       
<input type="file" style="visibility:hidden;" id="fileInput" multiple="true" onchange="fileUploaded(this)" />
</div>

enter image description here

0

The button and the text is rendered by the browser. So you would need to change the language of the browser. You can check out the way to change the language in IE by following the steps in here. In Chrome you can go to the settings->Language and input settings and add the language.

2
  • There is no other way in salesforce to change the language......
    – Vivek113
    Commented Mar 13, 2014 at 5:51
  • I think it will be a little tricky You probably need to hide the input:file button and display another button clicking on which you can trigger (using the .trigger() in jQuery) the click on the input:file button. Check it out here: stackoverflow.com/questions/1944267/…
    – Sam
    Commented Mar 13, 2014 at 6:19
0

You cannot hide the no file selected since it is a default text for the button, one way to do this is by hiding the text using CSS

    <apex:form enctype="multipart/form-data">
         <apex:outputText > Choose the fil(选择文件)</apex:outputText>
  <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file" style="color:transparent;"/>
      <apex:commandButton action="{!upload}" value={!$Label.Upload}"/>                                          
    </apex:form>

enter image description here

3
  • thanx for your prompt response.....for that suppose here i am logged in customer portal as chinese language...so this all things displayed in chinese language.....suppose i am logged in as ittalian language then all the things displayed as ittalian language.....that's here i want.....
    – Vivek113
    Commented Mar 13, 2014 at 5:55
  • yeah that going to be a bit tricky, from what I know you cannot control the text language ( I will be happy if proven wrong) so using a controller logic you can load text for the output text as per the user locale at the worst
    – Rao
    Commented Mar 13, 2014 at 5:57
  • thanks for replay...ok for that if "no file selected" is not translated...it's ok....but is there any way can i translate Button text "choose file" as per language norms...
    – Vivek113
    Commented Mar 13, 2014 at 6:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .