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:
Leonard Hecker
2024-07-09 01:33:54 +02:00
committed by GitHub
parent 5bbd905ded
commit a2d7121489
3 changed files with 18 additions and 17 deletions

View File

@@ -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()

View File

@@ -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()

View File

@@ -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