Jump to content

Localization and Internationalization?


random1

Recommended Posts

Hey All!  :D

 

I'm trying to get some experienced advise on how to localize and internationalize a PHP app.

 

My current app uses UTF-8 and I have multiple languages in my database listing the translated strings of text.

 

I have set it up to have all data in a mysql database and have no strings hard-coded in any PHP files.

 

How can I echo out for example:

 

- the current date and time

- the current date and time plus 1 hour

- a money format (e.g. $1000.00 to EU$1000,00)

 

in a format suitable for say the 'de-DE' (German) locale?  :confused:

 

Should I be using gettext or setlocale()?  :wtf:

Link to comment
https://forums.phpfreaks.com/topic/243081-localization-and-internationalization/
Share on other sites

The setlocale() function will be useful for other functions used in your script. For example, if you allow the user to enter a date in the format "aa-bb-yyyy", the locale setting will determine whether the month comes first (US) or if the day comes first (Europe). But as for actually displaying the date, I believe you will need to create the formats you want to use and apply the appropriate ones for the user. I don't think there is a built-in way to automatically handle this because there can be numerous, valid way to display an address in each locale.

 

For determining the time offset just use strtotime to adjust the current time to the correct time for the user. Example

$usersCurrentTime = strtotime("+1 hours");

Of course you need to set the default time for the server to GMT time using date_default_timezone_set.

 

For money and numeric information you can build your display functions using the values from localeconv() which provides data on number of decimals, separator, and currency symbol. Example:

function formatMoney($number)
{
    $locale_info = localeconv();
    $money = number_format($number, 2, $locale_info['mon_decimal_point'], $locale_info['mon_thousands_sep']);
    return $locale_info['currency_symbol'] . $money;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.