0

Can someone, please, suggest an approach to translate SharePoint columns programmatically? I tried different approaches including PowerShell, but nothing seems to be working.

Sample PS code that does not seem to translate properly:

# Set the thread culture to French
[System.Threading.Thread]::CurrentThread.CurrentCulture = 'fr-FR'
[System.Threading.Thread]::CurrentThread.CurrentUICulture = 'fr-FR'

# Update the column title
Set-PnPField -List "MultilingualList" -Identity "Contracts" -Values @{Title="FrenchTranslated"}

# Result: instead if French, English name is replaced

Is there no way to do it programmatically?

Update

I was able to deploy column translations using the PnP Provisioning templates and PowerShell. I also had to create .resx files for every language.

In the PnP provisioning template I included this:

  <pnp:Localizations>
    <pnp:Localization LCID="1033" Name="English" ResourceFile="resources.en-US.resx"/>
    <pnp:Localization LCID="1036" Name="French" ResourceFile="resources.fr-FR.resx"/>
  </pnp:Localizations>

And this:

      <pnp:SupportedUILanguages>
        <pnp:SupportedUILanguage LCID="1033" />
        <pnp:SupportedUILanguage LCID="1036" />
      </pnp:SupportedUILanguages>

Then, I referred to the translations using this syntax:

<Field DisplayName="{resource:test}" Name="Contracts" ... />

PowerShell Code to extract and apply the template

# Generate a fresh template
Get-PnPSiteTemplate -Out "Multilingual-site.xml"

# TODO: 
# - Create resources.en-US.resx
# - Create resources.fr-FR.resx
# - Modify the template to replace the hardcoded Display names with translation tockets

# Apply the template to the target site
Invoke-PnPSiteTemplate -Path "Multilingual-site.xml"

<?xml version="1.0"?>
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2022/09/ProvisioningSchema">
  <pnp:Preferences Generator="PnP.Framework, Version=1.11.2.0, Culture=neutral, PublicKeyToken=0d501f89f11b748c" />
  <pnp:Localizations>
    <pnp:Localization LCID="1033" Name="English" ResourceFile="resources.en-US.resx"/>
    <pnp:Localization LCID="1036" Name="French" ResourceFile="resources.fr-FR.resx"/>
  </pnp:Localizations>
  <pnp:Templates ID="CONTAINER-Multilingual">
    <pnp:ProvisioningTemplate ID="MultilingualE" Version="1" BaseSiteTemplate="STS#3" Scope="RootSite">

      <pnp:SupportedUILanguages>
        <pnp:SupportedUILanguage LCID="1033" />
        <pnp:SupportedUILanguage LCID="1036" />
      </pnp:SupportedUILanguages>
      <pnp:Lists>

        <pnp:ListInstance Title="MultilingualList" Description="" DocumentTemplate="" OnQuickLaunch="true" TemplateType="100" Url="Lists/MultilingualList" >
          <pnp:Fields>
            <Field DisplayName="{resource:test}" Name="Contracts"  StaticName="Contracts"  ClientSideComponentId="00000000-0000-0000-0000-000000000000" Format="Dropdown" MaxLength="255" Title="FrContracts" Type="Text" ID="{370d58f7-cb3d-4851-a6b6-aa3d29c54f69}" Version="3"SourceID="{{listid:MultilingualList}}" ColName="nvarchar7" RowOrdinal="0" />
          </pnp:Fields>          
        </pnp:ListInstance>
      </pnp:Lists>

    </pnp:ProvisioningTemplate>
  </pnp:Templates>
</pnp:Provisioning>

Update #2

I also found that I can translate fields using this PnP method:

$field = Get-PnPField -List MultilingualList -Identity Contracts
$field.TitleResource.SetValueForUICulture('fr-FR','French3')
$field.TitleResource.SetValueForUICulture('en-US','English3')
$field.Update()
Invoke-PnPQuery

0

Your Answer

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