This topic was marked solved by its starter, on October 7th, 2012, 05:46 PM
SMF bug 4870 (incorrectly capitalised month names)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
SMF bug 4870 (incorrectly capitalised month names)
« on February 29th, 2012, 02:56 PM »
I still don't get why SMF and Wedge don't just have the months set appropriately for language and use them rather than trying to mess around with ucwords...
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Nao

  • Dadman with a boy
  • Posts: 16,082

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: SMF bug 4870 (incorrectly capitalised month names)
« Reply #2, on March 1st, 2012, 09:20 AM »
The bug report points to Dutch. In all other languages, the months are written January/February/whatever, but in Dutch, the correct spelling is entirely lowercase.

Yet, timeformat() pushes them through ucwords() unless a $txt variable is set, which implies it's a known workaround, but if we already have $txt strings for the months, we would have them just be correct without any need to mess with ucwords in the first place.

Nao

  • Dadman with a boy
  • Posts: 16,082

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: SMF bug 4870 (incorrectly capitalised month names)
« Reply #4, on March 1st, 2012, 09:55 AM »
That's the thing, it's actually broken. Here's our code.

Code: [Select]
if ($user_info['setlocale'])
{
foreach (array('%a', '%A', '%b', '%B') as $token)
if (strpos($str, $token) !== false)
$str = str_replace($token, !empty($txt['lang_capitalize_dates']) ? westr::ucwords(strftime($token, $time)) : strftime($token, $time), $str);
}
else
{
// Do-it-yourself time localization. Fun.
foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
if (strpos($str, $token) !== false)
$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
}

Now, SMF's code is slightly different because I tweaked how setlocale was run but the basis is the same: if we could setlocale, locale is *probably correct* (certainly the example on the setlocale page in PHP actually validates this... it uses Dutch specifically so that the formatting will be shown) and yet it's discarded.

If we don't trust the locale DB, we shouldn't use it and just use the later branch where we have the strings ourselves, and if we do trust the locale DB, we should leave it the hell alone and not mess about with ucwords on it.