L18L wrote:eval is outside.
In the context of
gettext:
Code: Select all
# #example
#echo "$(gettext 'hello $adjective world')"
hello $adjective world
#
#
# adjective='wonderful'
# echo "$(gettext 'hello $adjective world')"
hello $adjective world
#
# echo "$(eval echo `gettext 'hello $adjective world'`)"
hello wonderful world
#
And in our
"new" syntax: Code: Select all
# echo "$eval ${_M_1:-hello $adjective world}"
hello wonderful world
#
Try it yourself please.
regards
EDIT
Converting from and to .po format can be done (and has be done) simply of course.
Hi L18L,
With a bit of online research and some trial and error, I actually managed to get
eval working before I received your last reply although I don't understand all the mechanisms behind it.
Hence, I have discovered and implemented the following techniques.
In order for a variable to NOT be resolved, when used in a String assigned to another variable, it needs to be escaped with a Backslash (i.e. \) before the $ symbol.
For example, if we have a variable named var1 which has a value of 123 (var1=123), then, the following statement ...
Code: Select all
_M_01="This string references the variable var1 by using \$var1"
... will cause _M_01 to have a value of
This string references the variable var1 by using $var1
Otherwise, if the following statement was used ...
Code: Select all
_M_01="This string references the variable var1 by using $var1"
... the resulting value of _M_01 would be
This string references the variable var1 by using 123
A variable reference, within a String, needs to be escaped with a Backslash when you want to use the eval Command to evaluate the string stored by the Referencing variable (i.e. _M_01) to retrieve the current value for variables referenced by _M_01.
This is important to consider, when included Code Source files reference variables of the including Script file, as referenced variables will be resolved immediately, when a Code Source file is included, unless they are escaped with a Backslash.
In relation to the techniques proposed by technosaurus, using these methods allows the retrieval of the current value of a Referenced variable (e.g. var1) without the need to reload a Code Source file.
For eval and/or echo to correctly parse New Lines, variables declared in the executed Script file or a Code Source file need to use '\n' for a New Line (Line Break). Actual line breaks can't be used.
The following code is an example of what I have implemented.
Code Source file
Code: Select all
_M_01="Other language before new lines'\n\n'Other language after new lines \$var2"
Script file
Code: Select all
var1="Text before new lines'\n\n'Text after new lines \$var2"
var1Yad=`eval "echo "${_M_01:-$var1}""`
yad --title "Title" --width 580 --center --text "$var1Yad"
However, with t12s, when entering '\n' or '\n\n' for a message the Single Quotes ' were being changed to Apostrophes ´ and I couldn't determine a way to escape the Single Quotes to stop them from being changed to Apostrophes which made testing difficult.
So, I commented the following line to prevent it from being executed.
Code: Select all
#new_msgtr=`echo $new_msgtr | sed -e "s${delim}'${delim}´${delim}g"` # change quote to apostrophe
When restarting t12s, though, the Backslashes had been removed so that '\n\n' had become 'nn'.
Which line of code is causing that to happen? Could it be the following?
Code: Select all
sed -r "s${delim}="${delim}\n${delim}g;s${delim}"\$${delim}${delim}g" ${T}/${this_LANG}/${app} > /dev/shm/t # just for inspection
I also learnt that Round Brackets, ( and ), need to be escaped with a Backslash.
A bug I noticed with t12s is that when you click on the Ok button, to re-edit a message, the message is deleted and then you have to click on the Ok button again to re-enter text.
Thanks, Michael.