Skip to content

Commit

Permalink
localisation
Browse files Browse the repository at this point in the history
  • Loading branch information
zen0bit committed Mar 27, 2023
1 parent c8ec674 commit a42b38e
Show file tree
Hide file tree
Showing 13 changed files with 1,292 additions and 1,207 deletions.
140 changes: 64 additions & 76 deletions dh
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/bin/bash
#!/usr/bin/bash
# shellcheck disable=1078,1079,1091,2027,2034

TEXTDOMAIN=distrohopper
TEXTDOMAINDIR=/usr/share/locale
export "TEXTDOMAINDIR" "TEXTDOMAIN"

# bugs notice
function some_bugs() {
Expand All @@ -12,27 +17,31 @@ function some_bugs() {
}

function show_help() {
printf "DistroHopper v. $version\nquickemu v. $("$prefix"quickemu --version)\n"
echo $"Possible arguments:"
echo $" -h --help Show this help and exit"
echo "---------------------------------------------------------"
echo $" -d --dir Set default directory where VMs are stored"
echo $" -i --install Install DistroHopper"
echo "---------------------------------------------------------"
echo $" -m --mode Portable mode"
echo "---------------------------------------------------------"
echo $" -s --supported Update supported VMs"
echo $" -r --ready Update ready to run VMs"
echo "---------------------------------------------------------"
echo $" -t --tui Run TUI"
echo $" -g --gui Run GUI"
echo "---------------------------------------------------------"
echo $" -a --add Add new distro to quickget"
echo $" -f --functions Sort functions in quickget"
echo $" -p --push Push changed quickget to quickemu project #todo"
echo "---------------------------------------------------------"
echo $" -c --copy Copy all ISOs to target dir (for Ventoy)"
echo "---------------------------------------------------------"
echo $"DistroHopper v. $version"
echo $"quickemu v. $("$prefix"quickemu --version)"
echo ""
echo $"Possible arguments:"
echo $" -h --help Show this help and exit"
echo "---------------------------------------------------------"
echo $" -d --dir Set default directory where VMs are stored"
echo $" -i --install Install DistroHopper"
echo "---------------------------------------------------------"
echo $" -m --mode Portable mode"
echo "---------------------------------------------------------"
echo $" -s --supported Update supported VMs"
echo $" -r --ready Update ready to run VMs"
echo "---------------------------------------------------------"
echo $" -t --tui Run TUI"
echo $" -g --gui Run GUI"
echo "---------------------------------------------------------"
echo $" -a --add Add new distro to quickget"
echo $" -f --functions Sort functions in quickget"
echo $" -p --push Push changed quickget to quickemu project #todo"
echo "---------------------------------------------------------"
echo $" -c --copy Copy all ISOs to target dir (for Ventoy)"
echo "---------------------------------------------------------"
echo $" -l --language Translate DistroHopper"
echo "---------------------------------------------------------"
echo $"Homepage: dh.osowoso.xyz"
echo $"Project hosted at: https://github.com/oSoWoSo/DistroHopper"
echo $"Chat group on SimpleX: https://tinyurl.com/7hm4kcjx"
Expand All @@ -58,16 +67,16 @@ function mode_installed() {

# installation
function check_gui_dependencies() {
[ -f "$PREFIX/yad" ] || echo $"You are missing yad...
Needed for GUI!"
[ -f "$PREFIX/yad" ] || echo $"Missing yad!"
}

function check_tui_dependencies() {
[ -f "$PREFIX/fzf" ] || echo $"You are missing fzf...
Needed for TUI!"
[ -f "$PREFIX/fzf" ] || echo $"Missing fzf!"
}

function set_variables() {
# DEBUG mod
#bash -x ./dh 2>&1 | tee output.log
#progname="${progname:="${0##*/}"}"
progname="DistroHopper"
version="0.7"
Expand Down Expand Up @@ -117,6 +126,7 @@ function install_dh() {
echo $"Copying to config dir..."
cp -r ready "$DH_CONFIG_DIR/"
cp -r supported "$DH_CONFIG_DIR/"
cp -r locale "$DH_CONFIG_DIR/"

}

Expand All @@ -139,10 +149,11 @@ function install_process() {
function renew_ready() {
cd "$VMS_DIR" || exit 1
rm "$DH_CONFIG_DIR"/ready/*.desktop
if [ ! -e *.conf ]; then
echo $"No .conf files found"
return
fi
# for files in "$VMS_DIR"/*; do
# if [ ! -e *.conf ]; then
# echo $"No .conf files found"
# return
# fi
for vm_conf in *.conf; do
if [ "$vm_conf" == "distrohopper.conf" ]; then
continue # skip processing distrohopper.conf
Expand Down Expand Up @@ -200,6 +211,7 @@ Categories=System;Virtualization;"
echo "$desktop_file_content" > "$DH_CONFIG_DIR"/supported/"$vm_desktop".desktop
else
# Create desktop file for VMs with editions
# shellcheck disable=2154
desktop_file_content="[Desktop Entry]
Type=Application
Name=$get_name
Expand Down Expand Up @@ -343,9 +355,10 @@ Choose other language" | fzf --cycle)
function isos_to_dir() {
yad --file --directory > target
cd "$VMS_DIR" || exit 1
cp */*.iso "$target"
# shellcheck disable=2154
cp ./*glob*/*.iso "$target"
}

# shellcheck disable=2086
function add_distro() {
TMP_DIR="/tmp"
yad --form --field="Pretty name" "" --field="Name" "" --field="Releases" "" --field="Editions" "" --field="URL" "" --field="ISO" "" --field="Checksum file" "" > ${TMP_DIR}/template.tmp
Expand All @@ -357,7 +370,7 @@ function add_distro() {
ISO="$(cat ${TMP_DIR}/template.tmp | cut -d'|' -f6)"
CHECKSUM_FILE="$(cat ${TMP_DIR}/template.tmp | cut -d'|' -f7)"
echo " $NAME) PRETTY_NAME=$PRETTY_NAME;;
" > ${TMP_DIR}/${NAME}.tmp
" > "${TMP_DIR}/${NAME}".tmp
{ echo " $NAME \\
"; echo "function releases_$NAME() {
echo $RELEASES
Expand All @@ -373,11 +386,12 @@ function add_distro() {
HASH=\"$(wget -q -O- "${URL}/${CHECKSUM_FILE}" | grep "(${ISO}" | cut -d' ' -f4)\"
echo \"${URL}/${ISO} ${HASH}\"
}
"; } >> ${TMP_DIR}/${NAME}.tmp
"; } >> "${TMP_DIR}/${NAME}".tmp
meld "${TMP_DIR}/${NAME}.tmp $DH_CONFIG_DIR/quickget"
}

function sort_functions() {
#TODO
# Get the name of the script from the command line argument
script_name=$1
# Get a list of all the function names in the script
Expand All @@ -388,53 +402,26 @@ function sort_functions() {
for function_name in $sorted_function_names
do
# Print the function definition to stdout
grep -A $(wc -l < "$script_name") -w "function $function_name" "$script_name"
grep -A "$(wc -l < "$script_name")" -w "function $function_name" "$script_name"
done
}

function localization() {
. gettext.sh
TEXTDOMAIN=distrohopper
TEXTDOMAINDIR=./locale
# použití gettext() pro lokalizaci výpisu
#echo $"Hello, world!")
# ask for language
create_translation_source
export "TEXTDOMAIN" "TEXTDOMAINDIR"
}

function create_translation_source() {
cat > header.tmp <<EOF
msgid ""
msgstr ""
"Project-Id-Version: DistroHopper $version\n"
"POT-Creation-Date: $(date +%Y-%m-%d\ %H:%M%z)\n"
"PO-Revision-Date: $(date +%Y-%m-%d\ %H:%M%z)\n"
"Last-Translator: zenobit\n"
"Language-Team: Czech\n"
"Language: cs\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n>=2 && n<=4 ? 1 : 2);\n"
"X-Generator: Poedit 3.2.2\n"
"X-Poedit-Basepath: ../..\n"
"X-Poedit-SearchPath-0: .\n"
EOF
#cat ./dh | grep '$(gettext "' | cut -d'(' -f2 | cut -d'"' -f2 | cut -d')' -f1 > po.tmp
#sed -i 's/$/msgstr""\n\nmsgid "/g' po.tmp
#cat header.tmp po.tmp > locale/translation_source.po
#rm header.tmp po.tmp
#LANGUAGE="cs"
#export "LANGUAGE"
#echo "language: $LANGUAGE"
bash --dump-po-strings dh > locale/strings_dump-$version.po
function create_translation() {
echo $"Which language use [en,cs]?"
read -rn 2 -s lang
echo $"Choosed language is: $lang"
echo $"Dumping language source..."
bash --dump-po-strings dh > "$DH_CONFIG_DIR"/locale/dh-source.pot
echo $"Merging changes... (Do it yourself)"
meld "$DH_CONFIG_DIR"/locale/dh-source.pot "$DH_CONFIG_DIR"/locale/distrohopper-"$lang".pot
echo $"Generating .mo file..."
msgfmt -o "$DH_CONFIG_DIR"/locale/distrohopper-"$lang".mo "$DH_CONFIG_DIR"/locale/distrohopper-"$lang".pot
echo $"Copying translation to '/usr/share/local'..."
sudo cp "$DH_CONFIG_DIR"/locale/distrohopper-"$lang".mo /usr/share/locale/"$lang"/LC_MESSAGES/distrohopper.mo
}

# run
set_variables
localization

if [[ $# -eq 0 ]]; then
printf $"No argumet provided!\n\n"
Expand Down Expand Up @@ -510,11 +497,12 @@ do
shift
;;
-l|--language)
localization
create_translation
shift
;;
*)
printf $"Invalid option: $1\n\n"
echo $"Invalid option: $1"
echo ""
show_help
exit 1
;;
Expand Down
Loading

0 comments on commit a42b38e

Please sign in to comment.