Latest

Archive

Community news

C++

Communities and Content

Databases

Editorials

Emacs

General

HTML

Java

Notices

PHP

XML

Apache

C++

Database

General

HTML

Java

Javascript

Linux

Object oriented programming

Open source

Perl

PHP

Python

Ruby

SOAP

XML

Suggest a link

Advertise on zez

Contribute

Contact us

About zez


Internationalization Using PHP and GetText



Extracting Strings from the Code


Gettext provides a utility called 'xgettext' to extract all the strings from your scripts to a file called a "po" file, you have to use:


 
  $xgettext -a src/*.php 



To extract all the strings. Read the GNU's documentation for 'xgettext' for more options . After xgettexting your code you will have a 'messages.po' file which may look like this one:


 
# SOME DESCRIPTIVE TITLE. 
# Copyright (C) YEAR Free Software Foundation, Inc. 
# FIRST AUTHOR , YEAR. 
# 
#, fuzzy 
msgid "" 
msgstr "" 
"Project-Id-Version: PACKAGE VERSION\n" 
"POT-Creation-Date: 2000-12-08 19:15-0300\n" 
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 
"Last-Translator: FULL NAME \n" 
"Language-Team: LANGUAGE \n" 
"MIME-Version: 1.0\n" 
"Content-Type: text/plain; charset=CHARSET\n" 
"Content-Transfer-Encoding: ENCODING\n" 

#: prueba.php:12 
msgid "Hello world" 
msgstr "" 

#: prueba.php:12 prueba.php:13 
msgid "
" msgstr "" #: prueba.php:13 msgid "This is a test" msgstr ""



This will be the file that you have to pass to translators, they will have to set msgstr for each entry to the proper translation of the string for the target language. You can add comments (using #comment) for each entry to provide context if needed such as:


 
#: prueba.php:12 
# This is displayed at the beginning of the script 
msgid "Hello world" 
msgstr "" 



Etc, after this you have a "master" po file where all the msgstr strings are "". Using gettext on a string that is not translated will simply output the msgid. This is a good feature.

Once translators have translated the 'messages.po' file, you'll have several files for different languages. It is time yo use them from PHP.


<< Previous page | 1 | < 2 > | 3 | Next page >> | Printer-friendly page |

Comment List


Topic: Author:
Time:
internationalization using GETTEXT Suma Abey 13.07.2007 13:13

explain the stepwise procedure to install gettext in windows/mysql platform


Use gettext in windowsXP Hitesh Kanjaria 30.01.2006 08:18

Hi,
Can you explain me how to use gettext in window os.
Or any tutorial for that.


mo error jase dixon 21.10.2002 14:49

when i compile the po file to convert it into an mo file i get this error msg

"the character set has no portable coded name"

however the mo file is still created but when i run the php file no translation takes place . Does anyone know what this type of error is?

thanks in advance

jas


   RE: mo error ota fred 05.06.2003 12:56

Hello, I have the same problem.

Can you tell me if you have resolved it, and how.

Thanks


> when i compile the po file to convert it into an mo file i
> get this error msg
>
> "the character set has no portable coded name"
>
> however the mo file is still created but when i run the php
> file no translation takes place . Does anyone know what this
> type of error is?
>
> thanks in advance
>
> jas


xgettext Rakesh Shroingi 30.04.2002 14:31

xgettext -a langtest.php

While using xgettext i am getting the following error.

warning: file `langtest.php' extension `php' is unknown; will try C

My php is having the gettext option enabled.

Please help.
Thanks


   RE: xgettext Jose Cortina 07.06.2002 09:51

I had the same problem, and finally found the way out... Try with:

xgettext -C script.php -o messages.po --keyword=_

(The keyword "_" is because I use the short form of gettext in php _("My Text") instead of gettext("My Text") )

If you don't specify the keyword, then it will get *all* strings from your script... (it gets messy)

Hope this helps.


gettext and here docs? Colin Viebrock 31.07.2001 00:45

Imagine this php script:

<?php

echo _( <<< EOF
It's a great day!
EOF
);

?>

When I run "xgettext file.php" on it, I get warnings about "unterminated character constant" ... which I assume is the single quote in "it's".

Is there a way around this?

Also, how do I tell xgettext to only look for strings inside _( ... ) blocks?

- Colin


How to produce .mo file harvail singh 05.03.2001 06:31

What ia m doing is
After writng .php file i
run xgettext -a command to get the po file
After this i run i msgfmt file.po -o fil1.mo
but this command is not producing .mo
file

any help will be appreciated


Common problem Luis Argerich 26.01.2001 16:50

If you get that message you don't have the gettext extension compiled into php, add the following string...

--with-gettext

To your configuration script or ./configure command line.

Luis.


   RE: Common problem W L 01.11.2001 12:13

> If you get that message you don't have the gettext extension
> compiled into php, add the following string...
>
> --with-gettext
>
> To your configuration script or ./configure command line.
>
> Luis.

So does that mean we enter the following code in command prompt?

./configure --with-gettext

coz I did that and it still doesn't work.


Hmmm Urban Weigl 14.12.2000 21:38

I don't think I'm sure I know what you mean... ?


   RE: Hmmm Paul Kenneth Egell-Johnsen 15.12.2000 11:28

The problem with that is that I don't have any idea at all with what your problem might be:)

I'd love to help out (and probably Luis as well), but you need to be much more specific in describing what you have problem with understanding.

I'm looking forward to that clarification and the opportunity to help you.


     RE: Hmmm W L 07.11.2001 04:54

> The problem with that is that I don't have any idea at all
> with what your problem might be:)
>
> I'd love to help out (and probably Luis as well), but you
> need to be much more specific in describing what you have
> problem with understanding.
>
> I'm looking forward to that clarification and the
> opportunity to help you.

I have PHP installed but it's pointing gettext=/usr

how do i change that to gettext=/usr/bin?

What do I have to type in the command prompt?


       RE: Hmmm nobody important 29.08.2007 00:14

> > The problem with that is that I don't have any idea at
> all
> > with what your problem might be:)
> >
> > I'd love to help out (and probably Luis as well), but
> you
> > need to be much more specific in describing what you
> have
> > problem with understanding.
> >
> > I'm looking forward to that clarification and the
> > opportunity to help you.
>
> I have PHP installed but it's pointing gettext=/usr
>
> how do i change that to gettext=/usr/bin?
>
> What do I have to type in the command prompt?

I just compiled the so file
./configure --with-gettext=shared

and then copied the .so file in

$PHP_BUILD_DIR/modules/gettext.so

to the folder pointed at in the line

extensions_dir=/some/dir

in php.ini (on my machine it was /usr/local/lib/php/modules), and then added the following line to php.ini

extension=gettext.so

Pretty much the same thing for every shared library I didn't compile when I first compiled PHP.

Just make sure that the version you're building from is the same as your current PHP build.


     harvail singh 02.01.2001 07:17

hi
I ahve a problem Using gettext() or its alias _
It gives error
Call to undefined function: gettext() in /home/httpd/html/testing/hello.php on line 10


I am using php 4.0.3pl1

can u help
thanx




Forgot your password?

Register a new user

Results

Polls