I have a site made in PHP, now it has come to me that it is obligatory to make the site multilingual. I need to translate titles, menus and error messages. Texts added a posteriori by the user do not need to be translated.
I have seen several types of approaches like:
Definition of constants:
It consists of defining constants in different PHP files, for example pt_PT.php and then adding include 'pt_PT.php';
of translations before page loading.
Example: define( 'USER' , 'UTILIZADOR' );
Definition of arrays :
Consists of defining arrays also including include 'pt_PT.php';
.
Example: $lang['USER'] = 'UTILIZADOR';
Example in this answer .
Gettext:
After viewing this question I discovered it might be by function gettext
.
For those who need it here a mini tutorial to use gettext and poEdit
Database:
There is also the possibility of saving the translations in a table of translations.
+-------+------------+--------+-----
|sigla | pt_PT | en | ...
+-------+------------+--------+-----
| usr | utilizador | user | ...
+-------+------------+--------+-----
Different pages for each language:
I've also seen having replicated pages for different languages:
www.myhost.pt/en/index.php
www.myhost.pt/en/index.php
In my case that I do not need to have content translation, what is the best option?
Advantages / Disadvantages?
Is there any better option? What?
PS: the most consensual solution I've seen is through gettext.