4

Which batch command can I use to detect the currently used system language, (not the default language)?

I have code which checks the default system language and goes to a separate code depending on whether the detected language is Polish or another = English:

@echo OFF
FOR /F "tokens=2 delims==" %%l IN ('wmic os get OSLanguage /Value') DO set OSLanguage=%%l
IF %OSLanguage% == 1045 GOTO L_POLISH
IF %OSLanguage% NEQ 1045 GOTO L_ENGLISH

:L_POLISH
echo Polish was detected
pause
exit

:L_ENGLISH
echo English was detected
pause
exit

enter image description here

The problem is that if we install the system in e.g. Polish, and then change the language in the system to English, German, etc., the code will not detect and will not set/display and will not go to the code for the English version, but will detect the default Polish and go to Polish code.

What command can I use as a check to make the code verify the currently used version of the system language instead of the default language?

3
  • The obvious thing, I notice with your batch file, is that it is trying to make a comparison using 1045 instead of 0415, (as clearly shown in your dism output). As far as I know there is no language which uses 1045, so your code will always GOTO L_ENGLISH.
    – Compo
    Commented Mar 7, 2021 at 14:41
  • 1045 = POLISH, 1033 = ENGLISH, NEQ 1045 = always GOTO ENGLISH - i.imgur.com/j8KEAIu.png Commented Mar 7, 2021 at 15:18
  • 1
    You need to clarify exactly what you're looking for, and in what context you're intending to use it. What exactly do you need the LCID for? what are you doing with it? BTW, your DISM output is providing the hex LCID, 0415, and your OSLanguage is in a decimal LCID format, 1045. Incidentally, if you take a look at the other properties and values from your WMIC OS command, you should also note that there's a Locale property, which will use the hex LCID, and also a MUILanguages property which will provide an array of the installed language packs in string format, e.g. {"en-US","pl-PL"}
    – Compo
    Commented Mar 7, 2021 at 17:00

1 Answer 1

5

Im not too sure about cmd, but in powershell you may use Get-Culture.

The Get-Culture cmdlet gets information about the current culture settings. This includes information about the current language settings on the system, such as the keyboard layout, and the display format of items such as numbers, currency, and dates.

See Here: Get-Culture

And for user settings specifically, you can check Get-WinUserLanguageList.

The Get-WinUserLanguageList cmdlet returns the current user language settings. These settings include input method, spelling setting, text prediction setting, and handwriting input mode.

See Here:Get-WinUserLanguageList

...and when theres a Get, theres a Set. Hopefully this is what you were looking for, or if it can point you in the right direction!:)

1
  • 4
    Get-WinUserLanguageList also returns the english name of the language, which can be assigned to a variable like so: For /F "Delims=" %%G in ('powershell -c "(Get-WinUserLanguageList)[0].EnglishName"')Do Set "Language=%%G"
    – T3RR0R
    Commented Mar 7, 2021 at 17:40

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