user1967184 user1967184 - 9 months ago 44
PHP Question

How to efficiently translate website content with php, keeping it SEO friendly?

This is the scenario:

I have a website that I'll translate and eventually apply a good SEO on it.
Which method is best for translate the content (menu links, about 10 articles, alt tags, title tags, meta tags, html lang, etc) while being easely indexed by Google, Bing, Yandex and other search engines?

My first idea is to use a translate php function that consists of arrays made by myself (I have a prototyope of it already) that takes the content and displays it in the user's language.

Is this the right path? the problem here is that I wanted to be sure to have a dynamic system that allows me to add a new language in the future.

Maybe MySql is the right choice?

The website doesn't use a cms, I made it by myself with php though I have no problem to rely on MySql if I need to.

Thank you in advance :)

Answer Source

Store all texts inside a db and apply another field for language:

| id | text_en | text_de |
|  1 | English | Deutch  |

Now, when user switches languages, just use the field for that language:

$lang = 'en';
$query = "SELECT text_".$lang." FROM texts WHERE id = 1";

Something like that. So, all your client side texts will be stored inside the db at all times. So your output will be like:

<div id="header"><?=get_db_text_for_id(1)?></div>

Of course, you need precautions and some more field, but thats the general idea.