Using PHP Gettext Extension vs PHP Arrays in Multilingual Websites?

Posted by janoChen on Stack Overflow See other posts from Stack Overflow or by janoChen
Published on 2010-02-23T14:58:20Z Indexed on 2010/03/25 9:03 UTC
Read the original article Hit count: 555

Filed under:
|
|
|

So far the only 2 good things that I've seen about using gettext instead of arrays is that I don't have to create the "greeting" "sub-array" (or whatever its called). And I don't have to create a folder for the "default language".

Are there other pros and cos of using gettext and php arrays for multilingual websites?

USING GETTEXT:

spanish/messages.po:

#: test.php:3
msgid "Hello World!"
msgstr "Hola Mundo"

index.php:

<?php echo _("Hello World!"); ?>

index.php?lang=spanish:

<?php echo _("Hello World!"); ?> turns to Hola Mundo

USING PHP ARRAYS:

lang.en.php

<?php
$lang = array(
    "greeting" => "Hello World",
);
?>

lang.es.php

<?php
$lang = array(
    "greeting" => "Hola Mundo",
);
?>

index.php:

<?php echo $lang['greeting']; ?> greeting turns to Hello World

index.php?lang=spanish

<?php echo $lang['greeting']; ?> greeting turns to Hola Mundo

(I first started with gettext, but it wasn't supported in my shared free hosting Zymic. I didn't want to use Zend_translate, I found it too complicated to my simple task, so I finally ended up using php define, but later on someone told me I should use arrays)

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays