stemsee wrote: Mon May 08, 2023 10:05 pm
I spent the day getting snapp script gettext ready, all labels, notifications , help, and presented text....just need translations. Maybe I can acheive that programatically.
So yesterday I achieved success in regards to gettexting the script. So I only have a vague idea of the gettext process, I know that there are two code forms used when adding gettext one with variable expansion and one without, they look like this "$(gettext "$A_TEXT")", "$(gettext 'This is a test')". I also know that you don't normally gettext code, because even if you translate binary and script names within the script, outside of the script the binaries still have their original names.....you could link those executables with links named in the desired language, that should work, and maybe its a good idea. Gettext also requires some preparation, in preparing the 'po' files (i think), with the translated menu and text items. So generally speaking to cover translations for many languages requires several people to do the preparation for each language translation, creating sets of translated snippets for menus and help and feedback texts etc. But now from today there is another option .....
Introducing stemsee's 'transtext'
This is an internal option which depends on the 'trans' script and 'google' translation service.
So, gettext your scripts as usual. Then create a gettext function
Code: Select all
function gettext {
#if [[ $(echo "$EXIP" | grep "[0-255].[0-255].[0-255].[0-255]") != "" ]]; then
if [ $(type -p trans) != "" ]; then
lng=$(locale | grep LANG | cut -c6,7)
WORK=$(echo -e "$1" | timeout 7 trans -e google -b -tl "$lng")
[ "$WORK" ] && echo "$WORK" || echo "$1"
#fi
else
echo "$1"
fi
};export -f gettext
Now the gettext strings are translated 'live' into the system's locale setting's language! This results in a delay when opening gui windows or initiating new functions, while the translations are executed. If there is no internet connection or trans is not installed then it remains in English, and there is no delay.

- xscreenshot-20230513T081314.png (204.85 KiB) Viewed 4519 times
I have tested in four languages so far .... all fairly succesful, but maybe not the 'best' vocabulary selections used in idiomatic or computer jargon expressions. This is a first attempt so room for improvement.
The next step is to save these translations locally so retrieval delays will then be minimised if not eradicated , after first uses. The saving and retrieval system ideally should be compatible with the gettext system, which i don't yet understand, or proprietary, which is my usual thing. Either way I think it will be difficult. Maybe need some help with that one!
Phew...that saved a lot of 'leg work' .... snapp is now available in every language which google translate has available to we-the-public.
--------------------------------------------------------------------------------
I have taken the book64 password entry function just one step further.
Previously I added 'OffSet' but to be clear OffSet is usual for the end of string padding, so to balance this out I felt compelled to add 'OnSet' settings as well. OnSet is for the beginning of string padding and OffSet is for the end of string padding. So the actual code is somewhere within a longer string, only you know the start and end points. Padding works with unencoded passwords too. For example, the password 'CryptoCop555' can be OnSet padded 'NiceCryptoCop555' the padding is 'Nice' , isn't it, which is 4 character places, so the OnSet value is '4 + 1 = 5', our password starts at the fifth character place. Add OffSet padding 'NiceCryptoCop555Moron', The OffSet is 'Moron', which is 5 character places, so the OffSet value is '5 + 1 = 6'. Just remember 5/6 ... as a tempo! Because of this you can just remember favourite musical pieces and its tempo 2/4, 5/4, 6/8 etc. And give yourself a 'hint' in the comment or book title. It's optional and doesn't need to be used for those who want to keep it simple and quick.

- xscreenshot-20230513T080657.png (145.36 KiB) Viewed 4519 times
The security and password gui mechanism has now been moved to its own function that can be called and used by other parts of the script and its functions.
Also I added a bit of code which selects a default player. The last is the preferred option.
Code: Select all
[[ $(type -p mplayer) != "" ]] && player="mplayer"
[[ $(type -p pmusic) != "" ]] && player="pmusic"
[[ $(type -p vlc) != "" ]] && player="vlc"
[[ $(type -p ffplay) != "" ]] && player="ffplay"
[[ $(type -p mpv) != "" ]] && player="mpv"