# A dialog to get string to be replaced
$startValue = Read-Host "
Enter a language string, for example 'zh-CN', then press Enter; If empty, use 'zh-CN' as the default value"
if ($startValue -eq "") {
    $startValue = 'zh-CN'
}
$searchString = $startValue;

# A dialog to get string to replace
$inputValue = Read-Host "
Enter a language string to replace '$searchString', for example 'en-US', then press Enter"

# Confirm replacement
$response = Read-Host "
Are you sure you want to replace '$searchString' with '$inputValue'?
If you are sure, please enter 'Y/y' and press Enter; otherwise, enter 'N/n' and press Enter"

if ($response -eq "Y") {
    # Result: "lang/zh-CN" => "lang/en-US"

    $replaceString = $inputValue

    # Get all js and ts files
    $files = Get-ChildItem -Path '.\scripts\global\' -Filter "namespace*" -File -Recurse

    # Perform replacement operation on each file individually
    foreach ($file in $files) {
        # Get
        $content = Get-Content -Path $file.FullName -Raw
        
        # Replace
        $newContent = $content -replace [Regex]::Escape($searchString), $replaceString
        
        # Fill
        Set-Content -Path $file.FullName -Value $newContent
    }
    # Success
    Read-Host -Prompt 'Operation successful! Press Enter to exit.'
}
