Lookup Field localization not working when using ContentTypeBinding

Whilst working with lookup fields, I noticed something strange when you separated the Fields and ContentType from your list and you try to use localization. Separating your content type and fields from your list basically means that you no longer work with a custom list definition, but you use ContentTypeBinding on a list instance to create your list.

Here’s an example on how the project is set up:

lookupFieldLocalizationProject

The red arrows point to the lookup list where I use the ContentType “LookUpContentType”, where a lookup field is referenced. This lookup field resides in the “Fields” element:

“Fields” Elements.xml

<?<span class="hiddenSpellError">xml version="1.0" encoding="utf-8"?>
xmlns="http://schemas.microsoft.com/sharepoint/">
  <Field Name="LookUpFieldInElements"
  Required="TRUE"
  ID="{32A4FE06-2745-40D0-B92C-76A58B16C7B0}"
  Type="Lookup"
  Mult="FALSE"
  Overwrite="TRUE"
  List="Lists/Source"
  ShowField="Title"
DisplayName="$Resources:lookupfield,LookUp;"
  StaticName="LookUpFieldInElements"
  />
</Elements>

“LookUpContentType” Elements.xml

<?xml version="1.0" encoding="utf-8"?>
xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Parent <span class="hiddenSpellError" pre="Parent ">ContentType</span>: Item (0x01) -->
<ContentType ID="0x01002846E06F521348B79F631D4D9E6A07CC" Name="LookUpContentType" Group="Custom Content Types" Description="My Content Type" Inherits="TRUE" Version="0">
    <FieldRefs>
<FieldRef ID="{32A4FE06-2745-40D0-B92C-76A58B16C7B0}" Name="LookUpFieldInElements" Required="TRUE" />
    </FieldRefs>
ContentType>
</Elements>

“LookUpListCTInstance” Elements.xml

<?xml version="1.0" encoding="utf-8"?>
xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance
Title="LookUpListCT"
    OnQuickLaunch="TRUE"
    TemplateType="100"
    Url="Lists/LookUpListCT"
Description="My List Instance with ContentTypeBinding"
    FeatureId="00bfea71-de22-43b2-a848-c05709900100">
  </ListInstance>
<ContentTypeBinding ContentTypeId="0x01002846E06F521348B79F631D4D9E6A07CC" ListUrl="Lists/LookupListCT" />
</Elements>

The blue arrows point to a regular list definition which has a list instance included.

The Schema.xml of the “LookupList” list definition

<ContentTypes>
      <ContentType ID="0x0100468fd589c1da4592929a6768ac144020" Name="ListFieldsContentType">
        <FieldRefs>
<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" />
<FieldRef ID="{a51cabb2-7594-41db-8523-ea5de71e6202}" Name="LookUp" />
        </FieldRefs>
      </ContentType>
    </ContentTypes>
    <Fields>
      <Field
        Name="LookUp"
        ID="{a51cabb2-7594-41db-8523-ea5de71e6202}"
DisplayName="$Resources:lookupfield,LookUp;"
        Type="Lookup"
        List="Lists/Source"
        ShowField="Title" />

When you take a look at the DisplayNames of both the LookupFields residing in Schema.xml and “Fields” Elements.xml, you’ll see that the value holds “$Resources:lookupfield,LookUp;”. So we’re trying to localize the LookupField’s column name.

I’ve added the following resource files where I can add my translations:

lookupFieldLocalizationResourceFiles

lookupfield.resx

<data name="LookUp" xml:space="preserve">
  <value>LookUp</value>
</data>

lookupfield.en-US.resx

<data name="LookUp" xml:space="preserve">
  <value>[ENG] LookUp</value>
</data>

lookupfield.nl-NL.resx

<data name="LookUp" xml:space="preserve">
  <value>[NL] LookUp</value>
</data>

lookupfield.fr-FR.resx

<data name="LookUp" xml:space="preserve">
  <value>[FR] LookUp</value>
</data>

Looks great! Let’s check out the result on our SharePoint lists:

lookupFieldLocalizationDutchLocalization

lookupFieldLocalizationDutchLocalizationCT

Apparently there’s a bug when separating your LookupField from your Schema.xml where it will only use the English localization. So whenever you want to use LookupFields in custom lists, use the list definition way!

Advertisements

4 thoughts on “Lookup Field localization not working when using ContentTypeBinding

  1. It’s really a nice and useful piece of info. I am glad that you just shared this useful info with us. Please keep us informed like this. Thank you for sharing.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s