Answer the question
In order to leave comments, you need to log in
How to localize a script in BASH?
Good day! Sobsno wondered about the localization of the BASH script... The language files are in a certain folder. Their content is of the form: language=Russian. Their names correspond to the code names of the languages (ru.lng, en.lng, etc.). Their content is read and displayed. The problem is that I can not think of any way to display a menu for their selection. That is, a person has created his own language file (for example, uk.lng), in each of these files there is a line language=LanguageName. How can I list these languages in the menu based on the files in their language directory (the name of the language from the language file will get: language=).
I know it's a stupid question, don't kick too much. Who cares, could you provide an example of such an implementation? Thanks in advance.
Answer the question
In order to leave comments, you need to log in
#!/bin/bash
declare -A LANGUAGES
BASE="./langs"
for path in $(find $BASE -name '*.lng')
do
base=$(basename $path)
language=${base%.*}
line=$(grep "language" $path)
name=${line#*=}
LANGUAGES[$name]=$language
done
echo ${!LANGUAGES[@]}
echo ${LANGUAGES[@]}
select l in ${!LANGUAGES[@]}
do
echo "Selected: $l"
echo "Selected file: " $BASE/${LANGUAGES[$l]}.lng
break
done
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question