Sunday, March 24, 2013

Making a Multilingual Web Site with PHP

Some have the perception that the only language is English but that idea disappears quickly after a few minutes in Europe and it becomes clear that many Europeans have some understanding of English but few are fully-conversant in it.

There are various options for providing multilingual support in a Web page and this documentation is offered with the thinking that there is peace in understanding each other.  Nur in Stille sind wir besiegt.

Note that there is no emphasis on Facebook search as performance is irrelevant in that context, the only thing that works to boost a listing within that mercenary piece of crap is money.


Ugly - The Easiest:

As with this blog, put out a button it that connects to Google Translate and let it do the work.

Pros:  It's easy
Cons:  It's ugly and many features of your Web site may not work as a result of using it


Bad - The Medium Solution:

In this solution, your index page will have a set of flags that link to alternative language streams.  For example, index.php links to index-ger.php, index-fra.php, etc.  Those streams in turn link to parallel pages written in the appropriate languages.

Pros:   It's effective and presents well
Cons:  It's very poor in terms of Google search as a single page will climb much higher than a master and its clones.


Good - The In-Stream Solution:

Use a single page with in-stream switching to present the various languages.  This assumes your page receives a link in the following format:  <a href="/mypage.php?lang=ger">My Page</a> and if 'lang' is not specified then English is assumed.

Pros:  It's effective, presents well, and climbs the highest in Google Search

Cons:
  • The coding is more difficult
  • It doesn't solve the problem of doing everything as many times as you have languages to present (i.e. it's not dynamically translating anything)

Programming example:

Note the use of included code which is written in the various languages and also the use of 'echo' to write the different languages in-stream.  The latter approach should be used minimally as readability will be significantly degraded if it is used too much and there is also a performance penalty in doing that.


<?php
$language = $_GET['lang'];
if (!$language or $language == "eng") {
require("/home/katakolo/public_html/includes/buttons.html");
echo "<h3 style=\"margin-bottom:10px;\">Instructions</h3>";
        ...
";

}
elseif ($language == "ger") {
require("/home/katakolo/public_html/includes/buttons-ger.html");
echo "<h3 style=\"margin-bottom:10px;\">Anleitung</h3>";
        ...
";

}


elseif ($language == "fra") {
require("/home/katakolo/public_html/includes/buttons-fra.html");
echo "<h3 style=\"margin-bottom:10px;\">Instructions</h3>";
        ...
";

}


elseif ($language == "gre") {
require("/home/katakolo/public_html/includes/buttons-gre.html");
echo "<h3 style=\"margin-bottom:10px;\">Οδηγίες</h3>";
        ...
";

}



et cetera

No comments: