Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does gettext translate an empty string to the .po header text?

Tags:

php

gettext

I've got gettext setup within PHP5. After some struggling with the charactersets and the like, I've managed to translate some basic strings. Now I've ran into a problem. When translating an empty string I expect to get the untranslated (empty) string back (correct me if I'm wrong ;)).

However instead of returning the input string, I get the header of the .PO file as the translation:

Project-Id-Version: PACKAGE VERSION Report-Msgid-Bugs-To: POT-Creation-Date: 2011-09-22 15:03+0200 PO-Revision-Date: 2011-09-22 15:37+0200 Last-Translator: timo Language-Team: English Language: en MIME-Version: 1.0 Content-Type: text/plain; charset=ASCII Content-Transfer-Encoding: 8bit Plural-Forms: nplurals=2; plural=(n != 1); 

When I look in the .mo file with a text-editor I see that the header seems to placed at a random place within the file. I would like to show you, but I can't paste the file in. It looks like there is a list of my msgid's, then the header and then a list of my msgstr's

I've used the following command to generate the .mo file:

msgfmt -c -v -o en/LC_MESSAGES/messages.mo messages_en.po

After this command I've restarted my webserver (lighttpd).

What did I do wrong and how can I fix it?

like image 216
Timo Avatar asked Sep 30 '11 12:09

Timo


People also ask

What is .po format?

A . PO file is a portable object file, which is text-based. These types of files are used in commonly in software development. The . PO file may be referenced by Java programs, GNU gettext, or other software programs as a properties file.

What is use of gettext in PHP?

The gettext module in PHP only supports languages and language identifiers that are installed on your server. on the command line of your server (e.g., by logging in with SSH). The command may require admin privileges and maybe not work on a hosted shared server.

Is gettext a function?

The gettext function searches the currently selected message catalogs for a string which is equal to msgid . If there is such a string available it is returned. Otherwise the argument string msgid is returned.

How do you comment in a .po file?

Outside strings, white lines and comments may be used freely. Comments start at the beginning of a line with ' # ' and extend until the end of the PO file line. Comments written by translators should have the initial ' # ' immediately followed by some white space.


1 Answers

After searching around with some different queries I stumbled upon this site: http://framework.zend.com/issues/browse/ZF-2914

Here I found that the translation of the empty string to meta information is actually in the specifications of gettext:

This also has another advantage, as the empty string in a PO file GNU gettext is usually translated into some system information attached to that particular MO file, and the empty string necessarily becomes the first in both the original and translated tables, making the system information very easy to find.

like image 148
Timo Avatar answered Sep 23 '22 13:09

Timo