Repository: microsoft/terminal
File: tools/ConvertTo-PseudoLocalization.ps1 (PowerShell)

Code before:
        $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)
                $locked = $locked.Replace('\"', '"')
            }

            $placeholder = "$([char]$placeholderChar)"
            $placeholderChar++

            $placeholders[$placeholder] = $locked
            $value = $value.Replace($locked, $placeholder)
        }
    }

    # We can't rely on $key.GetHashCode() to be consistent across different runs,
    # because in the future PowerShell may enable UseRandomizedStringHashAlgorithm.
    $hash = [System.Text.Encoding]::UTF8.GetBytes($key)
    $hash = [System.Security.Cryptography.SHA1]::Create().ComputeHash($hash)
    $hash = [System.BitConverter]::ToInt32($hash)
    $rng = [System.Random]::new($hash)

    $lines = $value -split '\r?\n'
    $lines = $lines | ForEach-Object {
        # Replace all characters with pseudo-localized characters
        $newValue = ''
        foreach ($char in $_.ToCharArray()) {
            if ($m = $mapping[$char]) {
                $newValue += $m[$rng.Next(0, $mapping[$char].Length)]
            }
            else {
                $newValue += $char
            }
        }

        # Replace all placeholders with their original values
        foreach ($kv in $placeholders.GetEnumerator()) {
            $newValue = $newValue.Replace($kv.Key, $kv.Value)
        }

        # Add 40% padding to the end of the string
        $paddingLength = [System.Math]::Round(0.4 * $newValue.Length)
        $padding = ' !!!' * ($paddingLength / 4 + 1)
        $newValue + $padding.Substring(0, $paddingLength)
    }
    $lines = $lines -join "`r`n"
    return $lines
}


Review comment (suggestion):
`` `n `` leaves the `` `r `` in the strings, which is... ugh. Well so that's fixed now.
Also, some files seem to be LF and some CRLF? So now it's using a regex.

Code after:
        }

        $lockedList = $locked -split ','

        foreach ($locked in $lockedList) {
            if ($locked.StartsWith('"') -and $locked.EndsWith('"')) {
                $locked = $locked.Substring(1, $locked.Length - 2)
                $locked = $locked.Replace('\"', '"')
            }

            $placeholder = "$([char]$placeholderChar)"
            $placeholderChar++

            $placeholders[$placeholder] = $locked
            $value = $value.Replace($locked, $placeholder)
        }
    }

    # We can't rely on $key.GetHashCode() to be consistent across different runs,
    # because in the future PowerShell may enable UseRandomizedStringHashAlgorithm.
    $hash = [System.Text.Encoding]::UTF8.GetBytes($key)
    $hash = [System.Security.Cryptography.SHA1]::Create().ComputeHash($hash)
    $hash = [System.BitConverter]::ToInt32($hash)
    $rng = [System.Random]::new($hash)

    $lines = $value -split '\r?\n'
    $lines = $lines | ForEach-Object {
        # Replace all characters with pseudo-localized characters
        $newValue = ''
        foreach ($char in $_.ToCharArray()) {
            if ($m = $mapping[$char]) {
                $newValue += $m[$rng.Next(0, $mapping[$char].Length)]
            }
            else {
                $newValue += $char
            }
        }

        # Replace all placeholders with their original values
        foreach ($kv in $placeholders.GetEnumerator()) {
            $newValue = $newValue.Replace($kv.Key, $kv.Value)
        }

        # Add 40% padding to the end of the string
        $paddingLength = [System.Math]::Round(0.4 * $newValue.Length)
        $padding = ' !!!' * ($paddingLength / 4 + 1)
        $newValue + $padding.Substring(0, $paddingLength)
    }
    $lines = $lines -join "`r`n"
    return $lines
}