Translate SharePoint form field label and description by a dropdown select

Change log
August 08. 2013
Moved the code for the file “TranslateFormFields.js” to spjsfiles.com due to errors in the preview.

I got this request from Mary Larson for a solution to translating a SharePoint 2010 form in 20+ languages by the selection of a desired language in a dropdown select.

I guess installing all these languages as language packs and using the MUI interface to translate the form is not an option.

I created this solution for translating the form label and description (description not supported in DispForm) – with cookie support for remembering the selected language.
IMG

Get the code for the file TranslateFormFields.js here.

You can either include this code in the HTML Form Web part or you can put it in a folder as a separate file and refer it using a script tag.

When the above code is referred, call the translation script like this from a HTML form Web part placed below the form web part:

<script type="text/javascript" src="/Scripts/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="/Scripts/TranslateFormFields.js"></script>
<script type="text/javascript">

/*
	The translation setup:
	dropdownLabel: "text" is the displayed text, "style" is the CSS style you want to apply to the label.
	dropdownDefaultVal: This is the initial value you want to display in the dropdown.
	lcArr: This is the array of languages as they should appear in the dropdown select.
	translations: This is an object literal in this format:	
		FieldInternalName_of_field : [
						{
							"label":"Tittel",
							"description":"This is the norwegian title"
						},
						{
							"label":"Titel",
							"description":"This is the swedish title"
						}
					]
*/

spjs.translateForm.init(
	{
		"dropdownLabel":
			{
				"text":"Translate",
				"style":"font-weight:bold"
			},
		"dropdownDefaultVal":
			"English",
		"lcArr":
			[
				"Norwegian",
				"Swedish"
			],	
		"translations":
			{
				"Title":
					[
						{ // Norwegian
							"label":"Tittel",
							"description":"This is the norwegian title"
						},
						{ // Swedish
							"label":"Titel",
							"description":"This is the swedish title"
						}
					],
				"Status":
					[
						{ // Norwegian
							"label":"Prosjektstatus",
							"description":"This is the norwegian status"
						},
						{ // Swedish
							"label":"Projektstatus",
							"description":"This is the swedish status"
						}
					]
			}
	}
);
</script>

This code is tested in a out of the box SharePoint 2010 only, but it most likely will work in out of the box forms in SP 2007 and 2013 as well.

Please let me know if you have trouble getting it to work, or you have any success stories.

If you like the solution, please click the beer mug in the top right margin of this page to buy me some beer!

Alexander

10 thoughts on “Translate SharePoint form field label and description by a dropdown select”

      1. Hi Alexander,

        I’m currently using SP 2007 and I appreciate that it would support that platform (cause we have a lot of sites in this version), but in two months I’ll be migrating to 2013 so that would help me if this solution was supported in 2013.

        Thanks for this blog It has been a great help…. 🙂

      2. Sorry for the delay, Have you tested it in SP2013?

        If it does not work, I guess delaying the function call will do the trick (as the form in SP2013 is drawn asynchronously). Try it like this:

        setTimeout(function(){
          spjs.translateForm.init({...});
        }),100);

        Alexander

  1. Hi, Alexander. Wondering if you this was made compatible with your current version of DFFS? I’d like to use tool to change field labels depending on a dropdown value.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.