1

In linux shell script I can change the language very easily, using variables to detect SO language and execute variables depending on the language:

Example:

# english
echo "Hello world"
blabla
echo "Done"

# spanish
echo "Hola mundo"
blabla
echo "Terminado"

# solution
greeting=("Hello World" "Hola Mundo")
goodbye=("Done" "Terminado")

test "${LANG:0:2}" == "en"
eng=$?

echo ${greeting[${eng}]}
blablabla
echo ${goodbye[${eng}]}

How can I do that in batch script - cmd?

Example bat script:

# english
echo Hello world
blabla (cmd command)
echo Bye

# spanish
echo Hola Mundo
blabla (cmd command)
echo Hasta la vista Baby

Update:

I found this batch maybe it can be useful (based on Languaje Codes)

set Key="HKEY_CURRENT_USER\Control Panel\International"
for /F "tokens=3" %%a in ('reg query %Key% ^| find /i "LocaleName"') do set Language=%%a

Output:

set Language=en-US

but it is only necessary: en

1
  • You can parse systeminfo for System Locale to detect system's language. NB: taskkill without /im, and possibly with /f as well, won't work :) Commented Oct 26, 2016 at 22:18

1 Answer 1

2

This way keeps things most closely to the way it is done in UNIX shells. That is not to say that there might not be better ways. Keep in mind that you might not have the same amount of environment variable space as you do in a UNIX shell.

C:>TYPE ml.bat
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

SET "GREETING[0]=Hello World"
SET "GREETING[1]=Hola Mundo"
SET "GOODBYE[0]=Done"
SET "GOODBYE[1]=Terminado"

SET "KEY=HKEY_CURRENT_USER\Control Panel\International"
FOR /F "usebackq tokens=3" %%a IN (`reg query "%KEY%" ^| find /i "LocaleName"`) do set Language=%%a
SET "UL=%LANGUAGE:~0,2%"
IF "%UL%" EQU "en" (SET /A L=0)
IF "%UL%" EQU "es" (SET /A L=1)

ECHO !GREETING[%L%]!
ECHO !GOODBYE[%L%]!

EXIT /B %ERRORLEVEL%

The output is:

C:>CALL ml.bat
Hello World
Done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.