translate.php - Assocciative array example, passing a reference to a function

[code]
  1. <?php
  2. /***************************************************************************
  3. /*
  4. /* FileName            ::    translate.php
  5. /* Author            ::    Adrian Morgan
  6. /* Description        ::    Using some assocciative arrays to create a translation
  7. /*                    ::    page. Shows how to access array elements using a
  8. /*                    ::    posted variable.
  9. /*                    ::
  10. /* DateModified        ::    22/04/2004
  11. /*
  12. /* FurtherComments    ::    Shows how to pass a reference to a function to affect
  13. /*                    ::    global variables. This program could be tackled more
  14. /*                    ::    effectively using a database i.e. MySQL
  15. /*
  16. /***************************************************************************/
  17.  
  18. //
  19. //-- Create some arrays -- $word[][] for single words -- $phrase[][] for common phrases -- $text[][] for paragraphs or whole items.
  20. //
  21. $word['Help']=array('En'=>'Help', 'Us'=>'Help', 'Es'=>'Ayuda', 'Fr'=>'Aide', 'De'=>'Hilfe', 'Ru'=>'&#1055;&#1086;&#1084;&#1086;&#1097;&#1100;');
  22. $word['Submit']=array('En'=>'Submit', 'Us'=>'Submit', 'Es'=>'Rendir', 'Fr'=>'Soumettez', 'De'=>'Gehorchen', 'Ru'=>'&#1055;&#1086;&#1076;&#1095;&#1080;&#1085;&#1080;&#1090;&#1077;&#1089;&#1100;');
  23. $phrase['Cat On Mat']=array('En'=>'The cat sat on the colourful mat!',
  24.                             'Us'=>'The cat sat on the colorful mat!',
  25.                             'Es'=>'El gato se sent&oacute; sobre la estera colorida',
  26.                             'Fr'=>'Le chat s`est assis sur le tapis color&eacute;',
  27.                             'De'=>'Die Katze sa&szlig; auf der bunten Matte',
  28.                             'Ru'=>'&#1050;&#1086;&#1090; &#1089;&#1080;&#1076;&#1077;&#1083; &#1085;&#1072; &#1082;&#1088;&#1072;&#1089;&#1086;&#1095;&#1085;&#1086;&#1081; &#1094;&#1080;&#1085;&#1086;&#1074;&#1082;&#1077;');
  29. $phrase['Click for help']=array('En'=>'Click<a href="#"> here </a>for '.$word['Help']['En'],
  30.                                 'Us'=>'Click<a href="#"> this </a>to get'.$word['Help']['Us'],
  31.                                 'Es'=>'Chasquido<a href="#"> aqu&iacute; </a>para'.$word['Help']['Es'],
  32.                                 'Fr'=>'Cliqueter<a href="#"> ici </a>pour'.$word['Help']['Fr'],
  33.                                 'De'=>'Klicken<a href="#"> Sie hier </a>daf&uuml;r'.$word['Help']['De'],
  34.                                 'Ru'=>'&#1065;&#1077;&#1083;&#1082;&#1085;&#1080;&#1090;&#1077;<a href="#"> &#1079;&#1076;&#1077;&#1089;&#1100; </a>&#1076;&#1083;&#1103;'.$word['Help']['Ru']);
  35. $text['Disclaimer']=array(    'En'=>'<h1>Disclaimer</h1>This code example will<ol><li>work properly</li>
  36.                                                                                 <li>give you a starting point</li>
  37.                                                                                 <li>not make your hair grow</li>
  38.                                                                                 <li>not pay the mortgage</li></ol>',
  39.                     'Us'=>'<h1>Disclaimer</h1>This code example will<ol><li>execute correctly</li>
  40.                                                                                 <li>get you started</li>
  41.                                                                                 <li>not stimulate hair growth</li>
  42.                                                                                 <li>not keep up your repayments</li></ol>',
  43.                     'Es'=>'<h1>Ment&iacute;s</h1>Este ejemplo de c&oacute;digo va a<ol><li>trabajo correctamente</li>
  44.                                                                                 <li>d&eacute;le un punto de partida</li>
  45.                                                                                 <li>no hacen su pelo crecer</li>
  46.                                                                                 <li>no pagan la hipoteca</li></ol>',
  47.                     'Fr'=>'<h1>Refus</h1>Cet exemple de code fera<ol><li>Travailler convenablement</li>
  48.                                                                                 <li>Vous donner un point de d&eacute;part</li>
  49.                                                                                 <li>Ne pas faire vos cheveux grandissent</li>
  50.                                                                                 <li>Ne pas payer l`hypoth&egrave;que</li></ol>',
  51.                     'De'=>'<h1>Verzichterkl&auml;rung</h1>Dieses Codebeispiel<ol><li>Arbeit richtig</li>
  52.                                                                                 <li>geben Sie Ihnen einen Startpunkt</li>
  53.                                                                                 <li>nicht lassen Ihr Haar wachsen</li>
  54.                                                                                 <li>nicht bezahlen die Hypothek</li></ol>',
  55.                     'Ru'=>'<h1>&#1055;&#1088;&#1072;&#1074;&#1086;&#1074;&#1072;&#1103; &#1086;&#1075;&#1086;&#1074;&#1086;&#1088;&#1082;&#1072;</h1>&#1069;&#1090;&#1086;&#1090; &#1082;&#1086;&#1076;&#1086;&#1074;&#1099;&#1081; &#1087;&#1088;&#1080;&#1084;&#1077;&#1088; &#1073;&#1091;&#1076;&#1077;&#1090;<ol><li>&#1088;&#1072;&#1073;&#1086;&#1090;&#1072; &#1076;&#1086;&#1083;&#1078;&#1085;&#1099;&#1084; &#1086;&#1073;&#1088;&#1072;&#1079;&#1086;&#1084;</li>
  56.                                                                                 <li>&#1076;&#1072;&#1081;&#1090;&#1077; &#1042;&#1072;&#1084; &#1086;&#1090;&#1087;&#1088;&#1072;&#1074;&#1085;&#1091;&#1102; &#1090;&#1086;&#1095;&#1082;&#1091;</li>
  57.                                                                                 <li>&#1085;&#1077; &#1079;&#1072;&#1089;&#1090;&#1072;&#1074;&#1083;&#1103;&#1102;&#1090; &#1074;&#1072;&#1096;&#1080; &#1074;&#1086;&#1083;&#1086;&#1089;&#1099; &#1088;&#1072;&#1089;&#1090;&#1080;</li>
  58.                                                                                 <li>&#1085;&#1077; &#1087;&#1083;&#1072;&#1090;&#1103;&#1090; &#1079;&#1072;&#1082;&#1083;&#1072;&#1076;</li></ol>');
  59.  
  60. $text['Licence']=array(    'En'=>'<h1>Licence</h1>Use this code freely, the translations may be inaccurate, but it makes a useful learning tool!',
  61.                     'Us'=>'<h1>License</h1>Use this code uninhibited, the translations may not be accurate, but it makes a useful learning tool!',
  62.                     'Es'=>'<h1>Licencia</h1>!Use este c&oacute;digo libremente, las traducciones pueden ser inexactas, pero hace un instrumento de aprendizaje &uacute;til!',
  63.                     'Fr'=>'<h1>Permis</h1>Utiliser ce code librement, les traductions peuvent &ecirc;tre inexactes, mais il fait un outil d`&eacute;rudition utile!',
  64.                     'De'=>'<h1>Lizenz</h1>Gebrauchen Sie diesen Code frei, die &Uuml;bersetzungen k&ouml;nnen ungenau sein, aber es macht ein n&uuml;tzliches Lernwerkzeug!',
  65.                     'Ru'=>'<h1>&#1051;&#1080;&#1094;&#1077;&#1085;&#1079;&#1080;&#1103;</h1>&#1048;&#1089;&#1087;&#1086;&#1083;&#1100;&#1079;&#1091;&#1081;&#1090;&#1077; &#1101;&#1090;&#1086;&#1090; &#1082;&#1086;&#1076;&#1077;&#1082;&#1089; &#1089;&#1074;&#1086;&#1073;&#1086;&#1076;&#1085;&#1086;, &#1087;&#1077;&#1088;&#1077;&#1074;&#1086;&#1076;&#1099; &#1084;&#1086;&#1075;&#1091;&#1090; &#1073;&#1099;&#1090;&#1100; &#1085;&#1077;&#1090;&#1086;&#1095;&#1085;&#1099;, &#1085;&#1086; &#1101;&#1090;&#1086; &#1076;&#1077;&#1083;&#1072;&#1077;&#1090; &#1087;&#1086;&#1083;&#1077;&#1079;&#1085;&#1099;&#1081; &#1080;&#1085;&#1089;&#1090;&#1088;&#1091;&#1084;&#1077;&#1085;&#1090; &#1080;&#1079;&#1091;&#1095;&#1077;&#1085;&#1080;&#1103;!');
  66.  
  67. //
  68. //-- End of array definitions
  69. //
  70. //
  71. //-- Create page content -- Write a form to change the language settings
  72. //
  73. //
  74. //-- Check whether this is first visit or whether language has been changed
  75. //
  76. if(isset($language)) // The user has visited & changed the original language.
  77. {
  78.     $submit = $word['Submit'][$language];
  79.     write_form($submit); // write_form accepts a reference to $submit.
  80.     print $phrase['Cat On Mat'][$language]."/n<br /><br />/n";
  81.     print $text['Disclaimer'][$language];
  82.     print $text['Licence'][$language]."<br /><br />";
  83.     print $phrase['Click for help'][$language];
  84. }
  85. else
  86. {
  87.     $language = "En"; // Set the default language for the first visit to the page.
  88.     $submit = $word['Submit'][$language];
  89.     write_form($submit); // write_form accepts a reference to $submit.
  90.     print $phrase['Cat On Mat'][$language]."/n<br /><br />/n";
  91.     print $text['Disclaimer'][$language];
  92.     print $text['Licence'][$language]."<br /><br />";
  93.     print $phrase['Click for help'][$language];
  94. }
  95.  
  96. function write_form(&$sub) // Accept a reference (denoted by [&]) to a var as the argument.
  97. {
  98.     print "<form method=/"post/">/n";
  99.     print "<select name=/"language/">/n";
  100.     print "<option>En</option>/n";
  101.     print "<option>Us</option>/n";
  102.     print "<option>Es</option>/n";
  103.     print "<option>Fr</option>/n";
  104.     print "<option>De</option>/n";
  105.     print "<option>Ru</option>/n";
  106.     print "</select>/n";
  107.     print "<input type='submitvalue=/"$sub/">/n";
  108.     print "</form>/n";
  109. }
  110. ?> [/code]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值