mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-19 18:11:39 -05:00
Fix more PDP ploc related issues (#17530)
This fixes some more issues not properly covered by #17526: * Fixed `_locComment_text` comments being effectively ignored. * Fixed line splitting of comments (CRLF vs LF). * Fixed BOM suppression. * Fixed support for having multiple `{Locked=...}` comments.
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 = @{}
|
||||
|
||||
if ($locked) {
|
||||
$lockedList = $locked -split ','
|
||||
$placeholderChar = 0xE000
|
||||
|
||||
# Replaced all locked words with placeholders from the Unicode Private Use Area
|
||||
# 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
|
||||
}
|
||||
|
||||
$lockedList = $locked -split ','
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user