I’m working on making a skeleton from which to build small to medium-sized sites in multiple languages. I’m using the method from this tutorial:
http://www.bitrepository.com/php-how-to-add-multi-language-support-to-a-website.html
I know it’s from 2009 but I like how they did it, and it will be the easiest to understand for my coworkers, especially since I’ve commented the bejeezus out of the files myself.
This is a good solution for replacing relevant text in the site. The problem I’m facing now stems from the fact that not all the words on any given site are necessarily text. There are plenty of images, navigation buttons, and so on that would need to be replaced as well.
My thought is to go into common.php (as described in the tutorial) and add a conditional that would change the image directory (img/ or image/) as well. For example, if my file structure looked like this:
www
index.php
common.php
/img
/jplang.jp.php
/img
If the user selects Japanese as their language and the script runs to get all the text from lang.jp.php, I would want to be using the images in the /img directory within /jp as well.
So my question is, how would I change the src to the proper /img directory for each image tag within the html? Is it possible to use a php switch and set the src to a variable and just call that variable before stating the image name, like <img src="<?php echo($imgsrc);?>/image.jpg" />, and assign the path dynamically to $imgsrc? If so, what’s the best way to set that variable?
@OpenCode had the right idea, but it might be easier to, instead, keep using the img folder you have and make a new folder within it for each language.
Then use:
This way your webroot won’t become too messy should you decide to add more languages later on.