> Has anyone written shell scripts that can be translated into non-English > languages? I am only interested in translation for prompts and
Use external files which contains the messages, prompts, etc. I wrote a small example script for you. It uses a file where the messages are stored by number. A record look like this : number=text At the beginning of the script, all messages are read into a one- dimentional array and the index-numbers are stored in contants. Change the line MsgFile="English.dat" when you want to use other files with messages in other languages.
Below are the two necessary files, 1st the script and the 2nd is the English.dat file.
# # The script # #!/usr/bin/ksh # Message contants msg_info="1" msg_prompt="2" msg_success="3" msg_failure="4" msh_end="5" # The message file MsgFile="English.dat" # Use grep to ignore comment- and empty lines grep -Ev '^#|^[ ]*$' ${MsgFile} | while read MsgLine do Messages[${MsgLine%%=*}]="${MsgLine##*=}" done # The part of the script which actually uses the messages echo "${Messages[${msg_info}]}" printf "${Messages[${msg_prompt}]}" ; read Value case "${Value}" in y|Y) echo "${Messages[${msg_success}]}" ;; *) echo "${Messages[${msg_failure}]}" ;; esac echo "${Messages[${msg_end}]}"
# # English.dat # 1=This is a script with multi-language support 2=Don't you think it's a nice script (Y/N) ? : 3=I thought so ! 4=That's to bad ! 5=This is the end of the script - bye.