23

How can I get system locale in Windows 7?

I mean something like: cs_CZ.UTF-8

I tried writing "locale" in the command line but that doesn't work in Windows. Any suggestions?

17

There's not a specific command (or at least, not one that I'm aware of) to get this information, but you can find it between those provided by systeminfo.exe.

  • 3
    When running systeminfo on a command line, a lot of information is output to the screen. The relevant information to look for is: System Locale: en-us;English (United States) Input Locale: en-us;English (United States) – djondal May 30 '14 at 8:40
  • systeminfo /FO csv | ConvertFrom-Csv | select *locale – Ogrish Man Mar 6 '15 at 11:04
  • @Ogrish Man : This seems to be a Powershell command, but it gives me no output. Maybe because the headers are not in English. systeminfo.exe by itself works, as does gWaldo's answer in PS – mivk Jun 16 '15 at 16:19
9

Get-UICulture or Get-Host in PowerShell

(capitalization optional)

0

If you need the actual locale to conditionally do other things in a batch file you can create a batch file (save a text file as .bat extension) with the following. As a starting point this will print to the command prompt, for example, "en-us" (no quotes) You can also use the variable !VERBOSE_SYSTEM_LOCALE! for the human readable locale e.g. English(UnitedStates)

@echo off
setlocal EnableDelayedExpansion
FOR /F "delims==" %%G IN ('systeminfo.exe') Do  (
    set input=%%G
    for /l %%a in (1,1,100) do if "!input:~-1!"==" " set input=!input:~0,-1!
    IF "!input:~0,13!"=="System Locale" (
        set answer=!input:~15!
        set answer=!answer: =!
        set VERBOSE_SYSTEM_LOCALE=!answer:*;=!
        call set SYSTEM_LOCALE_WITH_SEMICOLON=%%answer:!VERBOSE_SYSTEM_LOCALE!=%%
        set SYSTEM_LOCALE=!SYSTEM_LOCALE_WITH_SEMICOLON:~0,-1!
        echo !SYSTEM_LOCALE!        
   )
)
0

In fact, your proposals fail, because they rely on searching a string ("System Locale") which changes depending on the current locale! On my french Win10Pro, the string is "Option régionale du système" (with accented letter, which is very difficult to handle properly in a CMD file).

I've done some testing, and it seems, on MY system, that the lines about locale in systeminfo output are the only ones to contain a semi-colon character (";"):

24/09/2017 17:18:43,23 | C:\CMD ()
> systeminfo | findstr ;
Option régionale du système:                fr;Français (France)
Paramètres régionaux d'entrée:              fr;Français (France)

Based on that (which may NOT be true on other systems with different languages), I coded this get_locale.cmd script :

@echo off
setlocal EnableDelayedExpansion    
FOR /F "delims==" %%A IN ('systeminfo.exe ^|  findstr ";"') do  (
    FOR /F "usebackq tokens=2-3 delims=:;" %%B in (`echo %%A`) do (
        set VERBOSE_SYSTEM_LOCALE=%%C
        REM Removing useless leading spaces ...
        FOR /F "usebackq tokens=1 delims= " %%D in (`echo %%B`) do (
            set SYSTEM_LOCALE=%%D
        )
        set SYSTEM_LOCALE_WITH_SEMICOLON=!SYSTEM_LOCALE!;
    set | findstr /I locale
    REM No need to handle second line, quit after first one
    goto :EOF
    )
)

The result of my script on MY system is:

24/09/2017 17:18:45,31 | C:\CMD ()
> get_locale.cmd
SYSTEM_LOCALE=fr
SYSTEM_LOCALE_WITH_SEMICOLON=fr;
VERBOSE_SYSTEM_LOCALE=Français (France)

Be warned, however, that the three environment variables exist only inside the script, they do NOT persist in CMD environment after the script ends (no export command as in *nix).

0

me again.

I discovered a slight enhancement to my script. Using SETX one can store environment variables into USER environment for future CMD Windows to use (as stated in SETX /? second remark).

Then the get_locale.cmd script becomes:

@ECHO OFF
SETLOCAL EnableDelayedExpansion    
FOR /F "delims==" %%A IN ('systeminfo.exe ^|  findstr ";"') DO (
    FOR /F "usebackq tokens=2-3 delims=:;" %%B IN (`echo %%A`) DO (
        SET VERBOSE_SYSTEM_LOCALE=%%C
        setx VERBOSE_SYSTEM_LOCALE "%%C" 1>NUL
        REM Removing useless leading spaces ...
        FOR /F "usebackq tokens=1 delims= " %%D IN (`echo %%B`) DO (
            SET SYSTEM_LOCALE=%%D
            setx SYSTEM_LOCALE %%D 1>NUL
        )
        SET SYSTEM_LOCALE_WITH_SEMICOLON=!SYSTEM_LOCALE!;
        setx SYSTEM_LOCALE_WITH_SEMICOLON !SYSTEM_LOCALE!; 1>NUL
    SET | findstr /I locale
    REM No need to handle second line, quit after first one
    GOTO :EOF
    )
)

For the VERBOSE_SYSTEM_LOCALE variable, since the value is possibly several words long, it is required to wrap %%C into quotes so that SETX receives only one parameter as expected.

Now, in any new CMD window, these values will be available:

16/12/2017  2:00:46 | C:\Users\Seagram ()
>set | findstr /i locale
SYSTEM_LOCALE=fr
SYSTEM_LOCALE_WITH_SEMICOLON=fr;
VERBOSE_SYSTEM_LOCALE=Français (France)

PS: It would be nice if other contributors from other countries with other languages could confirm that looking for semi-colon ';' works on their Windows systems. Thanks in advance!

  • Please consider combining this answer with your previous one. – kbyrd Dec 16 '17 at 3:16
  • @Seagram - thanks for this - I can confirm that it workds for English (United Kingom): System Locale: en-gb;English (United Kingdom) – SteveR Jan 8 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.