gettext: escape single quotes... and other goodies [SOLVED]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

gettext: escape single quotes... and other goodies [SOLVED]

#1 Post by Argolance »

Hello,
Using gettext, this works:
<text><label>$(gettext 'I know')</label></text>
But this doesn't:
<text><label>$(gettext 'I don't know')</label></text>
It is not the first time I encounter this problem. So far, I was used to get around the problem by writing:
<text><label>$(gettext 'I do not know')</label></text>
or
<text><label>$(gettext "I don't know ")</label></text>
I would rather like to know if there is any character which could let me escape single quotes inside a chain?

Thank you!
Cordialement.
Last edited by Argolance on Wed 13 Feb 2013, 19:42, edited 3 times in total.

postfs1

#2 Post by postfs1 »

Code: Select all

busybox echo 'I don'"'"'t know'
OUTPUT wrote: I don't know
Last edited by postfs1 on Sun 27 Mar 2016, 21:21, edited 6 times in total.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#3 Post by Argolance »

Hello postfs1,
:D :D
Thank you!

Cordialement.

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#4 Post by don570 »

Another solution...

utf-8 characters i.e. unicode has other quote characters
available to users.

I open up Abiword and go to the top menu

Insert > symbol

and find another quote symbol in dejavu font.

___________________________________________________

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#5 Post by Argolance »

Thanks!

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

apostrophe in gettext

#6 Post by don570 »

I've been experimenting using pupmd5sum.sh

As an example I try to make a button label showing 'John's message'
This was able to work...

Code: Select all

<button>
     <label>'"$(gettext "John's message")"'</label>
     <action>checkfunc '"$ENT1"'</action>
     <action type="refresh">ENT2</action>
</button>
Image




BTN1=$(gettext 'John's message')
resulted in an error
unexpected EOF while looking for matching `)'
________________________________________________________


Edit: deleted a section because of bad info


_________________________________________
Last edited by don570 on Mon 11 Feb 2013, 23:11, edited 2 times in total.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: apostrophe in gettext

#7 Post by L18L »

don570 wrote: Also I could do a substitution like this...

First define variable ABC

ABC="John's message"

then BTN1 becomes...
BTN1=$(gettext "$ABC")
Image

________________________________________________________
Did translation work :?:

If so forget eval_gettext

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#8 Post by don570 »

L18L wrote:Did translation work?
That's a good question? I was just trying the English.

When I translated build_gettext I found that the English would work and
the translations into German and French wouldn't work. So I should have
known better :oops:

I'll take the time to test thoroughly and report back on Saturday.
______________________________________________________

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#9 Post by don570 »

When I made a fresh frugal install of precise the launch speed
of MoManager was much faster (35 seconds) , but now it has slowed
down again after I installed a few scripts.

_________________________________________________

I have found that yaf-splash can be tricky to gettext properly.

Code: Select all

yaf-splash -close box -fontsize large -bg orange -fb black -text  " $(gettext 'Sorry.  'devx' file must be loaded.')" 
works properly when typed in the terminal and in English,
but the strong quotes confuse Momanager so that a German translation
is impossible, but change the outer quotes to double(as shown below)
will make the script translate properly with MoManager.

Code: Select all

yaf-splash -close box -fontsize large -bg orange -fb black -text  " $(gettext "Sorry.  'devx' file must be loaded.")" 
.
Last edited by don570 on Sat 09 Feb 2013, 19:38, edited 1 time in total.

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#10 Post by don570 »

I checked the button labels with a German translation with MoManager.


This works for a button
<label>'$(gettext "Jim's text")'</label>

This won't work
<label>"$(gettext "Jim's text")"</label>

________________________________________________

Then I checked an assigned variable inside the gettext expression...
I did translations into German --> expressions with an apostrophe.

Image

This works
<label>'"$BTN1"'</label>

and this works
<label>'$BTN1'</label>

Here was the output in German language

Image

________________________________________________________
This didn't work
<label>"$BTN1"</label>


.

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

multiple lines of translated text in a yaf-splash window

#11 Post by don570 »

The only method I found to place multiple lines of translated text in
a yaf-splash window....

Breakup a large amount ot text into lines of text.
Text can have apostrophe.

Code: Select all

TEXT1=$(gettext ".......")
TEXT2=$(gettext ".......")
TEXT3=$(gettext ".......")
TEXT4=$(gettext ".......")
Then invoke yaf-splash with the code

Code: Select all

yaf-splash -close box -fontsize large -bg orange -fb black -text  " $TEXT1
$TEXT2
$TEXT3
$TEXT4
"
.

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#12 Post by don570 »

Xdialog was more flexible than yaf-splash. Breaking the text into lines
can also be used with Xdialog, however the following method using \\n
is more useful....

Note: two Escapes \\ should be used (one Escape \ is possible
but should be avoided)

Code: Select all

TEXT1=$(gettext "John's text \\nSecond line\\nThird line")
Xdialog  --ok-label "OK" --backtitle "\n  $TEXT1 \n "  --msgbox  "" 0 0
Here is a sample of the output of Poedit. (Note the double 'Escapes')

Image

And here is the final output in English first then German
Image

Image

_____________________________________________________

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#13 Post by don570 »

Some notes about Xdialog

1) left justification option ( --left) makes a large amount
of text look neater

2) Geometry of 0 0 forces the size of the window to resize to
fit the text.

3) Warning: Lines of Foreign language text are often longer than English.

.

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#14 Post by don570 »

I tested eval_gettext using the instructions HERE

you must put the following line before evoking eval_gettext

Code: Select all

. gettext.sh
A variable contains the output of a command. Here's the example...

Code: Select all

filecount="`ls | wc -l`"
eval_gettext "Remaining files: \$filecount"; echo
Now that the script is ready for translation , switch to German with
country Wizard , and run Momanager/Poedit.

Image

You can now do the translation into German.

Run script in terminal, and here is output...
(script_name is pupmd5sum5.sh)

Image



In the terminal
Last edited by don570 on Wed 13 Feb 2013, 18:24, edited 1 time in total.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#15 Post by Argolance »

Hello,
I didn't see your posts before although "Notify me when a reply is posted" was checked. :?
Very interesting!
But "gettexting" a script (using different xxxmessage inside) is finally complex to handle... As you walked around the problem, this thread became a very useful "tutorial"... :D
Thank you.

Cordialement.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

gettext: escape single quotes inside a chain? [SOLVED]

#16 Post by L18L »

Argolance wrote:... this thread became a very useful "tutorial"...
+1 :D

Argolance,
maybe you add something to the title like
..and other goodies

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#17 Post by Argolance »

L18L wrote:maybe you add something to the title like
..and other goodies
Done!
Last edited by Argolance on Thu 14 Feb 2013, 08:41, edited 1 time in total.

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#18 Post by don570 »

...continuing the tutorial :wink:

I tested eval_gettext using the instructions HERE

You can use the echoed text in useful situations. Here's an example with
yaf-splash. Take the echo of eval_gettext command

Code: Select all

eval_gettext "Remaining files: \$filecount"; echo
... and put backquotes around it to make a command's output text
and stick it in a standard yaf-splash line.

Code: Select all

yaf-splash -close box -fontsize large -bg orange -fb black \
-text  "`eval_gettext \"Remaining files: \\\$filecount\"; echo`"
Notes:

1) Double quote character( " ) needs to be escaped i.e. \

2) The dollar sign character($) needs three 'Escapes' i.e. \\\


Here is the output of localised script in German...

Image

.

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#19 Post by don570 »

Here's another useful example this time with an Xdialog command
with multiple lines of text in the action line of a button.

First define a variable 'MESSAGE'

Warning ! 'Export' of variable must be used.

Code: Select all

export MESSAGE=$(gettext "John's message\\nin the office") 

Here is the action line of the button...

Code: Select all

<action>Xdialog  --ok-label "$BTN4" --backtitle "\n\n    $MESSAGE  "  --msgbox  "" 0 0</action> 
Here is the output if translated to French...


Image

.

Post Reply