WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : translate.php - Assocciative array example, passing a reference to a function.
Categories : PHP, Arrays, Languages, Variables Click here to Update Your Picture
Ade Morgan
Date : Apr 22nd 2004
Grade : 4 of 5 (graded 2 times)
Viewed : 5867
File : 3844.php
Images : No Images for this code example.
Search : More code by Ade Morgan
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

A round about way to provide multilingual support for your site :) ???



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


<?php
//-- 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";
}
?>



clearing variables in php3
Categories : Variables, Arrays, PHP
PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside.
Categories : PHP, Arrays, Variables
Dump the contents of a PHP variable in html format with a recursive list of subfolders and files from a given root directory.
Categories : PHP, Directories, Variables, Arrays
Pageinfo: Array containing page URI, page query string (parameters), request method (GET or POST) and the complete URI
Categories : Variables, PHP Options and Info, Arrays, URLs, PHP
Variable serialization and unserialization. Loading and saving variable structures to and from file.
Categories : Arrays, Filesystem, Variables, Strings, PHP
A class to put get and post variables in hidden form elements. Works on scalars, normal arrays, associative arrays.
Categories : Algorithms, Variables, Arrays, PHP, PHP Classes
A database abstraction layer for the PHP Oracle 8 module (available from PHP 3.0.5). It supports persistent connections, fetching rows into arrays, prepare/execute (variable binding) and has a new and improved error interface.
Categories : Databases, Oracle, PHP, Arrays, Variables
How to pass an array to a function, or how to define a function wich recieves an array.
Categories : Variables, PHP, Arrays
Simple script to passing persistent and growing array between recalls of one page (manipulate little stack).
Categories : Arrays, Global Variables, PHP, HTML and PHP, Variables
Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET
Categories : Algorithms, HTML and PHP, PHP, Variables
Select with current month
Categories : PHP, HTML and PHP, Date Time, Arrays
PHP Random rss feeds - selects 49 random feeds from an unlimited list and displays them on your website. It's Ideal for those moments when you got 5 minutes and dont know which one of your feeds to read.
Categories : PHP, Rich Site Summary (RSS), Arrays
Display list of files within current and subdirectories (recursively) showing each file as an anchored link and each directory as a category header.
Categories : Filesystem, Directories, Arrays, PHP
A simple function to prevent undefined $_POST/$_GET/$_SESSION variable errors
Categories : PHP, Variables, Errors and Logging
Stock quotes from yahoo!
Categories : PHP, Web Services, Arrays