0

I have a blog archive that's in English and I want the month to display in Swedish instead. I've searched and tried answers to similar problems, but nothing is working. Can someone please help?

<?php
include 'includes/db_connection.php';
setlocale(LC_ALL, 'sv_SE');
$result = mysql_query("SELECT FROM_UNIXTIME(timestamp, '%M %Y') AS get_month, COUNT(*) AS entries FROM php_blog GROUP BY get_month ORDER BY timestamp DESC"); ?>

<ul class="archive_list">
<br><br><br><br>
<ul class="archive_ul">
<?php
while ($row = mysql_fetch_array($result)) {
setlocale(LC_ALL, 'sv_SE');

$get_month = $row['get_month'];
$entries = $row['entries'];
echo "<li><a href=\"archive.php?month=" . $get_month . "\">" . $get_month . "</a></li>";
}


//setlocale(LC_ALL, 'sv_SE');
//echo utf8_encode (strftime("%A %e %B %Y"));

?>

So in the link below I want the month to display in Swedish instead, and I'm using get_month to extract it from my database. Any ideas? I really only need the name of the month that will be shown in the link to be translated. THANKS!

2 Answers2

1

setlocale() sets the locale for PHP, but the Month name is being generated by MySQL which has its own settings. Try updating MySQL's locale with:

mysql_query("SET lc_time_names = 'sv_SE'");

(this should replace your first instance of setlocale(), before your SELECT ... statement

NB: mysql_* functions are depreciated, you might want to consider using mysqli_* instead

Emily Shepherd
  • 1,369
  • 9
  • 20
  • Thank you SO SO SO much! This worked! This archive has been driving me crazy for the longest time now. Thanks alot! :D – Sazyline Apr 07 '14 at 10:51
0

If its only the month, have it put in an array with the month index and use google translate for the 12 months.

$swedish_months = array('Januari','Februari','Mars','April','Maj','Juni','Juli','Augusti','September','Oktober','november','December');

that will have it as index of 0

so when you grab it $swedish_months[$get_month] will zone into the index. Unless get_month is not numeric you will need to adjust the index look up accordingly. (ie: array('00'=>'Januari',...)

azngunit81
  • 1,574
  • 2
  • 20
  • 38