views:

87

answers:

4

Hey guys!

I need to create a global application. This means it should work ok anywhere in the world, at any country (or most of them). It's a PHP website that will deal with money and time at certain points.

I wish I could know a good resource for countries, related timezones, currency formatting, symbols and codes, this kind of stuff...

If anyone has tips about these kind of data and how could I use them in the propper way, I would be really grateful :)

Thanks in advanced!

+1  A: 

Take a look at how the Mantis BugTracking software handles internationalization. The method that they use is rather nice.

Additional Information: It has been years since I have used it, but a quick look through the source code shows that this portion of the code has not changed significantly. They use the common message catalog and get message approach that many products use. Their language API is pretty simple - the phpxref output is available and it isn't that surprising. The message catalog is implemented as a PHP script that simply gets include'd. For example, the catalog for English contains entries like:

$s_new_bug = 'New Issue';
$s_bugnote_added = 'Note Added';

It contains about 1,600 or so declarations. The interesting magic happens inside of lang_load. When a language is loaded, the catalog file is included so all of the variables that it defines are defined in the local scope. Lang_load iterates over the locally defined variables and builds a message map based on the variable names so that it can look up the message by name. For example, after loading the previous snippet, it will be as if the following statements were executed:

$g_lang_strings['en']['new_bug'] = 'New Issue';
$g_lang_strings['en']['bugnote_added'] = 'Note Added';

When the UI needs to access a "hard coded" string, it uses a call like lang_get('new_bug') which will:

  1. Lookup the preferred language in the settings for the current user
  2. Ensure that the language map is loaded by calling lang_load()
  3. Return the value from the appropriate language map

The interesting thing is that all of the machinery is lazily loaded. You don't pay for the fact that they have 50 or so languages defined until you need to access one of them. Overall, this is probably one of the most inpressive PHP applications that I have dug into over the years.

D.Shawley
Could you add a further clarifications? I'm curious, but I don't have the time to check the code right now.
Alix Axel
Sorry man, there're better ways how to deal with multilingual applications - gettext. I would never go the way you described. Gettext is a de facto standard and you don't have to build it by yourself.
dwich
+1  A: 

Take a look at intl (http://www.php.net/manual/en/book.intl.php).

It is a wrapper around ICU (International Components for Unicode, http://site.icu-project.org/) and contains most of the stuff you need.

Mihai Nita
+2  A: 

Zend Locale, part of Zend Framework, helps you solve problems related to currencies, time zones, translation, ...

It's easy to adopt Zend Framework piece-by-piece, so you can just use those parts you need (no bloat or slowdown).

Joeri Sebrechts
+1  A: 

I've worked on an globalised app and I find one of the trickiest elements is time zones and how you store your datetimes. Sometimes dates need to be stored in local time (like the time of an event at the place in the world) and somethimes they need to be stored in a common time zone (e.g. storing created dates as UTC for everything) and converted to the users local time when needed. I would advise a naming convention of your db columns/variables to make it clear which it is.

Never try to do deal with timezone conversions manually (it's much more complicated than you think), use some kind of library/framework - I wouldn't know what to use in PHP, in .Net we can rely on the .Net BCL for this sort of thing.

JonoW
JonoW, why not store all dates/times as UTC and convert them on the fly? This seems far more reliable to me, and since you know the date/time, the conversion functions will work accordingly. The only way I could see running into trouble would be if you only stored time without the date.
Brad
Yes you could of course, but there are dates that you may want to remain unconverted. E.g. if a user in London says an event starts at 7pm in London, you might not want users in Germany to see this as 8pm (depends on context), so there needs to be some way to document this - in our case we choose a naming convention. If the event was a global event (e.g. a speech being broadcast over the web), then it would make sense to store in UTC.
JonoW