random1 Posted July 28, 2011 Share Posted July 28, 2011 Hey All! 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? Should I be using gettext or setlocale()? Quote Link to comment https://forums.phpfreaks.com/topic/243081-localization-and-internationalization/ Share on other sites More sharing options...
Psycho Posted July 28, 2011 Share Posted July 28, 2011 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; } Quote Link to comment https://forums.phpfreaks.com/topic/243081-localization-and-internationalization/#findComment-1248699 Share on other sites More sharing options...
random1 Posted July 29, 2011 Author Share Posted July 29, 2011 Thanks for the detailed help, really useful! Quote Link to comment https://forums.phpfreaks.com/topic/243081-localization-and-internationalization/#findComment-1248830 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.