Using gettext for multiple languages
Posted: Fri Apr 27, 2012 2:34 pm
Good evening friends!
I am completely new to this forum as you can see. Up to now I have tried my best to figure things out myself and use Google. But I have hit a brick wall
this time because for the life of me I cannot find a solution to my problem. The problem is I dont even know where to start.
Ok my vision ! ..............
When you visit a website you may in in the top right corner a dropdown box to select your preferred language. I only want two for mine and thats English and German.
Now I am currently testing php-gettext and it is very easy to use so I think I will stick with it. I have started building my strings already so that part is fine. Here is the code I have so far:
test.php
local.php
My question is:
How do I implement this as a sitewide solution where the user can choose their language?
How do I have it set a default language?
I hope I am making sense but if you need any clarification then just let me know.
I am completely new to this forum as you can see. Up to now I have tried my best to figure things out myself and use Google. But I have hit a brick wall
Ok my vision ! ..............
When you visit a website you may in in the top right corner a dropdown box to select your preferred language. I only want two for mine and thats English and German.
Now I am currently testing php-gettext and it is very easy to use so I think I will stick with it. I have started building my strings already
Code: Select all
<?php echo _(hello world); ?>test.php
Code: Select all
<?php
include("local.php"); ?>
<html>
<head lang="en" >
</head>
<body>
<div id="navbar"><div class="langbar"><a href="?lang=en_GB">English</a> | <a href="?lang=de_DE">Deutsch</a> |
<br />
<?php echo gettext("Welcome to My PHP Application");
echo "<br />";
// Or use the alias _() for gettext()
echo _("Have a nice day");
echo $_SERVER['HTTP_ACCEPT_LANGUAGE'];
?>
</body>
</html>
Code: Select all
<?php
$directory = dirname(__FILE__).'/locale';
$domain = 'messages';
$locale ="de_DE.utf8";
//$locale ="en_GB.utf8";
setlocale( LC_MESSAGES, $locale);
bindtextdomain($domain, $directory);
textdomain($domain);
bind_textdomain_codeset($domain, 'iso-8859-1');
?>How do I implement this as a sitewide solution where the user can choose their language?
How do I have it set a default language?
I hope I am making sense but if you need any clarification then just let me know.