How to handle dynamic site localizations?
I've got a website that is currently all in English. It is an online game, so it has a bunch of different pages with static text, as well as a lot of content in a database.
I am trying to expand more globally and am gearing up to release some localizations of the site. However, I'm not sure about the best way to go about setting this up so that it'll be the easiest for me to manage and the easiest for users to use as well.
Should I be storing the translated texts in a database, or should开发者_StackOverflow this be done in a completely different way? If it matters at all, the site is written in PHP and uses MySQL.
In my experience doing all the translations manually can be a real nightmare! %-)
i think you must focus your translation to the dashboard command site like the navigation menu and all other user profile settings, and buttons around the site and things like that!
do this by including into your pages file like this:
include "./includes/languages/english.php";
in a file called ex.: english.php
put like this ex
define('LAN_USER_LOGIN' , 'User Logged In');
define('LAN_USER_LOGOUT' , 'User Logged Out');
.....
and so on italian.php, spanish.php, french.php ect... and in each of this files have the same defined variables but translated!
then you can let user chose from a list of Countries! many way of doing this btw!
one way can be by using session
// if the user haven't selected a language before!!
if (empty($_SESSION['language'])) {
$_SESSION['language'] = "EN";
} else {
$_SESSION['language'] = YOUR_LANG ;
}
for all other content i recommend to use tools like
http://code.google.com/intl/it-IT/apis/ajaxlanguage/
NOTE: i recommend to you of don't use an auto recognition system, cause it can result in a very annoying experience expecially if you are watching the site from another country!! or just you want chose from, briefly let the user final choice! ;-)
use the auto recognition for autocompletation registration purpose! ;-)
hope this help!
I'd suggest to use a centralized storage (this could be a MySQL database table, with a column "language" which stores what language the translation is in). This could also be XML files, one file per language.
If you are looking for even more possible file formats, look at this documentation page from Zend Framework: http://framework.zend.com/manual/en/zend.translate.adapter.html
For the translation I would either create a custom function or custom class, if you are not using a framework that already includes translation.
Another option is to use standard PHP functions. Just look for the "_()" function. I haven't worked with these functions though and only just found them, not sure how well they work.
I'd recommend using gettext with a framework that integrates (e.g. Zend) and storing in the .po file format. The .po format has editors that make the translation work fairly. It's also quite portable (thus the name) and could move with you onto other games.
We use a mixed approach with the Zend framework. Page content (WYSIWYG pages) is stored in the DB (one record per language, non-localized data is separated from localized data and stored in different tables that are linked), but field labels and standard error/feedback messages are stored in XML or gettext files (one file per language).
We use a mixed approach :
- Database for CMS pages translations
- XML for word/sentence translations (static texts, labels, error messages, etc)
For database we generaly use 2 tables : 1 for main content, other form translations, so we can choose what to do if translation is not available : display content in its original language, or hide it.
For XML, we use XLIFF format, which can be easily is supported by many frameworks and softwares
精彩评论