Reputation: 324
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
Upvotes: 1
Views: 7163
Reputation: 16246
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
Upvotes: 2