Item Languages
The section on working with items provided a variety of examples in retrieving items based on their language. In this section will show how to manage items and their languages.

Add Language Version

Example: The following example queries all of the content items and adds a new language version of "en-ca", while overwriting any that exist.
1
Get-ChildItem "master:\content" -Recurse |
2
Add-ItemLanguage -Language "en-us" -TargetLanguage "en-ca" -IfExist OverwriteLatest
Copied!
Example: The following example adds a language version from English to US and Polish while leaving the Title field blank. If a version already exists nothing happens.
1
$languageParameters = @{
2
Path = "master:\content\home"
3
Language = "en"
4
TargetLanguage = @("pl-pl","en-us")
5
IfExist = "Skip"
6
IgnoredFields = @("Title")
7
}
8
Add-ItemLanguage @languageParameters
Copied!
Example: The following example adds a language version from English to Polish of Template Name Sample Item. If the version exists a new version is created for that language. Finally the results are displayed as a table showing only the Name, Language, and Version.
1
Get-ChildItem "master:\content\home" -Language "en" -Recurse |
2
Where-Object { $_.TemplateName -eq "Sample Item" } |
3
Add-ItemLanguage -TargetLanguage "pl-pl" -IfExist Append |
4
Format-Table Name, Language, Version -AutoSize
Copied!
Example: The following example adds a language version in Polish to the Home item and all its children. If the version exists nothing happens. No fields were harmed in the making of this version.
1
Add-ItemLanguage -Path "master:\content\home" -TargetLanguage "pl-pl" -IfExist Skip -DoNotCopyFields -Recurse
Copied!

Remove Language Version

Example: The following example queries all of the content items and removes the language version of "fr-CA".
1
Get-ChildItem "master:\content" -Recurse |
2
Remove-ItemLanguage -Language "fr-CA"
Copied!

New Item with Forced Language Version

Example: The following example creates a new item with language versions only matching the specified languages; all other language version are removed.
1
$itemPath = "master:\content\home\sample item\Sample Item 3"
2
New-Item -Path $itemPath -ItemType "Sample/Sample Item" -Language "en-CA"
3
4
Name Children Language Version Id TemplateName
5
---- -------- -------- ------- -- ------------
6
Sample Item 3 False en-CA 1 {C9517583-3AF9-4AFB-B247-BB0A09F55D94} Sample Item
Copied!

Parameters and Configuration

Supported parameters:
  • -Recurse Translates item and its children
  • -IfExist Accepts one of 3 pretty self explanatory actions: Skip, Append or OverwriteLatest
  • -TargetLanguage accepts a list of languages that should be created
  • -DoNotCopyFields creates a new version but does not copy field values from original language
  • -IgnoredFields list of fields that should not be copied over from original item this can contain e.g. __Security if you don't want the new version to have the same restrictions as the original version.
On top of the ignored fields in the -IgnoredFields the following fields are ignored as configured within the Spe.config file:
1
<configuration xmlns:patch="https://www.sitecore.net/xmlconfig/">
2
<sitecore>
3
<powershell>
4
<translation>
5
<ignoredFields>
6
<field>__Archive date</field>
7
<field>__Archive Version date</field>
8
<field>__Lock</field>
9
<field>__Owner</field>
10
<field>__Page Level Test Set Definition</field>
11
<field>__Reminder date</field>
12
<field>__Reminder recipients</field>
13
<field>__Reminder text</field>
14
<!--field>__Security</field-->
15
</ignoredFields>
16
</translation>
17
</sitecore>
18
</configuration>
Copied!

References

Last modified 2yr ago