CS174
Chris Pollett
April 27, 2016
For small projects, one quick and easy way to support multiple languages is an array-based approach. You have an array:
$tl = [ "locale1" => [ "msg_id" => "translation" ], "locale2" => [ ], ];
Your PHP script determines the locale of the client by looking at the Accept-Language header to determine the most preferred locale, $locale. In views, when there is text that needs to be translated, we have inclusions like: <?= $tl[$locale]['string_to_translate']; ?>.
Test this strategy out, by writing a short PHP program which detects the locale and uses an array like the above to either output "Hello" in English or "Hello" in one of the other languages you have translated this word for.
Post your solutions to the April 27 Class Thread.
Content-Type: text/html; charset=utf-8
AddCharset UTF-8 .php
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
<p style="direction:rtl; unicode-bidi: bidi-override; text-align: right" ><bdo dir="rtl" > This is a test.</bdo></p>would look like:
This is a test.