Eber Freitas Dias
Eber Freitas Dias

Reputation: 879

The pains of creating a global application

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 advance!

Upvotes: 3

Views: 180

Answers (4)

JonoW
JonoW

Reputation: 14229

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.

Upvotes: 1

Joeri Sebrechts
Joeri Sebrechts

Reputation: 11156

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).

Upvotes: 3

D.Shawley
D.Shawley

Reputation: 59623

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.

Upvotes: 1

Mihai Nita
Mihai Nita

Reputation: 5787

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.

Upvotes: 2

Related Questions