PHP+gettext (was Re: My stab at the templates)



Shawn T Amundson wrote:
> I know PHP has been stated time and time again as the preferred
> choice, but I must point out that it really doesn't look too
> maintainable when you start to discuss serious themability and
> especially multi-lingual sites.
> 
> My solution to this problem:
> 
>   http://www.eventloop.com/fabric/
> 
> It works extremely well in the theme and multi-lingual areas.  And
> there is *total* seperation between code and templates, which makes
> it really easy to let translators edit text without the need for
> digging through code or other methodologies.

I haven't checked your solution, but I hope "digging through code"
wasn't a seriously considered approach for translations and maintaining
translations anyway. :)

I always thought about using gettext() in PHP - PHP has support for
thisą (http://www.php.net/manual/en/function.gettext.php) and gettext is
the translation system used in the rest of GNOME - thus, GNOME
translators can re-use dictionaries, statistics tools, and all other
tools when translating the web site, and maintaining the translation
will be just like maintaining any other GNOME translation. This has *so*
many advantages other any other system - if we can use this, it will
rock.

A slightly modified example from the php gettext page:

<?php
// the following will be common for every page and could be put in a
// common inclusion file.

// Set language to German. This would obviously be handled by
// a system for choosing language and/or using the one the
// browser supplies.
putenv ("LANG=de");
// use all the locale variables. This can be used for printing numbers
// correctly (decimal points/commas) and so on.
setlocale(LC_ALL, "");
// Specify location of translation tables
bindtextdomain ("gnomeweb",
"./path-to-where-the-language-catalogs-are");
// Choose domain
textdomain ("gnomeweb");

// This is how translations will be used in the pages. _() is a shortcut
// for gettext() and will show the translated message.
echo _("Welcome to Gnome Web")."<BR>";
echo _("This should all be translated. If you see this message in the
	language you entered, it works");
?>

That should be it. Whenever you add new content to the site, you only
have to put strings that you will show inside _() and it should work.

Granted, I haven't tested that gettext in php works. If anyone wants
something to do... If you want help, just ask. Or I'll have to wait
until I have the time to test this... :(


Christian




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