[code]
- <?php
- /***************************************************************************
- /*
- /* FileName :: translate.php
- /* Author :: Adrian Morgan
- /* Description :: Using some assocciative arrays to create a translation
- /* :: page. Shows how to access array elements using a
- /* :: posted variable.
- /* ::
- /* DateModified :: 22/04/2004
- /*
- /* FurtherComments :: Shows how to pass a reference to a function to affect
- /* :: global variables. This program could be tackled more
- /* :: effectively using a database i.e. MySQL
- /*
- /***************************************************************************/
- //
- //-- Create some arrays -- $word[][] for single words -- $phrase[][] for common phrases -- $text[][] for paragraphs or whole items.
- //
- $word['Help']=array('En'=>'Help', 'Us'=>'Help', 'Es'=>'Ayuda', 'Fr'=>'Aide', 'De'=>'Hilfe', 'Ru'=>'Помощь');
- $word['Submit']=array('En'=>'Submit', 'Us'=>'Submit', 'Es'=>'Rendir', 'Fr'=>'Soumettez', 'De'=>'Gehorchen', 'Ru'=>'Подчинитесь');
- $phrase['Cat On Mat']=array('En'=>'The cat sat on the colourful mat!',
- 'Us'=>'The cat sat on the colorful mat!',
- 'Es'=>'El gato se sentó sobre la estera colorida',
- 'Fr'=>'Le chat s`est assis sur le tapis coloré',
- 'De'=>'Die Katze saß auf der bunten Matte',
- 'Ru'=>'Кот сидел на красочной циновке');
- $phrase['Click for help']=array('En'=>'Click<a href="#"> here </a>for '.$word['Help']['En'],
- 'Us'=>'Click<a href="#"> this </a>to get'.$word['Help']['Us'],
- 'Es'=>'Chasquido<a href="#"> aquí </a>para'.$word['Help']['Es'],
- 'Fr'=>'Cliqueter<a href="#"> ici </a>pour'.$word['Help']['Fr'],
- 'De'=>'Klicken<a href="#"> Sie hier </a>dafür'.$word['Help']['De'],
- 'Ru'=>'Щелкните<a href="#"> здесь </a>для'.$word['Help']['Ru']);
- $text['Disclaimer']=array( 'En'=>'<h1>Disclaimer</h1>This code example will<ol><li>work properly</li>
- <li>give you a starting point</li>
- <li>not make your hair grow</li>
- <li>not pay the mortgage</li></ol>',
- 'Us'=>'<h1>Disclaimer</h1>This code example will<ol><li>execute correctly</li>
- <li>get you started</li>
- <li>not stimulate hair growth</li>
- <li>not keep up your repayments</li></ol>',
- 'Es'=>'<h1>Mentís</h1>Este ejemplo de código va a<ol><li>trabajo correctamente</li>
- <li>déle un punto de partida</li>
- <li>no hacen su pelo crecer</li>
- <li>no pagan la hipoteca</li></ol>',
- 'Fr'=>'<h1>Refus</h1>Cet exemple de code fera<ol><li>Travailler convenablement</li>
- <li>Vous donner un point de départ</li>
- <li>Ne pas faire vos cheveux grandissent</li>
- <li>Ne pas payer l`hypothèque</li></ol>',
- 'De'=>'<h1>Verzichterklärung</h1>Dieses Codebeispiel<ol><li>Arbeit richtig</li>
- <li>geben Sie Ihnen einen Startpunkt</li>
- <li>nicht lassen Ihr Haar wachsen</li>
- <li>nicht bezahlen die Hypothek</li></ol>',
- 'Ru'=>'<h1>Правовая оговорка</h1>Этот кодовый пример будет<ol><li>работа должным образом</li>
- <li>дайте Вам отправную точку</li>
- <li>не заставляют ваши волосы расти</li>
- <li>не платят заклад</li></ol>');
- $text['Licence']=array( 'En'=>'<h1>Licence</h1>Use this code freely, the translations may be inaccurate, but it makes a useful learning tool!',
- 'Us'=>'<h1>License</h1>Use this code uninhibited, the translations may not be accurate, but it makes a useful learning tool!',
- 'Es'=>'<h1>Licencia</h1>!Use este código libremente, las traducciones pueden ser inexactas, pero hace un instrumento de aprendizaje útil!',
- 'Fr'=>'<h1>Permis</h1>Utiliser ce code librement, les traductions peuvent être inexactes, mais il fait un outil d`érudition utile!',
- 'De'=>'<h1>Lizenz</h1>Gebrauchen Sie diesen Code frei, die Übersetzungen können ungenau sein, aber es macht ein nützliches Lernwerkzeug!',
- 'Ru'=>'<h1>Лицензия</h1>Используйте этот кодекс свободно, переводы могут быть неточны, но это делает полезный инструмент изучения!');
- //
- //-- End of array definitions
- //
- //
- //-- Create page content -- Write a form to change the language settings
- //
- //
- //-- Check whether this is first visit or whether language has been changed
- //
- if(isset($language)) // The user has visited & changed the original language.
- {
- $submit = $word['Submit'][$language];
- write_form($submit); // write_form accepts a reference to $submit.
- print $phrase['Cat On Mat'][$language]."/n<br /><br />/n";
- print $text['Disclaimer'][$language];
- print $text['Licence'][$language]."<br /><br />";
- print $phrase['Click for help'][$language];
- }
- else
- {
- $language = "En"; // Set the default language for the first visit to the page.
- $submit = $word['Submit'][$language];
- write_form($submit); // write_form accepts a reference to $submit.
- print $phrase['Cat On Mat'][$language]."/n<br /><br />/n";
- print $text['Disclaimer'][$language];
- print $text['Licence'][$language]."<br /><br />";
- print $phrase['Click for help'][$language];
- }
- function write_form(&$sub) // Accept a reference (denoted by [&]) to a var as the argument.
- {
- print "<form method=/"post/">/n";
- print "<select name=/"language/">/n";
- print "<option>En</option>/n";
- print "<option>Us</option>/n";
- print "<option>Es</option>/n";
- print "<option>Fr</option>/n";
- print "<option>De</option>/n";
- print "<option>Ru</option>/n";
- print "</select>/n";
- print "<input type='submit' value=/"$sub/">/n";
- print "</form>/n";
- }
- ?> [/code]