LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-01-2009, 07:38 AM   #1
KrzysieQ
LQ Newbie
 
Registered: Aug 2007
Posts: 12

Rep: Reputation: 0
Gettext - Bash with GTK


Hi,
In Bash Script I have definition of GTK Window:

Code:
export MAIN_DIALOG='
<window title="Some title">
	<text>
		<label>"SOME TEXT HERE"</label>
	</text>
</window>
'
I would like to add the possibility of translation into other languages (Window title and text)

In source code it was simple - before any string I put '$'. For example: A=$"Some text" - but here (in GTK window definition) I have a little problem because I can't replace ' ' by " " in MAIN_DIALOG definition and ' ' isn't recognize by xgettext
 
Old 07-02-2009, 07:35 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Hello KrzysieQ
Quote:
Originally Posted by KrzysieQ View Post
I can't replace ' ' by " " in MAIN_DIALOG definition and ' ' isn't recognize by xgettext
Can you give more information about what that means?

Best

Charles
 
Old 07-02-2009, 08:32 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,845

Rep: Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006
Assuming I understood your post correctly....

Quote marks in shell scripting are more like toggle switches than containers. You can use them to turn special character interpretation off and on, pretty much at will. So if you want to make the title text a variable you can do something like this:

Code:
$ TitleText="This is a title" LabelText="This is a label"

$ export MAIN_DIALOG='
<window title="'"$TitleText"'">    #note there's one double-quote "inside" the single quotes
<text>                             #and one "outside" them.  The ones inside will display
<label>'"$LabelText"'</label>      #literally in the output because they are "protected".
</text>
</window>
'

$ echo "$MAIN_DIALOG"
<window title="This is a title">
<text>
<label>This is a label</label>
</text>
</window>
The main thing to beware of is not to have any unquoted or unescaped spaces, tabs, or newlines in the string when setting the variable, or else the shell will interpret them as being the start of a new command.

BTW, I'm with catlan. What does xgettext have to do with this? Please explain it a bit more clearly.
 
Old 07-02-2009, 09:00 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,845

Rep: Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006
Actually, come to think of it, I think all you really have to do here is use double-quotes instead of single ones, then manually escape the double-quotes you want to output.

Code:
$ TitleText="This is a title" LabelText="This is a label"

$ export MAIN_DIALOG="
<window title=\"$TitleText\">
<text>
<label>$LabelText</label>
</text>
</window>
"

$ echo "$MAIN_DIALOG"
<window title="This is a title">
<text>
<label>This is a label</label>
</text>
</window>
FYI, double-quotes (") escape all characters except for $ \ and ` (dollar sign, backslash, and backquote). This way you can still use variables, command substitution, and escape sequences in your text string. Note that the single-quote is escaped while inside them, too.

Single-quotes ('), OTOH, make literal everything except another single-quote. You can't use any commands or variables, or escape anything, while inside them.

The ABSG section on quoting will give you more details.

Last edited by David the H.; 07-02-2009 at 09:03 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Gettext with anjuta iusegnu Programming 1 08-31-2008 05:51 PM
Help with Gettext Snouser Linux - Software 2 03-03-2006 12:41 AM
php 5.0.5 and gettext ziggie216 Linux - Software 0 11-10-2005 03:26 PM
php + gettext Ateo Linux - General 0 11-09-2005 12:40 PM
exec bash scripts from Glade/GTK? HELP! cho Programming 1 07-04-2005 09:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration