Re: Now available: AJAX/PHP multilingual website templates
Posted: Thu 24 Mar 2011 8:27 pm
It's not necessary to add these terms to the language-LL text files .. there is already a method to do this using a bit of code from the wxastronomy.php page. First, a clarification is needed... the Settings.phpgemini06720 wrote:Ron, you can add terms/expressions into your templates (with the 'langtrans()' or the 'langtransstr()' functions) and add the same terms/expressions into your 'language-nl.txt' (with the proper dutch translation) and the terms/expressions will be properly translated/displayed onto your web pages...nitrx wrote:Thanks Ray I've a look at your solution.
Code: Select all
// if your software uploads almanac dates using a language OTHER THAN English, please put the month
// names in your language to replace the English ones below. This is used primarily by the
// wxastronomy.php page for the local dates of moon phases, solistices, and equinoxes
$SITE['monthNames'] = array( // for wxastronomy page .. replace with month names in your language
'January','February','March','April','May','June',
'July','August','September','October','November','December'
);
// example:
//$SITE['monthNames'] = array( // Danish for wxastronomy page .. replace with month names in your language
//'januar','februar','marts','april','maj','juni',
//'juli','august','september','oktober','november','december'
//);
Code: Select all
function get_localdate ( $indate) {
global $SITE;
$EnglishMonths = array(
'January','February','March','April','May','June',
'July','August','September','October','November','December');
// Change '02:33 UTC 4 September 2007' to
// specified date by
$timeFormat = 'D, d-M-Y h:ia T'; // Fri, 31-Mar-2006 14:03 TZone
// $timeFormat = 'h:ia T D, d-M-Y '; // Fri, 31-Mar-2006 14:03 TZone
if(isset($SITE['timeFormat'])) { $timeFormat = $SITE['timeFormat']; }
$utcstr = substr($indate,10) . " " . substr($indate,0,9); // move formats
echo "<!-- input utcstr='$utcstr' -->\n";
// input dates are assumed to be in English only
if (isset($SITE['monthNames'])) {
// convert TO English for strtotime()
echo "<!-- before utcstr='$utcstr' -->\n";
foreach ($EnglishMonths as $i => $monthEN) {
$utcstr = preg_replace('|'.$SITE['monthNames'][$i].'|i',$monthEN,$utcstr);
}
echo "<!-- after utcstr='$utcstr' -->\n";
}
$utc = strtotime($utcstr);
$lclstr = date($timeFormat,$utc);
if (isset($SITE['langMonths'])) {
// convert From English for return (will only work if long-format month names in $timeFormat)
echo "<!-- before lclstr='$lclstr' -->\n";
foreach ($EnglishMonths as $i => $monthEN) {
$lclstr = preg_replace('|'.$monthEN.'|i',$SITE['langMonths'][$i],$lclstr);
}
echo "<!-- after lclstr='$lclstr' -->\n";
}
return ($lclstr);
}
You could add langtrans entries automatically by doing something like
Code: Select all
global $SITE,$LANGLOOKUP;
$EnglishMonths = array(
'January','February','March','April','May','June',
'July','August','September','October','November','December');
if (isset($SITE['langMonths'])) {
foreach ($EnglishMonths as $i => $monthEN) {
$LANGLOOKUP[$monthEN] = $SITE[langMonths][$i];
}
}
There's a similar feature for other $SITE['lang...'] values like this example for French
Run any page with ?debug=y and see this in the view-source.<!-- loading language-fr.js -->
<!-- langMonths='Array
(
[0] => janvier
[1] => février
[2] => mars
[3] => avril
[4] => mai
[5] => juin
[6] => juillet
[7] => août
[8] => septembre
[9] => octobre
[10] => novembre
[11] => décembre
)
-->
<!-- langDays='Array
(
[0] => dim
[1] => lun
[2] => mar
[3] => mer
[4] => jeu
[5] => ven
[6] => sam
[7] => dim
)
-->
<!-- langUVWords='Array
(
[0] => aucun
[1] => faible
[2] => moyen
[3] => élevé
[4] => très élevé
[5] => extrême
)
-->
<!-- langBaroTrend='Array
(
[0] => Soutenu
[1] => Monte lentement
[2] => Monte rapidment
[3] => Tombe lentement
[4] => Tombe rapidement
)
-->
<!-- langBeaufort='Array
(
[0] => calme
[1] => très légère brise
[2] => légère brise
[3] => petite brise
[4] => jolie brise
[5] => bonne brise
[6] => vent frais
[7] => grand frais
[8] => coup de vent
[9] => fort coup de vent
[10] => tempête
[11] => violente tempête
[12] => ouragan
)
-->
<!-- langHeatWords='Array
(
[0] => inconnu
[1] => extrême danger de chaleur
[2] => danger de chaleur
[3] => fort risque de chaleur
[4] => extrêmement chaud
[5] => inconfortablement chaud
[6] => chaud
[7] => modérément chaud
[8] => confortable
[9] => frais
[10] => froid
[11] => inconfortablement froid
[12] => très froid
[13] => extrêmement froid
)
-->
<!-- langWindDir='Array
(
[0] => N
[1] => NNE
[2] => NE
[3] => ENE
[4] => E
[5] => ESE
[6] => SE
[7] => SSE
[8] => S
[9] => SSO
[10] => SO
[11] => OSO
[12] => O
[13] => ONO
[14] => NO
[15] => NNO
)
-->
<!-- load_langtrans finished -->
Hope this helps...
Best regards,
Ken