LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 06: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, 06:35 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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, 07:32 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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, 08:00 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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 08:03 AM.
 
  


Reply



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 04:51 PM
Help with Gettext Snouser Linux - Software 2 03-02-2006 11:41 PM
php 5.0.5 and gettext ziggie216 Linux - Software 0 11-10-2005 02:26 PM
php + gettext Ateo Linux - General 0 11-09-2005 11:40 AM
exec bash scripts from Glade/GTK? HELP! cho Programming 1 07-04-2005 08:01 AM

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

All times are GMT -5. The time now is 08:26 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
Open Source Consulting | Domain Registration