@isidroco: Your latest script in post
#12 works fine on French Windows:
Code: Select all
C:\Temp>post12
. \Users\ADMINI~1\AppData\Local\Temp\test#.tmp (Oui/Non/Tous)
yes = Oui
no = Non
all = Tous
yes character = O
no character = N
all character = T
C:\Temp>
Still, it needs lots of changes to support all possible cases. As the example in Russian has shown, Microsoft localizers can be quite creative!
Here's what I think must be done to handle all known cases (English, Spanish, German, French, Russian):
- Remove the trailing spaces and ':'.
- If the last character is ')', look for the matching '('.
- If the last character is ']', look for the matching '['.
- Remove all characters until that last matching '(' or '['. (This can be done in a very short loop, to handle the case of () or [] appearing in the file name.)
- Only then, use a for "delim=/" to split what remains in 3 parts.
Sample implementation:
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set "echo.var=call :echo.var"
goto :main
:echo.var %1=Variable name
echo set "%1=!%1!"
exit /b
:main
:# Try overwriting a file, to collect the question asked by the copy command
set "TEMP_FILE=%TEMP%\yes-no-all.tmp"
copy /y nul "%TEMP_FILE%" >nul
set "PromptLine="
for /f "delims=" %%A in (
'^<nul copy /-y nul "%TEMP_FILE%"'
) do if not defined PromptLine set "PromptLine=%%A"
del "%TEMP_FILE%"
:# set "PromptLine=Overwrite foo.tmp? (Yes/No/All):" &:# English
:# set "PromptLine=¿Sobrescribir foo.tmp? (Sí/No/Todos):" &:# Spanish
:# set "PromptLine=foo.tmp überschreiben? (Ja/Nein/Alle):" &:# German
:# set "PromptLine=Remplacer foo.tmp (Oui/Non/Tous) :" &:# French
:# set "PromptLine=Заменить foo.tmp [Yes (да)/No (нет)/All (все)]:" &:# Russian
%echo.var% PromptLine
:# Remove the trailing spaces and :
set "YesNoAll=!PromptLine: =!"
set "YesNoAll=!YesNoAll::=!"
:# Find the last character, and the matching first character
set "LastC=!YesNoAll:~-1!"
set "FirstC="
if "!LastC!"==")" set "FirstC=("
if "!LastC!"=="]" set "FirstC=["
if not defined FirstC (
>&2 echo Error: Can't find the matching character for "!LastC!"
exit /b 1
)
set "YesNoAll=!YesNoAll:~0,-1!" &:# Remove that last character
:# Remove everything until that matching first character
:remove_more
set "YesNoAll0=!YesNoAll!"
set "YesNoAll=!YesNoAll:*%FirstC%=!"
if not "!YesNoAll!"=="!YesNoAll0!" goto :remove_more
%echo.var% YesNoAll
:# Extract the tokens
for /f "tokens=1-3 delims=/" %%A in ("!YesNoAll!") do (
set "yes=%%A" & set "y=!yes:~0,1!"
set "no=%%B" & set "n=!no:~0,1!"
set "all=%%C" & set "a=!all:~0,1!"
)
:# Display them all
for %%v in (yes no all y n a) do %echo.var% %%v
exit /b
Result on a French system:
Code: Select all
C:\Temp>t
set "PromptLine=Remplacer C:\Users\ADMINI~1\AppData\Local\Temp\yes-no-all.tmp (Oui/Non/Tous) : "
set "YesNoAll=Oui/Non/Tous"
set "yes=Oui"
set "no=Non"
set "all=Tous"
set "y=O"
set "n=N"
set "a=T"
C:\Temp>
Result with the Russian test string:
Code: Select all
#2 E:on V:on C:\JFL\Temp>t
# Заменить foo.tmp [Yes (да)/No (нет)/All (все)]:
# Yes(да)/No(нет)/All(все)
set "yes=Yes(да)"
set "no=No(нет)"
set "all=All(все)"
set "y=Y"
set "n=N"
set "a=A"
#2 E:on V:on C:\JFL\Temp>