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 = [System.Xml.XmlWriterSettings]::new()
|
||||||
$writerSettings.NewLineChars = "`r`n"
|
$writerSettings.NewLineChars = "`r`n"
|
||||||
$writerSettings.Indent = $true
|
$writerSettings.Indent = $true
|
||||||
|
$writerSettings.Encoding = [System.Text.UTF8Encoding]::new($false) # suppress the BOM
|
||||||
$writer = [System.Xml.XmlWriter]::Create($ResPath, $writerSettings)
|
$writer = [System.Xml.XmlWriter]::Create($ResPath, $writerSettings)
|
||||||
$XmlDocument.Save($writer)
|
$XmlDocument.Save($writer)
|
||||||
$writer.Flush()
|
$writer.Flush()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ Get-ChildItem -Recurse -Directory -Filter qps-ploc*
|
|||||||
$writerSettings = [System.Xml.XmlWriterSettings]::new()
|
$writerSettings = [System.Xml.XmlWriterSettings]::new()
|
||||||
$writerSettings.NewLineChars = "`r`n"
|
$writerSettings.NewLineChars = "`r`n"
|
||||||
$writerSettings.Indent = $true
|
$writerSettings.Indent = $true
|
||||||
|
$writerSettings.Encoding = [System.Text.UTF8Encoding]::new($false) # suppress the BOM
|
||||||
$writer = [System.Xml.XmlWriter]::Create($target, $writerSettings)
|
$writer = [System.Xml.XmlWriter]::Create($target, $writerSettings)
|
||||||
$ploc.Save($writer)
|
$ploc.Save($writer)
|
||||||
$writer.Flush()
|
$writer.Flush()
|
||||||
|
|||||||
@@ -60,23 +60,21 @@ $content.PreserveWhitespace = $true
|
|||||||
$content.Load($Path)
|
$content.Load($Path)
|
||||||
|
|
||||||
function GetPseudoLocalization([string]$key, [string]$value, [string]$comment) {
|
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 = @{}
|
$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 ','
|
$lockedList = $locked -split ','
|
||||||
$placeholderChar = 0xE000
|
|
||||||
|
|
||||||
# Replaced all locked words with placeholders from the Unicode Private Use Area
|
|
||||||
foreach ($locked in $lockedList) {
|
foreach ($locked in $lockedList) {
|
||||||
if ($locked.StartsWith('"') -and $locked.EndsWith('"')) {
|
if ($locked.StartsWith('"') -and $locked.EndsWith('"')) {
|
||||||
$locked = $locked.Substring(1, $locked.Length - 2)
|
$locked = $locked.Substring(1, $locked.Length - 2)
|
||||||
@@ -98,7 +96,7 @@ function GetPseudoLocalization([string]$key, [string]$value, [string]$comment) {
|
|||||||
$hash = [System.BitConverter]::ToInt32($hash)
|
$hash = [System.BitConverter]::ToInt32($hash)
|
||||||
$rng = [System.Random]::new($hash)
|
$rng = [System.Random]::new($hash)
|
||||||
|
|
||||||
$lines = $value.Split("`n")
|
$lines = $value -split '\r?\n'
|
||||||
$lines = $lines | ForEach-Object {
|
$lines = $lines | ForEach-Object {
|
||||||
# Replace all characters with pseudo-localized characters
|
# Replace all characters with pseudo-localized characters
|
||||||
$newValue = ''
|
$newValue = ''
|
||||||
@@ -117,11 +115,12 @@ function GetPseudoLocalization([string]$key, [string]$value, [string]$comment) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Add 40% padding to the end of the string
|
# 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)
|
$padding = ' !!!' * ($paddingLength / 4 + 1)
|
||||||
$newValue + $padding.Substring(0, $paddingLength)
|
$newValue + $padding.Substring(0, $paddingLength)
|
||||||
}
|
}
|
||||||
return $lines -join "`n"
|
$lines = $lines -join "`r`n"
|
||||||
|
return $lines
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($path.EndsWith(".resw")) {
|
if ($path.EndsWith(".resw")) {
|
||||||
@@ -133,7 +132,7 @@ if ($path.EndsWith(".resw")) {
|
|||||||
elseif ($path.EndsWith(".xml")) {
|
elseif ($path.EndsWith(".xml")) {
|
||||||
foreach ($parent in $content.DocumentElement.SelectNodes('//*[@_locID]')) {
|
foreach ($parent in $content.DocumentElement.SelectNodes('//*[@_locID]')) {
|
||||||
$locID = $parent.GetAttribute('_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()')) {
|
foreach ($entry in $parent.SelectNodes('text()')) {
|
||||||
$value = $entry.Value
|
$value = $entry.Value
|
||||||
|
|||||||
Reference in New Issue
Block a user