11
I have a site made in PHP, now I came up with the obligation to make the site multilingual. I need to translate titles, menus and error messages. User added texts do not need to be translated.
I’ve seen a lot of different approaches like:
Definition of constants:
It consists of defining constants in different PHP files, for example pt_PT.php and then making the inclusion include 'pt_PT.php';
translations before page loading.
Example: define( 'USER' , 'UTILIZADOR' );
Definition of arrays:
Consists of defining arrays also with inclusion include 'pt_PT.php';
.
Example: $lang['USER'] = 'UTILIZADOR';
Example in this answer.
Gettext:
After seeing this issue discovered that it may be by function gettext
.
For those who need here a mini tutorial to use the gettext and the poedit
Database:
There is also the possibility to store translations in a table of translations.
+-------+------------+--------+-----
|sigla | pt_PT | en | ...
+-------+------------+--------+-----
| usr | utilizador | user | ...
+-------+------------+--------+-----
Different pages for each language:
I have also seen, have replicated pages for different languages:
www.myhost.pt/en/index.php
www.myhost.pt/pt_PT/index.php
In my case I don’t need to have content translation, which is the best option?
Advantages/Disadvantages?
Is there a better option? Which one?
PS: The most consensual solution I’ve seen is through gettext.
possible duplicate of How to translate a website into PHP?
– Bruno Augusto
It is not duplicate, I refer to that question. My question is quite different. At least they bothered to read the questions?
– Jorge B.
In the link to possible dusplicata, has an excellent response from @Arivanbasos
– Bruno Augusto
@Brunoaugusto I edited the question and added the example of the answer you identified.
– Jorge B.
Now the duplicate signaling no longer makes sense. I removed it, but now it could be classified as "based on opinions" because to know the best way, it would require points of view from those who have already used all the alternatives and obtained a certain benchmark. But apparently I can’t vote again.
– Bruno Augusto
@Brunoaugust in this answer you have some disadvantages of methods in array and constants. It has nothing to do with opinions. It’s a question of advantages and disadvantages and I don’t translate content.
– Jorge B.