Date strings to be in correct language

Bug #1982702 reported by Robert Lyon
This bug affects 1 person
Affects Status Importance Assigned to Milestone
In Progress
Doris Tam

Bug Description

Display the dates in correct language

If we have a multi tenancy site then the PHP language may not be set to the one a person is viewing the site with so that PHP created strings, like a date may be in wrong language, eg

EN 24 July 2022, 08:37
DE 24. July 2022, 08:37

We can't use the PHP setlocale() function because it can cause issues on a multithreaded server

Now that we are including PHP intl module by default we can use some of it's functions to get what we need,


    $cl = current_language();
    // Remove the '.utf8' from the language
    $cl = preg_replace('/\.utf8$/','',$cl);
    $langobject = datefmt_create($cl, IntlDateFormatter::LONG, IntlDateFormatter::SHORT, null, null, 'dd. MMMM yyyy, hh:HH');
    $langstring = datefmt_format($langobject, 1658651838);

Tags: bite-sized
Robert Lyon (robertl-9)
Changed in mahara:
status: New → Confirmed
importance: Undecided → High
milestone: none → 22.10.0
Robert Lyon (robertl-9)
description: updated
tags: added: bite-sized
Robert Lyon (robertl-9)
description: updated
Revision history for this message
Robert Lyon (robertl-9) wrote :

We will need to create language string that follow the ICU date formats

They don't seem to have as many options that DateTime does but they do translate months / day words correctly

Changed in mahara:
milestone: 22.10.0 → 23.04.0
Revision history for this message
Kristina Hoeppner (kris-hoeppner) wrote :

Way forward:

Find all the places where we use date and date-time strings -> consolidate these to use formats allowed by ICU because we should keep things consistent anyway and don't need lots of different date displays

Changed in mahara:
milestone: 23.04.0 → 24.04.0
Revision history for this message
Doris Tam (doristam) wrote :
Changed in mahara:
assignee: nobody → Doris Tam (doristam)
status: Confirmed → In Progress
Revision history for this message
Kristina Hoeppner (kris-hoeppner) wrote :


To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.