Client localisation with zend framework

Martin Zellerphp Leave a Comment

If you want to find out the language or country of the clients browser, do it this way:
[php]<?php
require_once ‘Zend/Locale.php’;
$locale = new Zend_Locale();
echo $locale->toString();
?>[/php] But be aware! This way you only get the localisation of the clients browser. And this is configurable by the user.

The code above will give you output like this:
[text]de_AT[/text] or
[text]en_US[/text] There are many methods you can use with zend localisation:
[php]<?php echo $locale->toString() ?>
<?php echo $locale->getLanguage() ?>
<?php echo $locale->getRegion() ?>
<?php print_r($locale->getBrowser()); // Return an array of all accepted languages of the client ?>[/php] Example output:
[text]de_AT
de
AT
Array ( [de_AT] => 1 [de] => 1 [de_DE] => 0.8 [en_GB] => 0.5 [en] => 0.5 [en_US] => 0.3 )[/text] Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.