How to temporarily change locale from command prompt

Viewed 26

How can I temporarily set the current system's regional format so applications such as svn list always outputs in english no matter how system is configured ?

I am using svn list to get some info on a repository and it uses the system regional format to print the items date/time. But the problem is that when system's regional format is set in French, the number of columns used for the date/time section varies from line to line.

I have an old tool (that cannot be modified) that parses the output of svn list using hardcoded column count for each values.

For instance here are the two lines in french and in english using the command svn list -v-R "URL HERE":

    935 langevin        63185 Jul 13 07:50 doc/tests.docx
    935 langevin        63185 juil. 13 07:50 doc/tests.docx

Here the filename does not start at the same column due to the month not having the same amount of characters (And it varies from month to months...

Thank you

1 Answers

You could start PowerShell to change regional settings and then start your application and when your application closes regional settings will restore regional settings that were before.

$newCulture = "en-Us" # temporary value
$UsersCulture = (Get-Culture).Name # current value

# change date/time regional settings
Set-Culture $newCulture

# start app and wait
start cmd ReplaceCmdWithYourApp -Wait

# restore old setting
Set-Culture $UsersCulture

Details about Set-Culture are here http://go.microsoft.com/fwlink/p/?linkid=287346

If PowerShell is closed by mistake while your application is running, then the original settings will not be restored. For this case I have made modifications that will fix region settings after the next run:

$newCulture = "en-Us" # temporary value

# Get culture from file. On success use this data for later restore, on error get current culture and store the value in a temporary file and use the value for later restore. 
if ($UsersCulture = Get-Content .\dns_change_2022-02-23.xml -raw -ErrorAction SilentlyContinue) {
    "Culture loaded from file"
} else {
    "Getting current culture"
    $UsersCulture = (Get-Culture).Name # current value
    $UsersCulture | Out-File $env:temp\regionalsettings_userculture.txt -NoNewline
}


# change date/time regional settings
Set-Culture $newCulture

# start app and wait
start cmd ReplaceCmdWithYourApp -Wait

# restore old setting
Set-Culture $UsersCulture
Related