Bilingual website PHP script and advice

Hi, I have recently built a 10 pages website with a template (as everyone does, but now my client asked me to add a second language to it (Spanish). I have spent 2 days searching for a step by step guide but the only thing I found was either a simple plain advice on how to copy paste pages into a sub folder and translate them all or a php script, now, how do I combine the two?? (have in mind that each page will be accurately translated by specialists, so no need for any sort of translator) I only need to have Englis/Spanish buttons which will switch from one language to the other…that’s it. Is there ANYONE kind enough to guide me step by step? Thank you in advance. R.

We normally use “gettext” for multilingual sites, the benefit is that you only need to maintain one set of web files. Note. if you plan to support both left and right reading direction languages, it becomes more tricky but still possible.

All you need to do when adding a new language, is upload the language file, and it will work across the website. In addition the translator will be able to use a software utility when translating, showing which phrases that has to be translated at all time.

You can read more about it here:

1 Like

I appreciate your advice, the thing is that each html page is being translated by real interpreters as we speak, what I need is to have two links on the home page looking like this: English/Spanish sort of, and when clicking on them would load the English version (Spanish being the default language). All pages would have the same template, the content changes though, and of course the menu should change as well when switching languages.
I don’t know if “gettext” could help me with that…anyways, I’ll study hard and give it a try. If anyone has any more suggestions, please feel free to do so, thank you again. R.

Gettext is exactly suited for just that. Wherever you have rendered text you do something like (simplified example)
'<p>' . __("text here", "spanish") . '</p>'
and gettext will use the mo file compiled from the po file eg.
"text here" "texto aquĂ­"

It takes a little more work up front, but the beauty is that if you ever decide to support more languages everything is in place. That and you don’t need to go hunting through multiple files to tweak wording changes.

1 Like

Thank you,

Ok, I’ll get right on it.
Is there a book or manual where I could read everything related to “gettext”? I am most interested in finding the right script and full guidance on where to place them and so forth (especially if there’s PHP coding involved). Thanks again.

The site:
PHP docs:
WordPress Codex:

Even if you’re not WordPress IMHO reading it should give you a good clear idea about how it works that’s easy to understand.

1 Like

Thank you very, very much both of you!

For a website with only 10 pages and a single additional language to support the simplest solution is just copy the existing HTML to new templates and switch out the grammar. Once that is done use some type of language switcher that determines which version of the template to bring in. You could simply put the language switcher in the header of the site and set a session and/or cookie variable to detect the language to serve the site in.

Also, if your not dealing with dynamic pages than you could just have a separate website under a different domain with a copy of the existing work but with the spanish content. On the spanish website have a link to the english site and english a link to the spanish one. That wouldn’t require any server-side scripting just a separate domain and dns record. Though you could also but the spanish version under a subdirectory of the main site. If the site was static pages only at this point that is probably what I would recommend. Especially if you’re not familiar with server-side scripting.

1 Like

Thank you :slight_smile:

I think in the end, I would like to go with your first version, is there a tutorial, or a book that could show me how to do it? Thank you.

Found a good example here, do you think this will do: