gettext - the use of the apostrophe

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
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

gettext - the use of the apostrophe

#1 Post by don570 »

Here is an example for programmers to use as a guide when
writing a script for Puppy linux.

It shows the proper way to insert text (text widgets or buttons)
which have the apostrophe in the text string.

As well I show how to use Xdialog in an <action> tag.
It must be just one continuous line of code. \n is allowed by
Xdialog for several lines of text in the window.
Exporting of the variable is needed to get the string into Xdialog
which is a separate program. i.e. export TEXT3
Also note that two levels of quoting is sometimes necessary ie.

Code: Select all

"'$(gettext "Dick's Conversion")'"
The strong quoting allows the execution of gettext program

See the following --->

Code: Select all

<action>Xdialog --title "'$(gettext "Dick's Conversion")'" --inputbox "'$(gettext "Dick's button")'\n" 0 0 "'$(echo '$TEXT3')'" &</action>
Note that the above is all one line of code.

____________________________________________________

Note that the text string that is gettext'd is weak quoted i.e. double quoted
however 'My Book' string doesn't have an apostrophe so it can be strong quoted.
see image...

Image

_________________________________________________________


You can save the script as experiment.sh and test it with momanager.
It will be easy to translate.

Image

_______________________________________________________


The input file for the first entry box is a file with several lines in it
however only one line is read...

Code: Select all

<input file>'$WORKDIR'/default</input> 

Here's the final image of window. Try clicking the buttons. :lol:


Image

Code: Select all

#!/bin/bash
# apostrophe experiment

export TEXTDOMAIN=experiment.sh
export OUTPUT_CHARSET=UTF-8
 
export WORKDIR=/tmp/experiment
mkdir -p $WORKDIR
export TEXT1="$(gettext "Dick's Book") 
$(gettext "Mary's Book")
$(gettext 'My Book') 
$(gettext "Harry's Book")"


export TEXT2="$(gettext "Dick's Book 
Mary's Book
My Book 
Harry's Book")"
echo "$TEXT2" > $WORKDIR/default

export TEXT3="$(gettext "Mary's Example")"
export MAIN_DIALOG='
<window title="'$(gettext "Mary's Example")'" border-width="20">
<hbox>
<vbox space-expand="true" space-fill="true">
                      <text><label>"'$(gettext "Mary's Book
Harry's Book")'"</label></text>
                      <entry>
                                <input file>'$WORKDIR'/default</input>					
					            <variable>RESULT1</variable>					
				      </entry>
				      <entry>
                                 <input>echo "'$(gettext "Mary's Book")'"</input>					
					             <variable>RESULT2</variable>					
				      </entry>
<hseparator></hseparator>
                      <text><label>"'$TEXT2'"</label></text>
                      <list>
                      <variable>LIST</variable>
                      <height>150</height>
                      <width>250</width>            
                     <input file>'$WORKDIR'/default</input>                                 
                    </list>
    
</vbox>    
     
<vseparator></vseparator>
<vbox>
              <button>
              <label>'$(gettext "Dick's Conversion")'</label>
              <action>Xdialog --title "'$(gettext "Dick's Conversion")'" --inputbox "'$(gettext "Dick's button")'\n" 0 0 "'$(echo '$TEXT3')'" &</action>    
              </button>             
              <button>
              <label>'$(gettext "Mary's button")'</label>
              <action>Xdialog --title "$TEXT3" --ok-label "'$(gettext "Mary's Closebox")'" --msgbox "$TEXT1 " 30 30 &</action>    
              </button>            
              <text space-expand="true"><label>""</label></text>
              <button ok></button>     
</vbox>
</hbox>
</window>'
gtkdialog --program=MAIN_DIALOG 

_____________________________________________________
Last edited by don570 on Wed 19 Mar 2014, 22:50, edited 1 time in total.

slavvo67
Posts: 1610
Joined: Sat 13 Oct 2012, 02:07
Location: The other Mr. 305

#2 Post by slavvo67 »

Once again, I appreciate your work and tutelage. I have been piecing together a bunch of useful bash scripts and I've been considering a nicer interface. I wasn't so interested in the apostrophe as I was with the actual end product. Good stuff.

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

gettext - the use of the apostrophe

#3 Post by L18L »

I plead guilty to have changed sometimes some original messages to avoid these issues, e.g. changed isn't to is not,.... :oops:

Well done don thank you

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

#4 Post by Argolance »

Great!
Thanks don570...
I plead guilty to have changed sometimes some original messages to avoid these issues, e.g. changed isn't to is not,....
All the same!

Cordialement.

Post Reply