SOLVED

How to provision web part titles in multiple languages using Office Dev PnP Provisioning?

Bronze Contributor

Using the Office Dev PnP provisioning engine I've managed to deploy a site in multiple languages. We managed to localize just a few of the web part titles shown on the welcome page of our site:

  • The web part titles of our announcements, tasks and documents lists/libraries are localized.
  • The web part titles of a calendar, the contact details and site users web part are not shown in a localized language yet.

Below you'll see how we define the web parts and would expect these to be localized, a few support it, others simply fall back to English.

How can we realize localization for all the web part titles?

Or is localization only supported for v3 Web Parts (which I expect based on our test results)? If so, is it possible to "convert" the v2 web part definition to a v3 definition? Do you have an example for that?

 

Working for the documents library (displays in English or Dutch language based on the user)

<pnp:WebPart Title="Documents" Row="1" Column="1">
<pnp:Contents>
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<importErrorMessage>Cannot import the Documents Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="ShowWithSampleData" type="bool">False</property>
<property name="ListName" type="string">{{listid:Documents}}</property>
<property name="Title" type="string" />

 

 

Not working for the Site Users web part (always displays the English language)

<pnp:WebPart Title="Site Users" Row="1" Column="2">
<pnp:Contents>
<WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">
<Title>{resource:SiteUsersWebPartTitle}</Title>
<Assembly>Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.MembersWebPart</TypeName>

 Site Users web part showing web part title in incorrect language.png

 

Not working for the Contact Details (always displays the English language)

<pnp:WebPart Title="Contact Details" Row="1" Column="2"><pnp:Contents><WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">
<Title>{resource:ContactDetailsWebPartTitle}</Title>
<Assembly>Microsoft.SharePoint.Portal, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.Portal.WebControls.ContactFieldControl</TypeName>

 

 

Not working for the Calendar web part (always displays the English language)

<pnp:WebPart Title="Calendar" Row="1" Column="2">
<pnp:Contents>
<WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">
<Title>{resource:CalendarListTitle}</Title>
<Assembly>Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName>

 

5 Replies

Hi Harold,

 

I have currently a very similar problem: Some webpart titles "accept" the ressource-string others just always display their english title.

I'm using SharePpoint 2016 with PnP Partner Pack to provision the webparts.

For me the CSWP is translated correctly.

Not translated: Script-Editor-Webpart and Project Summary Webpart.

 

Did you ever find out what the problem was? Currently I guess that some webparts render server-side and some render client-side. Depending on the render mode it fails or it works - but till now I couldn't test it.

Hi,

 

I just figured out the behavior in my case: It is not related to the type of webpart but to the order the webparts are provisioned. Only the last Webpart in my PnP-Template-XML will get a translated title.

 

More testing is in progress.

best response confirmed by Harold van de Kamp (Bronze Contributor)
Solution

Hi Harold,

 

I did a big multi langual project and managed to get it working for all my webparts. In my experience your need to put the language tokens in bot the pnp:webpart title attribute as in the webpart xml title property. Both needs to be the same. All localization files needs to be refered to in your template and als the supported languages needs to be set. This way it works in my opinion.

 

One thing to note here: The webparts only show in the language of the site and does not follow the users language. So if a German user visits a French site, the webpart titles are shown in German. Not in French. I would have expected that the users language would be leading here, but haven't seen it work like that.

Thanks for the reactions. I wasn't able to find the solution in the past. Your contributions are helpful, I will try it out sometime when I need it for a new multilingual project.

Hi,

 

I have some new information on this topic.

For me (SP2016 on Prem) the webparts do change their webpart-title based on the users language, if the additional language is activated in the site settings.

I also found out, why some webparts had a correct tranlation and other didn't:

The PnP Code for the translation goes thorugh all open webparts on the page. To find out if a webpart is open, a comparison is made between the webpart-order in XML and "in reality" (this must be the XML retrieved by some get-webpart-from-page method).

https://github.com/SharePoint/PnP-Sites-Core/blob/master/Core/OfficeDevPnP.Core/Framework/Provisioni...

#if !SP2016
 var partOnPage = allParts.FirstOrDefault(w => w.ZoneId == webPart.Zone && w.WebPart.ZoneIndex == webPart.Order);
#else  
 var partOnPage = allParts.FirstOrDefault(w => w.WebPart.ZoneIndex == webPart.Order);
 #endif 

 

If you use a wikipage the order will always be "0" - so the translation is overwritten several times. Thats why it didn't work in my case.

With webpart pages there is another problem with SP2016: As only the ZoneIndex is compared and not the webpartZone your webpart-order has to be unique across all zones. This is impossible for two or more zones, as the first webpart added to an empty zone always gets a "0" as order. As a result the two webparts on top of the webpart zone will have wrong translations.

I'll make a bug at github in the next days to see if there is a reason for this SP2016-Exception.

1 best response

Accepted Solutions
best response confirmed by Harold van de Kamp (Bronze Contributor)
Solution

Hi Harold,

 

I did a big multi langual project and managed to get it working for all my webparts. In my experience your need to put the language tokens in bot the pnp:webpart title attribute as in the webpart xml title property. Both needs to be the same. All localization files needs to be refered to in your template and als the supported languages needs to be set. This way it works in my opinion.

 

One thing to note here: The webparts only show in the language of the site and does not follow the users language. So if a German user visits a French site, the webpart titles are shown in German. Not in French. I would have expected that the users language would be leading here, but haven't seen it work like that.

View solution in original post