This is the most optimal way of dealing with a multilingual website I can think of, right now (not sure) which doesn’t involve gettext, zend_translate or any php plugin or framework.
I think its pretty straight forward: I have 3 languages and I write their “content” in different files (in form of arrays), and later, I call that content to my index.php like you can appreciate in the following picture:
alt text http://img31.imageshack.us/img31/1471/codew.png
I just started with php and I would like to know if I’m breaking php good practices, if the code is vulnerable to XSS attack or if I’m writing more code than necessary.
EDIT: I posted a picture so that you can see the files tree (I’m not being lazy)
EDIT2: I’m using Vim with the theme ir_black and NERDTree.
Looks all right to me, although I personally prefer creating and using a dictionary helper function:
that would enable you to easily switch methods later, and gives you generally more control over your dictionary. Also with an array, you will have the problem of scope – you will have to import it into every function using
global $language;very annoying.You will probably also reach the point when you have to insert values into an internationalized string:
that is something a helper function can be very useful for:
$value1and$value2would be inserted into%1and%2in the dictionary string.Such a helper function can easily be built with an unlimited number of parameters using func_get_args().