Month name shown in English on item page, in spite of language settings

Alright, here is how I dealt with this.

In modules/NumericDataTypes/src/DataType/AbstractDateTimeDataType.php I changed the order of day and month, from e.g. the American “December 17, 2019” to “17 December 2019”. This was rather straightforward, and just meant inverting the order of j and F and removing commas immediatel after // Set the render format in the file. This is how it looks for me now:

// Set the render format.

        if (isset($dateTime['month']) && isset($dateTime['day']) && isset($dateTime['hour']) && isset($dateTime['minute']) && isset($dateTime['second']) && isset($dateTime['offset_value'])) {
            $format = 'j F Y H:i:s P';
        } elseif (isset($dateTime['month']) && isset($dateTime['day']) && isset($dateTime['hour']) && isset($dateTime['minute']) && isset($dateTime['offset_value'])) {
            $format = 'j F Y H:i P';
        } elseif (isset($dateTime['month']) && isset($dateTime['day']) && isset($dateTime['hour']) && isset($dateTime['offset_value'])) {
            $format = 'j F Y H P';
        } elseif (isset($dateTime['month']) && isset($dateTime['day']) && isset($dateTime['hour']) && isset($dateTime['minute']) && isset($dateTime['second'])) {
            $format = 'j F Y H:i:s';
        } elseif (isset($dateTime['month']) && isset($dateTime['day']) && isset($dateTime['hour']) && isset($dateTime['minute'])) {
            $format = 'j F Y H:i';
        } elseif (isset($dateTime['month']) && isset($dateTime['day']) && isset($dateTime['hour'])) {
            $format = 'j F Y H';
        } elseif (isset($dateTime['month']) && isset($dateTime['day'])) {
            $format = 'j F Y';
        } elseif (isset($dateTime['month'])) {
            $format = 'F Y';
        } else {
            $format = 'Y';
        }

Now the word order was right, but everything was still in English. Unfortunately, I was unable to get anything done with setlocale(), so I want with the find&replace option.

To fix this, I edited the file modules/NumericDataTypes/src/DataType/Timestamp.php , immediately after the comment // Render the datetime, allowing for reduced accuracy. My file looks as follows:

        // Render the datetime, allowing for reduced accuracy.
        $date = $this->getDateTimeFromValue($value->value());

// start of custom fix for Italian translation of months
$renderedDate = $date['date']->format($date['format_render']);
        $monthsEnglish = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
        $monthsItalian   = array("gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", "luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre");
        $renderedDate = str_replace($monthsEnglish, $monthsItalian, $renderedDate);

        return $renderedDate;
// end of custom fix for Italian translation of months

Everything works fine, but largely due to my limited php skills this took longer than it could have. Hope it helps others who find themselves in the same situation.

All things considered, I agree that “Internationalizing date strings is tricky”, and yet, it would be so nice to be able to get this right without all this custom editing.

I understand that doing this via locale, which should be the “right” way to go about it, is likely problematic due to server issues, but ultimately, even hardcoding month names in a couple of dozen languages and inheriting language settings from the site settings should be doable without the need to create custom settings exposed to the user. Ultimately, NumericDataTypes is really a must-have module for Omeka S, and having dates appear in a foreign language on every page is actually a very significant issue for non-English speakers.

3 Likes