diff --git a/build/scripts/Copy-ContextMenuResourcesToCascadiaPackage.ps1 b/build/scripts/Copy-ContextMenuResourcesToCascadiaPackage.ps1 index bbccdaf57d..33af3387b4 100644 --- a/build/scripts/Copy-ContextMenuResourcesToCascadiaPackage.ps1 +++ b/build/scripts/Copy-ContextMenuResourcesToCascadiaPackage.ps1 @@ -41,6 +41,7 @@ ForEach ($pair in $Languages.GetEnumerator()) { $writerSettings = [System.Xml.XmlWriterSettings]::new() $writerSettings.NewLineChars = "`r`n" $writerSettings.Indent = $true + $writerSettings.Encoding = [System.Text.UTF8Encoding]::new($false) # suppress the BOM $writer = [System.Xml.XmlWriter]::Create($ResPath, $writerSettings) $XmlDocument.Save($writer) $writer.Flush() diff --git a/build/scripts/Generate-PseudoLocalizations.ps1 b/build/scripts/Generate-PseudoLocalizations.ps1 index 7f7ffab396..e6fe713bef 100644 --- a/build/scripts/Generate-PseudoLocalizations.ps1 +++ b/build/scripts/Generate-PseudoLocalizations.ps1 @@ -9,6 +9,7 @@ Get-ChildItem -Recurse -Directory -Filter qps-ploc* $writerSettings = [System.Xml.XmlWriterSettings]::new() $writerSettings.NewLineChars = "`r`n" $writerSettings.Indent = $true + $writerSettings.Encoding = [System.Text.UTF8Encoding]::new($false) # suppress the BOM $writer = [System.Xml.XmlWriter]::Create($target, $writerSettings) $ploc.Save($writer) $writer.Flush() diff --git a/tools/ConvertTo-PseudoLocalization.ps1 b/tools/ConvertTo-PseudoLocalization.ps1 index 4eb810174d..c06b0bbd79 100644 --- a/tools/ConvertTo-PseudoLocalization.ps1 +++ b/tools/ConvertTo-PseudoLocalization.ps1 @@ -60,23 +60,21 @@ $content.PreserveWhitespace = $true $content.Load($Path) function GetPseudoLocalization([string]$key, [string]$value, [string]$comment) { - $locked = $null - if ($comment -match '.*\{Locked=?([^}]*)\}.*') { - $locked = $Matches[1] - } - - # Skip {Locked} and {Locked=qps-ploc} entries - if ($locked -and (($locked -eq '') -or $locked.Contains('qps-ploc'))) { - continue - } - $placeholders = @{} + $placeholderChar = 0xE000 + + # Iterate through all {Locked=...} comments and replace locked + # words with placeholders from the Unicode Private Use Area. + foreach ($m in [regex]::Matches($comment, '\{Locked=?([^}]*)\}')) { + $locked = $m.Groups[1].Value + + # Skip {Locked} and {Locked=qps-ploc} entries + if (($locked -eq '') -or $locked.Contains('qps-ploc')) { + return $value + } - if ($locked) { $lockedList = $locked -split ',' - $placeholderChar = 0xE000 - # Replaced all locked words with placeholders from the Unicode Private Use Area foreach ($locked in $lockedList) { if ($locked.StartsWith('"') -and $locked.EndsWith('"')) { $locked = $locked.Substring(1, $locked.Length - 2) @@ -98,7 +96,7 @@ function GetPseudoLocalization([string]$key, [string]$value, [string]$comment) { $hash = [System.BitConverter]::ToInt32($hash) $rng = [System.Random]::new($hash) - $lines = $value.Split("`n") + $lines = $value -split '\r?\n' $lines = $lines | ForEach-Object { # Replace all characters with pseudo-localized characters $newValue = '' @@ -117,11 +115,12 @@ function GetPseudoLocalization([string]$key, [string]$value, [string]$comment) { } # Add 40% padding to the end of the string - $paddingLength = [System.Math]::Round(0.4 * $_.Length) + $paddingLength = [System.Math]::Round(0.4 * $newValue.Length) $padding = ' !!!' * ($paddingLength / 4 + 1) $newValue + $padding.Substring(0, $paddingLength) } - return $lines -join "`n" + $lines = $lines -join "`r`n" + return $lines } if ($path.EndsWith(".resw")) { @@ -133,7 +132,7 @@ if ($path.EndsWith(".resw")) { elseif ($path.EndsWith(".xml")) { foreach ($parent in $content.DocumentElement.SelectNodes('//*[@_locID]')) { $locID = $parent.GetAttribute('_locID') - $comment = $parent.SelectSingleNode('comment()[contains(., "_locComment_text")]')?.'#text' ?? '' + $comment = $parent.SelectSingleNode('comment()[contains(., "_locComment_text")]')?.Value ?? '' foreach ($entry in $parent.SelectNodes('text()')) { $value = $entry.Value