Add gettext support

This commit is contained in:
zenobit 2023-03-26 21:31:30 +02:00
parent df0cbe0875
commit d4a4fd1849
1 changed files with 69 additions and 51 deletions

120
dh
View File

@ -1,40 +1,42 @@
#!/bin/bash #!/bin/bash
# bugs notice # bugs notice
some_bugs() { function some_bugs() {
echo "Done echo "$(gettext "Done")
PS: You saw some bugs? PS: $(gettext "You saw some bugs?")
Could you please provide feedback? $(gettext "Could you please provide feedback?")
How do you like DistroHopper? $(gettext "How do you like DistroHopper?")
What can be improved, added, changed? $(gettext "What can be improved, added, changed?")
Let me know on project page: $(gettext " Let me know...")
https://github.com/oSoWoSo/DistroHopper $(gettext "Flawless distro hopping...") zenobit"
Homepage: dh.osowoso.xyz
Flawless distro hopping... zenobit"
} }
show_help() { show_help() {
echo " echo "
Possible arguments: $(gettext "Possible arguments:")
-h --help Show this help and exit -h --help $(gettext "Show this help and exit")
--------------------------------------------------------- ---------------------------------------------------------
-d --dir Set default directory where VMs are stored -d --dir $(gettext "Set default directory where VMs are stored")
-i --install Install DistroHopper -i --install $(gettext "Install DistroHopper")
--------------------------------------------------------- ---------------------------------------------------------
-m --mode Portable mode -m --mode $(gettext "Portable mode")
--------------------------------------------------------- ---------------------------------------------------------
-s --supported Update supported VMs -s --supported $(gettext "Update supported VMs")
-r --ready Update ready to run VMs -r --ready $(gettext "Update ready to run VMs")
--------------------------------------------------------- ---------------------------------------------------------
-t --tui Run TUI -t --tui $(gettext "Run TUI")
-g --gui Run GUI -g --gui $(gettext "Run GUI")
--------------------------------------------------------- ---------------------------------------------------------
-a --add Add new distro to quickget -a --add $(gettext "Add new distro to quickget")
-f --functions Sort functions in quickget -f --functions $(gettext "Sort functions in quickget")
-p --push Push changed quickget to quickemu project #todo -p --push $(gettext "Push changed quickget to quickemu project #todo")
--------------------------------------------------------- ---------------------------------------------------------
-c --copy Copy all ISOs to target dir (for Ventoy) -c --copy $(gettext "Copy all ISOs to target dir (for Ventoy)")
---------------------------------------------------------" ---------------------------------------------------------
$(gettext "Homepage:") dh.osowoso.xyz
$(gettext "Project hosted at:") https://github.com/oSoWoSo/DistroHopper
$(gettext "Chat group on SimpleX:") https://tinyurl.com/7hm4kcjx
"
} }
portable() { portable() {
@ -57,12 +59,12 @@ mode_installed() {
# installation # installation
check_gui_dependencies() { check_gui_dependencies() {
[ -f "$PREFIX/yad" ] || echo "You are missing yad... [ -f "$PREFIX/yad" ] || echo "$(gettext "You are missing yad...")
It's needed for GUI!" It's needed for GUI!"
} }
check_tui_dependencies() { check_tui_dependencies() {
[ -f "$PREFIX/fzf" ] || echo "You are missing fzf... [ -f "$PREFIX/fzf" ] || echo "$(gettext "You are missing fzf...")
It's needed for TUI!" It's needed for TUI!"
} }
@ -82,15 +84,13 @@ set_variables() {
# Set traps to catch the signals and exit gracefully # Set traps to catch the signals and exit gracefully
trap "exit" INT trap "exit" INT
trap "exit" EXIT trap "exit" EXIT
echo "DistroHopper v. $version"
echo "quickemu v. $("$prefix"quickemu --version)"
} }
create_structure() { create_structure() {
source distrohopper.conf source distrohopper.conf
echo "creating config dir..." echo "$(gettext "creating config dir...")"
mkdir -p "$DH_CONFIG_DIR" mkdir -p "$DH_CONFIG_DIR"
echo "creating icons dir as root..." echo "$(gettext "creating icons dir as root...")"
mkdir -p "$DH_ICON_DIR" >/dev/null 2>&1 || sudo mkdir -p "$DH_ICON_DIR" mkdir -p "$DH_ICON_DIR" >/dev/null 2>&1 || sudo mkdir -p "$DH_ICON_DIR"
} }
@ -113,9 +113,9 @@ install_dh() {
cp dh quickget quickemu macrecovery windowskey "$PREFIX" >/dev/null 2>&1 || sudo cp dh quickget quickemu macrecovery windowskey "$PREFIX" cp dh quickget quickemu macrecovery windowskey "$PREFIX" >/dev/null 2>&1 || sudo cp dh quickget quickemu macrecovery windowskey "$PREFIX"
# quickget also to config directory for adding new distros... # quickget also to config directory for adding new distros...
cp quickget "$DH_CONFIG_DIR/" cp quickget "$DH_CONFIG_DIR/"
echo "Copying icons..." echo "$(gettext "Copying icons...")"
cp icons/* "$DH_ICON_DIR/" >/dev/null 2>&1 || sudo cp icons/* "$DH_ICON_DIR/" cp icons/* "$DH_ICON_DIR/" >/dev/null 2>&1 || sudo cp icons/* "$DH_ICON_DIR/"
echo "Copying to config dir..." echo "$(gettext "Copying to config dir...")"
cp -r ready "$DH_CONFIG_DIR/" cp -r ready "$DH_CONFIG_DIR/"
cp -r supported "$DH_CONFIG_DIR/" cp -r supported "$DH_CONFIG_DIR/"
@ -125,14 +125,14 @@ install_process() {
check_tui_dependencies check_tui_dependencies
check_gui_dependencies check_gui_dependencies
#check_quickemu_dependencies #check_quickemu_dependencies
echo "Creating directory structure..." \ echo "$(gettext "Creating directory structure...")" \
&& create_structure \ && create_structure \
&& echo "Setting up directory..." \ && echo "$(gettext "Setting up directory...")" \
&& set_dir \ && set_dir \
&& echo "Installing needed..." \ && echo "$(gettext "Installing needed...")" \
&& echo "For now voidlinux only" \ && echo "$(gettext "For now voidlinux only")" \
&& install_prereq \ && install_prereq \
&& echo "Installing DistroHopper to bin..." \ && echo "$(gettext "Installing DistroHopper to bin...")" \
&& install_dh && install_dh
} }
@ -141,7 +141,7 @@ renew_ready() {
cd "$VMS_DIR" || exit 1 cd "$VMS_DIR" || exit 1
rm "$DH_CONFIG_DIR"/ready/*.desktop rm "$DH_CONFIG_DIR"/ready/*.desktop
if [ ! -e *.conf ]; then if [ ! -e *.conf ]; then
echo "No .conf files found" echo "$(gettext "No .conf files found")"
return return
fi fi
for vm_conf in *.conf; do for vm_conf in *.conf; do
@ -273,7 +273,7 @@ run_tui() {
printf ' Prepared VMs:\n-------------\n\n' printf ' Prepared VMs:\n-------------\n\n'
# Check if there are any VMs # Check if there are any VMs
if [ ${#vms[@]} -eq 0 ]; then if [ ${#vms[@]} -eq 0 ]; then
echo "No VMs found." echo "$(gettext "No VMs found.")"
exit 1 exit 1
fi fi
# Print the names of the available VMs # Print the names of the available VMs
@ -378,9 +378,27 @@ add_distro() {
meld "${TMP_DIR}/${NAME}.tmp $DH_CONFIG_DIR/quickget" meld "${TMP_DIR}/${NAME}.tmp $DH_CONFIG_DIR/quickget"
} }
function localization() {
# načtení souboru s lokalizací
. gettext.sh
# nastavení domovského adresáře pro lokalizace
TEXTDOMAINDIR=./locale
# nastavení domovského jména pro skript
TEXTDOMAIN=dh
# použití gettext() pro lokalizaci výpisu
#echo $(gettext "Hello, world!")
}
# run # run
set_variables set_variables
localization
if [[ $# -eq 0 ]]; then
printf "$(gettext "No argumet provided!\n\n")"
show_help
exit 0
fi
while [[ $# -gt 0 ]] while [[ $# -gt 0 ]]
do do
@ -395,62 +413,62 @@ do
shift shift
;; ;;
-i|--install) -i|--install)
echo "Starting installation..." echo "$(gettext "Starting installation...")"
install_process install_process
shift shift
;; ;;
-m|--mode) -m|--mode)
echo "Switching to portable mode!" echo "$(gettext "Switching to portable mode!")"
mode_portable mode_portable
shift shift
;; ;;
-s|--supported) -s|--supported)
echo "Updating supported VMs..." echo "$(gettext "Updating supported VMs...")"
renew_supported renew_supported
shift shift
;; ;;
-r|--ready) -r|--ready)
echo "Updating ready VMs..." echo "$(gettext "Updating ready VMs...")"
renew_ready renew_ready
shift shift
;; ;;
-t|--tui) -t|--tui)
echo "Running TUI..." echo "$(gettext "Running TUI...")"
run_tui run_tui
shift shift
;; ;;
-g|--gui) -g|--gui)
echo "Starting DistroHopper GUI..." echo "$(gettext "Starting DistroHopper GUI...")"
run_gui run_gui
shift shift
;; ;;
-a|--add) -a|--add)
echo "Adding new distro started..." echo "$(gettext "Adding new distro started...")"
add_distro add_distro
shift shift
;; ;;
-f|--functions) -f|--functions)
echo "Sorting functions in template..." echo "$(gettext "Sorting functions in template...")"
sort_functions sort_functions
shift shift
;; ;;
-p|--push) -p|--push)
echo "Pushing changes to... #TODO" echo "$(gettext "Pushing changes to... #TODO")"
push_changes push_changes
shift shift
;; ;;
-c|--copy) -c|--copy)
echo "Copying ISOs to dir. It will take some time..." echo "$(gettext "Copying ISOs to dir. It will take some time...")"
isos_to_dir isos_to_dir
shift shift
;; ;;
-e|--test) -e|--test)
echo "Running supported test..." echo "$(gettext "Running supported test...")"
renew_supported_test renew_supported_test
shift shift
;; ;;
*) *)
echo "Invalid option: $1" printf "$(gettext "Invalid option: $1\n\n")"
show_help show_help
exit 1 exit 1
;; ;;