[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Using gettext in scripts

On Thu, Dec 13, 2001 at 12:05:44PM +0100, Javier Fdz-Sanguino Pen~a wrote:
> On Thu, Dec 13, 2001 at 02:58:52AM -0200, Gustavo Noronha Silva wrote:
> > Hello,
> > 
> > maybe someone here can point me to some good manual on how to
> > use gettext on shell scripts?
> > 
> 	Ussing gettext is easy. Check out the euro-support's euro-test
> script which uses gettext (and I did not have the least idea how to do it
> before I implemented it). Just call in the shell script:
> gettext "my message"
> after defining the domain for gettext.

That's the sh (inefficient) way. In bash, you can use the following shorthand:
$"My message"

> Gettext extraction is not that difficult, I hacked a perl script in ~5 min
> which would make the neccessary .pot for translation. It's in the sources
> but is quite simple:
> #!/usr/bin/perl -n
> $count++;
> if (/gettext.*?"(.*?)"/ ) {
>         print "#at line $count\nmsgid \"$1\"\nmsgstr \"\"\n";
> }
> Just do 'cat file.sh | perl script' 

Why not use the -D option of bash, or the --dump-po-strings one ?

>From bash man page:

       -D        A  list of all double-quoted strings preceded by
                 $ is printed on the standard ouput.   These  are
		 the  strings that are subject to language trans­
                 lation when the  current  locale  is  not  C  or
		 POSIX.   This implies the -n option; no commands
		 will be executed.
                 Equivalent to -D, but the output is in the GNU get­
		 text po (portable object) file format.
		 Equivalent to -D.
       A double-quoted string preceded by a dollar sign ($)  will
       cause the string to be translated according to the current
       locale.  If the current locale is C or POSIX,  the  dollar
       sign   is  ignored.   If  the  string  is translated  and
       replaced, the replacement is double-quoted.
              This  variable determines the locale used to trans­
	      late double-quoted strings preceded by a $.
And so on.
Bye, Mt.

Un clavier azerty en vaut deux.

Reply to: