Skip to content

Commit

Permalink
Add localization support
Browse files Browse the repository at this point in the history
  • Loading branch information
Evilur committed Nov 18, 2022
1 parent 23fea61 commit 52b11f9
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 20 deletions.
Empty file modified images/logo.svg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 11 additions & 11 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
chmod 700 -R .
chmod 755 install mnt configure

touch ~/.config/mnt.ini # Create config file if it doesn't exists
touch ~/.config/mnt.ini # Create config file if it doesn't exists

# Create a directory where additional files will be stored
sudo mkdir -p /usr/lib/mnt
sudo rm -rf /usr/lib/mnt/langs # Delete old dictionaries
sudo cp -r langs /usr/lib/mnt/langs # Copy dictionaries
sudo chmod 755 /usr/lib/mnt -R # Set permissions

# Fill in the configuration file with data from the template
if [[ -z $(cat ~/.config/mnt.ini) ]] # If config file is empty
Expand All @@ -16,7 +22,7 @@ else
if [[ $(echo $ans | tr [:upper:] [:lower:]) =~ ^y.*$ ]]
then
echo
source configure
./configure
echo
fi
fi
Expand All @@ -27,18 +33,12 @@ then
echo 'You need to install "whiptail" to your distribution'
fi

if [[ ! -e /usr/bin/mnt ]] # If link doesn't exist
if [[ -z $(command -v mnt) ]]
then
# Create a link for this programm if directory with binary files
sudo ln ./mnt /usr/bin/mnt
else # If link or file already exists
if [[ ! -e /usr/sbin/mnt ]] # Trying to install in the sbin folder
then
sudo ln ./mnt /usr/sbin/mnt
else
echo 'File /usr/bin/mnt already exists'
exit 1
fi
else # If link or file already installed
echo 'mnt already installed'
fi

echo 'The program has been successfully installed on your computer'
Expand Down
5 changes: 5 additions & 0 deletions langs/en
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Disk mount dialog
Select the disks to mount
The operation was canceled by user
was mounted to
was unmounted
5 changes: 5 additions & 0 deletions langs/ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Монтирование дисков
Выберите диски для монтирования
Операция была отменена пользователем
примонтирован к
размонтирован
27 changes: 19 additions & 8 deletions mnt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,21 @@ declare ignore # Array with ignored disks
touch ~/.config/mnt.ini # Create config file if it doesn't exists

# Default variables
mountpoint="/mnt"
language="en"
mountpoint='/mnt'
language='en'
source <(getConfigSection general) #Get the necessary variables

# Get clean variables
mountpoint=`echo $mountpoint | sed 's/\/*$//g'`

# Get language dictionary
if [[ -f "/usr/lib/mnt/langs/$language" ]] # If dictionary exists
then
dict=(`cat /usr/lib/mnt/langs/$language`)
else
dict=(`cat /usr/lib/mnt/langs/en`)
fi

# Get associations for part labels
for var in $(getConfigSection associations)
do
Expand Down Expand Up @@ -63,7 +74,7 @@ do
fi
done

width=29 #A whiptail width
width=$((${#dict[1]}+4)) #A whiptail width

# Get the list of disks in the required form
declare -a REQUEST
Expand All @@ -84,12 +95,12 @@ do
done

# Find out which disks need to be mounted and which ones need to be unmounted
QUERY=$(whiptail --title "Disk mount dialog" --checklist \
"Select the disks to mount" $((${#parts[*]}+7)) $width ${#parts[*]} \
QUERY=$(whiptail --title ${dict[0]} --checklist \
${dict[1]} $((${#parts[*]}+7)) $width ${#parts[*]} \
${REQUEST[*]} 3>&1 1>&2 2>&3)
if [[ $? != 0 ]]
then
echo "The operation was canceled by user"
echo ${dict[2]}
exit 1
fi

Expand All @@ -104,11 +115,11 @@ do
then
sudo mkdir "$mountpoint/$name" -p
sudo mount ${parts[$var]} "$mountpoint/$name" 2>/dev/null && \
echo "$var was mounted to $mountpoint/$name"
echo "$var ${dict[3]} $mountpoint/$name"
else
sudo umount ${parts[$var]} --quiet && \
sudo rmdir "$mountpoint/$name" 2>/dev/null && \
echo "$var was unmounted"
echo "$var ${dict[4]}"
fi
done

Expand Down
2 changes: 1 addition & 1 deletion templates/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

[general]
# The language in which the program will be output.
language = '<placeholder>language</placeholder>'
language = en

# The directory where the disks will be mounted.
mountpoint = '/mnt'
5 changes: 5 additions & 0 deletions templates/localization
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Disk mount dialog # Whiptail window title
Select the disks to mount # Whiptail description
The operation was canceled by user # The message displayed when canceling
was mounted to # Part of the message when the disk is mounted successfully
was unmounted # Part of the message when the disk is successfully unmounted

0 comments on commit 52b11f9

Please sign in to comment.