Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

When you declare a SPField in CAML, you can add the localization in the code:

<Field
  ID="{57258F13-19B2-4A97-B244-090845B5C4AB}"
  Type="Text"
  Name="Partner"
  DisplayName="$Resources:MyProject,Partner"
  Group="MyProject Columns"
  StaticName="Partner"/>

However, some of the fields have to be created in code (e.g. External Data Columns). For these I also want localization. I found this solution, but I wonder if there's a cleaner way to do this.

share|improve this question

2 Answers 2

up vote 8 down vote accepted

You can add fields programmatically using list.Fields.AddFieldAsXml, providing CAML field definition with resource tokens in it.

Or you can wrap SetValueForUICulture in a nice helper method, and gain a capability to use it for any SPUserResource object. We're using this approach at work, and I would not say, that it is unclear or smth like this :) It's ok, just wrap it.

share|improve this answer
    
I tried with the AddFieldAsXml. The field takes the localization on list creation, however when changing language, it doesn't change (all other fields do). –  Bart Oct 13 '11 at 15:08
    
Yep, a harsh detail. Haven't known about this. But what I do know undoubtedly, is that SetValueForUICulture will work properly with on-fly localization. –  Andrey Markeev Oct 13 '11 at 19:50

Have a look at SPUtility.GetLocalizedString()

share|improve this answer
    
I still got to push the localized string in some property, since I want the localization to change when the user changes his language in the browser, not only on provisioning. –  Bart Oct 13 '11 at 7:23
    
Gotcha. Go for omlin's answer. –  James Love Oct 13 '11 at 7:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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