[PHPTAL] Getting error on i18n:translate=""

Laurent Bedubourg laurent at motion-twin.com
Sun Apr 1 19:43:36 CEST 2007


On Sat, 31 Mar 2007 23:38:25 +0200
ATEC Admin <admin at atec-at.sk> wrote:

> Hello,
> 
> I am trying to translate non-English web site using gettext and 
> i18n:translate attribute, but I keep getting unexpected results.
> 
> In the template I have this code:
> 
> <p i18n:translate="">O nás</p>
> 
> which should generate gettext msgid equal to 'O nás', the content of
> the tag. Instead, PHPTAL generates msgid='O nC<195>C<161>s'.
> 

Hello Juraj, 

I remember having problems with gettext tools. They did not allow
non-ascii msgid at the time this PHPTAL feature was developed.  

Two years have passed since that time and maybe gettext is now able to
compile and understand UTF-8 msgid ? From the Gettext manual :

       The msgid argument identifies the message to be translated. By
convention, it is the English version of the  message,  with
non-ASCII  characters replaced by ASCII approximations. This choice
allows the translators to work with message catalogs, called PO files,
that contain both the English and the translated versions of each
message, and can be installed using the msgfmt utility.

Could you test the following for me ? 

Edit the PHPTAL/Php/Attribute/I18N/Translate.php file, 

Modify the _canonalizeKey() static method into something like :

static function _canonalizeKey($key){
	$key = str_replace("\r\n", "\n", $key);
	$key = str_replace("\r", "\n", $key);
	$key = str_replace("\n", " ", $key);
	$key = trim($key);
	return $key;
}

And tell me if the gettext tool suite is working with UTF-8 or not :)


In case it doesn't work, you will certainly find the following tools useful :

https://svn.motion-twin.com/phptal/phptal_i18n/trunk/cpp/

They are C++ tools I wrote to extract PHPTAL templates i18n strings,
generate gettext .po files and then inject back translations into
templates (in a different template directory).

The idea behind this is that translation should be done once and only
once.

Say your project have a main 'tpl' directory containing templates with
i18n attributes.

* i18n-extract will look into this directory and generate a .pot files
* i18n-merge will merge .pot modifications into per language .po files
* i18n-todo will tell you what has to be translated into .po file (msgid
== msgstr) 
* i18n-build will generate a tpl_es directory using your main
tpl directory and a .po file

After translations, you end with 'tpl_es', 'tpl_en', 'tpl_fr', etc...
directories.

Put everything on line and when a user wants another language just
point your PHPTAL repository to the correct directory.

These tools does not requires gettext and are plain C++ code, they
compile (at least) on linux / windows(cygwin). I used them for some
projects and they just work like I wanted them to work. May be a bit
tricky to set up when you are not used to the tools.

Here's a sample Makefile :

update-po:
	# find *ml files and tell i18n-extract to look for i18n
	# attributes inside 
	/usr/bin/find tpl -name "*.*ml" | i18n-extract -o locales/project.pot 
	# merge .pot with .po 
	i18n-merge -b locales/project.pot locales/project.fr.po
	i18n-merge -b locales/project.pot locales/project.en.po
	i18n-merge -b locales/project.pot locales/project.es.po

build-templates:
        /usr/bin/find tpl -name "*.*ml" | xargs i18n-build -v -r tpl -d tpl_fr -po locales/project.fr.po 
	/usr/bin/find tpl -name "*.*ml" | xargs i18n-build -v -r tpl -d tpl_en -po locales/project.en.po
	/usr/bin/find tpl -name "*.*ml" | xargs i18n-build -v -r tpl -d tpl_es -po locales/project.es.po

As shown above you just have to take care of your tpl and locales
directories, other tpl_* directory are generated by i18n-build.

i18n-build is gentle so if you want to really customize a template for
a target language you can have, for instance, tpl/news.html and
tpl/news.html.fr

Best regards
Laurent
-- 
Laurent Bedubourg
lbedubourg at motion-twin.com
http://www.motion-twin.com



More information about the PHPTAL mailing list