EWWW How I love this topic!!!!
This is the one topic I can really give my two cents on!!!
You see, as a standalone programmer of over 20 years, I have had to do this a couple of time prior to learning PHP and once heavily on a project in PHP. To further my recognition as knowing what I am speaking of, Mi segunda idioma es Español, que yo aprendi en Mexico y vivia en Chihuahua som 4 años. Tambian tango clientes Mexicanos aque y en el altra lado.
There are several ways you can accomplish this task. The easiest, cheapest, and also the poorest way to do this is to create a link to Altavista that pulls your site in automatically for the visitor (see:
http://babelfish.altavista.com/ for a link to assist you in doing this at the bottom of their page). Every time, someone clicks that link, the site will automatically be re-interpreted and displayed.. This is fine except that translated Spanish, by any program I have ever seen, is only 40% to 50% effective. Have you ever gone to a site and tried reading the English and decided that the person who wrote it must have been really really lost when they wrote the text?
What this means is, you must hand interpret your displayed text (not your variable names) so that anything read makes sense to the reader. Next you must store your text some how and as James mentioned, you could have the English and the Spanish embedded in the code but as James said, this is a no, no, no. Why? Because it may seem easy enough to do, but when there is a correction to make, it is harder to find and easier to create errors with. You may also store each phrase in it's own phrase file with extensions depicting eng or spn but this means you will have a lot of files to manage and this can lead to similar errors as embedded text except at this point you have a variable deciding the extension. You could also create a database and with the same variable idea, manage the records pulled from the MySQL database structure. But, the easiest way to manage a fair sized site would be to have a single language file.
Single language file
1) build the site
2) open a text file, remove phrase by phrase from your code the English phrases displayed and replace them with an array variable and very importantly, a comment text so that the code makes sense. Place a line in the text file indicating the array number and then the text on the line below it.
3) Once the entire site is stripped from it's text and replaced with array values, you may test and make sure that the text that should show in fact does show.
(one important note: you are creating two records for every line (or block) of text and your array will have to account for this. DO NOT physically set values to do this, rather create a multiplier variable at the top of your includes or top of your code to multiply the record number by, to account for the two records. You will ALSO need an offset variable to move the pointer forward one position to skip over the notes in this file above each text. This offset will be used later to select language)
4) One up your language file and add the interpretations for every text line directly below the line interpreted. This way, you will now have three lines for every text and you will want to adjust your multiplier at the top to 3.
5) After testing the text, add code to allow a person to switch to Spanish and when they do so, simply have that code adjust your offset up or down.
By doing this in this fashion, you have also opened the door to other languages. To add another language, you would create the text below the Spanish interpretation on each line and add code to adjust the offset to the new language plus adjust your multiplier variable by one more for one more language.
There are a great many more details such as how to use arrays and how to open files from disc in PHP and load them into an array but, this is the best way unless the site is overwhelmingly large. In this case, you may choose text files for each section or to go database.
If you need some tips, please feel free to call me, just be patient, I have to take care of a lot of calls from clients first. If you would rather have it done for you, that can be done also, contact me for pricing. In doing interpretations, I always share the work with another associate who speaks Spanish as his first language and English second. Between he and I, we create some remarkably readable text and unlike others, our interpretations will many times read different in English then in Spanish since we account for culture, class and customs that would affect the way someone reads in their own language.
HMIBarryLSalter -