Last active
January 1, 2019 19:09
-
-
Save AlexKasaku/596f336e421d0fc44227fe3088cf6988 to your computer and use it in GitHub Desktop.
Remove a language from an SXA site. Based on the "Add Site Language" set of scripts that comes with SXA.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Functions Site Language/Remove Site Language | |
Import-Function Validate-PowerShell | |
Test-PowerShell | |
Try | |
{ | |
$ctx = Get-Item . | |
Import-Function Remove-SiteLanguage | |
Import-Function Show-RemoveSiteLanguageDialog | |
$result = Show-RemoveSiteLanguageDialog $ctx | |
Remove-SiteLanguage $ctx $result.Language | Out-Null | |
} | |
Catch | |
{ | |
$ErrorRecord=$Error[0] | |
Write-Log -Log Error $ErrorRecord | |
Show-Alert "Something went wrong. See SPE logs for more details." | |
Close-Window | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Functions Site Language/Remove-SiteLanguage | |
function Remove-SiteLanguage { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory = $true, Position = 0)] | |
[Item]$Site, | |
[Parameter(Mandatory = $true, Position = 1)] | |
[string]$Language | |
) | |
begin { | |
Write-Verbose "Cmdlet Remove-SiteLanguage - Begin" | |
} | |
process { | |
Write-Verbose "Cmdlet Remove-SiteLanguage - Process" | |
$Site = Get-Item -Path $Site.Paths.Path -Language $Language | |
Get-ChildItem -Path $Site.Paths.Path -Recurse | ForEach-Object { | |
Remove-ItemLanguage -Item $_ -Language $Language | |
} | |
} | |
end { | |
Write-Verbose "Cmdlet Remove-SiteLanguage - End" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Content Editor/Context Menu/Show-RemoveSiteLanguageDialog | |
# Use a Show Rule to only show for the Site Item template {6669DC16-F106-44B5-96BE-7A31AE82B5B5} | |
function Show-RemoveSiteLanguageDialog { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory = $true, Position = 0)] | |
[Item]$Site | |
) | |
begin { | |
Write-Verbose "Cmdlet Show-RemoveSiteLanguageDialog - Begin" | |
} | |
process { | |
Write-Verbose "Cmdlet Show-RemoveSiteLanguageDialog - Process" | |
$languages = [ordered]@{} | |
$Site.Languages | ? { $Site.Versions.GetLatestVersion($_).Versions.Count -gt 0 } | ForEach-Object { | |
$displayName = [Sitecore.Globalization.Language]::GetDisplayName($_.CultureInfo) | |
$languages[$displayName] = $_.Name | |
} | Out-Null | |
$result = Read-Variable -Parameters ` | |
@{ Name = "language"; Options = $languages; Value = "en"; Title = "Existing lanuage"; } ` | |
-Description "This script removes a language from an existing site" ` | |
-Title "Remove language from the site" -Width 500 -Height 600 ` | |
-OkButtonName $([Sitecore.Globalization.Translate]::Text("Ok")) -CancelButtonName $([Sitecore.Globalization.Translate]::Text("Cancel")) ` | |
if ($result -ne "ok") { | |
Close-Window | |
Exit | |
} | |
@{ | |
Language = $language | |
} | |
} | |
end { | |
Write-Verbose "Cmdlet Show-RemoveSiteLanguageDialog - End" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Brilliant!