Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 this be done in a completely different way? If it matters at all, the site is written in PHP and uses MySQL.

like image 520
James Simpson Avatar asked May 25 '10 03:05

James Simpson


People also ask

What is dynamic localization?

Localization or Internationalization is the way of presenting your apps to the global audiance. In other terms, its the ability of your app to present itself in multiple languages.


2 Answers

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!

like image 88
Luca Filosofi Avatar answered Oct 21 '22 23:10

Luca Filosofi


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.

like image 41
Koen Avatar answered Oct 22 '22 00:10

Koen