0

I'm building a system that uses SharePoint lists to present forms to our website visitors, and these visitors can select a language preference for our website, so the form should be presented in that language. When I create my list, I'm specifying columns like "firstname" and "email", which of courses uses these as field labels on the form. I'd like to change "firstname" to be "Prénom" and "Adresse E-mail" when the form is viewed in French.

Is there a way that can I add C# code to a custom form for this list, so that I can locate and change the field labels?

If I had a text file (or something similar) could this be done with JavaScript instead? The preference is C#, as I already have code that gets the translations from another list, but if I have to use a non-C# method, than that might be OK.

Cheers

1
  • $('td.ms-formlabel h3.ms-standardheader:contains("Name")').text('NewName'); Commented Apr 6, 2018 at 17:51

2 Answers 2

1

As I understand by Tag you use your custom form. If you can invoke methods into code behind you can try to use SPUtility.GetLocalizedString Method

string str = "$Resources:onet_TeamWebSite";
string locStr = SPUtility.GetLocalizedString(str, "core", (uint)culture.LCID);

For more info see this post.

If you use you custom list definishion you can try to localize fields by $Resources methods.

<Field ID="{fcc46300-de6e-481e-ac2c-5bc369946712}"
     Name="SubmittedBy"
     DisplayName="$Resources:SubmittedBy"
     Type="User" List="UserInfo" ShowField="NameWithPicture"
     UserSelectionMode="PeopleOnly" UserSelectionScope="0"
     Required="TRUE" />

For more info see this post

5
  • the issue is not where to store the text or how to retrieve it. The issue is how can I add custom C# code to a custom 'new' form for my list. I tried putting code right before each field display name, but the page cannot be rendered as code blocks are not allowed.
    – QMKevin
    Commented Nov 2, 2011 at 12:10
  • How do you create your custom form? Do you use something like this. If yes, look at the second post
    – Alexander
    Commented Nov 2, 2011 at 12:29
  • Interesting. I'd created my list in SharePoint's browser UI, then created the custom form using SharePoint Designer. I'll check out these two articles, and see if they allow me to do what I need. Thank you :)
    – QMKevin
    Commented Nov 2, 2011 at 13:06
  • As you may read below, I ran out of time to find a programmatic way to do translation on my form, so ended up creating multiple forms, one for each language. It's not ideal, but given deadlines, I was able to get this completed on time. Of course, now I have to try and work out how to add validation to the forms... will this project never end! :p
    – QMKevin
    Commented Nov 4, 2011 at 14:48
  • My friend played around field names. It looks like you can use $Resources:onet_TeamWebSite in the field name thru UI. But the behavior is strange some times...
    – Alexander
    Commented Nov 4, 2011 at 15:13
0

For this answer to help you'll need to be able to access the chosen language using javascript. If the language that has been chosen by the user is in the querystring, check out this post.

By adding a Content Editor Web Part to the form and referencing an HTML file that contains the necessary javascript / jquery, the NewForm.aspx labels can be updated. If you're new to working with jQuery in SharePoint, this blog shows how to setup this solution.

You could use this JQuery selector to find the email label and set it to the French version:

$('td.ms-formlabel h3.ms-standardheader nobr:contains("email")').text('Adresse E-mail');

If you haven't used it before, check out Internet Explorer Developer Tools. It will help you when writing other jQuery selectors (try hitting the F12 key when IE is open).

5
  • Thanks for the idea. I'll look into it and get back to you with questions and/or the acceptance of the answer.
    – QMKevin
    Commented Nov 1, 2011 at 19:06
  • I tried this, but couldn't get any text to change. I suspect that either my jquery file isn't being loaded correctly, or that the 'path' to the nobr tag isn't correct in my version. I do believe that this is a valid answer, but I want to see if anyone has any advice on a C# solution first, before I mark it as such. I will come back to mark it as the answer if no-one does in a few days.
    – QMKevin
    Commented Nov 2, 2011 at 12:31
  • Is there a javascript error? Let me know if you have problems with the path (selector). Good luck.
    – Panter
    Commented Nov 2, 2011 at 13:37
  • That's the weird thing: no javascript errors at all - simply nothing happened. Unfortuantely, due to deadlines, I had to go with the less technical (and therefore less cool <g>) method, and created multiple forms, with the text translated in each. It's not ideal, but given the limited number of lists I have to deal with for this project, creating multiple forms was much faster than trying to find the 'cool' way. Thanks for the help though.
    – QMKevin
    Commented Nov 4, 2011 at 14:46
  • No problem. Sometimes, the deadline trumps all. Good luck.
    – Panter
    Commented Nov 4, 2011 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.