On a webpage that contains items in various languages, it would be desired to display different dates in different languages:
jeudi, 15 octobre
next to Donnerstag, 15. Oktober
- on the same page.
Ist that possible?
On a webpage that contains items in various languages, it would be desired to display different dates in different languages:
jeudi, 15 octobre
next to Donnerstag, 15. Oktober
- on the same page.
Ist that possible?
When you switch the locale with setlocale
, the set locale is being used for everything after that.
So you could create a custom function which will switch the locale just for the desired output and then switch back. The following should work:
function locDate($format, $locale, $time = null)
{
$oldlocale = setlocale(LC_ALL, "0"); // get the current locale
setlocale(LC_ALL, $locale);
$date = date($format, $time);
setlocale(LC_ALL, $oldlocale);
return $date;
}
Using this for localized dates is just an example. This approach works with everything that gives different output based on the current locale.
This also works if you're using gettext for string translation. You can temporarily switch the locale to output certain chunks of text in a different language (assuming that a translation exists in your catalog and the catalog is loaded).