Reputation: 2332
i'm working on my own way of handling a bilingual site. my method should allow proper search engine indexing and will keep everything on one page without external files.
one function would handle which content to display:
<?
function l($en, $fr){
echo ($_GET['lang'] === 'fr') ? $fr : $en ;
}
?>
then the appropriate text will display according to language in URL (/?lang=en)
<h1><? l('welcome!', 'bienvenue!') ?></h1>
for an image this is my solution:
<img src="<? l('hi-en.png', 'hi-fr.png')?>" width="100" height="20">
can anyone name drawbacks to this method if used? is it unusual to have a single function handle language for pages which would include all language content?
Upvotes: 1
Views: 138
Reputation: 10901
The general idea of using a singleton or global function like your l
function is very common. You're definitely on the right track!
Your method does have some drawbacks, though:
A more typical solution is to have the translations located in a separate file, either as a simple hash or as a structured data format like XML, and then your l
function would just look like l('welcome')
; the parameter is a key, and l
will look up the correct translation in the given language from the separate file.
Upvotes: 1