#!/bin/bash
#Script to localize antiX Linux File Manager (zzzFM's) "add-ons": Common Bookmarks, Home Bookmark, Recent Files and Trash related entries, by PPC, 7/2/2023, GPL
        TEXTDOMAINDIR=/usr/share/locale
        TEXTDOMAIN=zzzfmlocalize  ###NOTE: this is just an example, the dev team is free to choose
        
trash_label=$"Trash"
trash_menu_entry=$"Send to Trash" 
restore_menu_entry=$"Restore" 
recents_label=$"Recent Files"

#make sure that zzzfm is not running (yes, this makes desktop icons disapear, if using a zzz desktop
#pkill zzzfm && sleep 0.1

#Generic variable(s)
targetfile=~/.config/zzzfm/session

#Localize Downloads Bookmark and path
label=$(echo $XDG_DOWNLOAD_DIR| cut -d/ -f4)
sed -i "s/cstm_6c99bdd2-label=.*/cstm_6c99bdd2-label=$label/g"  $targetfile
sed -i "s|cstm_6c99bdd2-z=.*|cstm_6c99bdd2-z=$HOME/$label|g"  $targetfile

#Localize Documents Bookmark and path
label=$(echo $XDG_DOCUMENTS_DIR| cut -d/ -f4)
sed -i "s/cstm_1f966a72-label=.*/cstm_1f966a72-label=$label/g"  $targetfile
sed -i "s|cstm_1f966a72-z=.*|cstm_1f966a72-z=$HOME/$label|g"  $targetfile

#Localize Pictures Bookmark and path
label=$(echo $XDG_PICTURES_DIR| cut -d/ -f4)
sed -i "s/cstm_23f8698b-label=.*/cstm_23f8698b-label=$label/g"  $targetfile
sed -i "s|cstm_23f8698b-z=.*|cstm_23f8698b-z=$HOME/$label|g"  $targetfile

#Localize Videos Bookmark and path
label=$(echo $XDG_VIDEOS_DIR| cut -d/ -f4)
sed -i "s/cstm_3be1d265-label=.*/cstm_3be1d265-label=$label/g"  $targetfile
sed -i "s|cstm_3be1d265-z=.*|cstm_3be1d265-z=$HOME/$label|g"  $targetfile

#Localize Music Bookmark and path
label=$(echo $XDG_MUSIC_DIR| cut -d/ -f4)
sed -i "s/cstm_1bd6d9d6-label=.*/cstm_1bd6d9d6-label=$label/g"  $targetfile
sed -i "s|cstm_1bd6d9d6-z=.*|cstm_1bd6d9d6-z=$HOME/$label|g"  $targetfile

#Localize Trash related entries 
#Trash bookmark
sed -i "s/cstm_3ca29516-label=.*/cstm_3ca29516-label=$trash_label/g"  $targetfile
#Send to Trash contextual menu entry
sed -i "s/cstm_25a291d5-label=.*/cstm_25a291d5-label=$trash_menu_entry/g"  $targetfile
#Restore from Trash contextual menu entry
sed -i "s/cstm_2b015761-label=.*/cstm_2b015761-label=$restore_menu_entry/g"  $targetfile

#localized Recent Files bookmark:
#use geany's localization string, for now (our own localization can be added later, when creating the localization fils for the "addons" o zzzfm...
export TEXTDOMAIN=geany;  recents_label=$(echo "$(gettext "Recent _Files")")
#remove any underscore
recents_label=${recents_label//_/}
#localize bookmark
sed -i "s/cstm_0f7a0cea-label=.*/cstm_0f7a0cea-label=$recents_label/g"  $targetfile

#Localize Home bookmark:
TEXTDOMAINDIR=/usr/share/locale
TEXTDOMAIN=zzzfm
homie=$"Home"
sed -i "s/cstm_2b7f3cb1-label=.*/cstm_2b7f3cb1-label=$homie/g"  $targetfile

#Localize Details/Compact view toolbar buttons:
TEXTDOMAINDIR=/usr/share/locale
TEXTDOMAIN=zzzfm
label=$"_Detailed"
sed -i "s/cstm_248656b5-label=.*/cstm_248656b5-label=$label/g"  $targetfile
TEXTDOMAINDIR=/usr/share/locale
TEXTDOMAIN=zzzfm
label=$"_Compact"
sed -i "s/cstm_6c5d99cd-label=.*/cstm_6c5d99cd-label=$label/g"  $targetfile

echo "localized" > ~/.config/zzzfm/zzzfm_already_localized
