← Back to team overview

mahara-contributors team mailing list archive

[Bug 1982702] [NEW] Date strings to be in correct language

 

Public bug reported:

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,

eg:

    $cl = current_language();
    // Remove the '.utf8' from the language
    $cl = preg_replace('/\.utf8$/','',$cl);
    $langobject = datefmt_create($cl, IntlDateFormatter::LONG, IntlDateFormatter::SHORT);
    $langstring = datefmt_format($langobject, 1658651838);
    log_debug($langstring);

** Affects: mahara
     Importance: High
         Status: Confirmed

** Changed in: mahara
       Status: New => Confirmed

** Changed in: mahara
   Importance: Undecided => High

** Changed in: mahara
    Milestone: None => 22.10.0

-- 
You received this bug notification because you are a member of Mahara
Contributors, which is subscribed to Mahara.
Matching subscriptions: mahara-contributors
https://bugs.launchpad.net/bugs/1982702

Title:
  Date strings to be in correct language

Status in Mahara:
  Confirmed

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,

  eg:

      $cl = current_language();
      // Remove the '.utf8' from the language
      $cl = preg_replace('/\.utf8$/','',$cl);
      $langobject = datefmt_create($cl, IntlDateFormatter::LONG, IntlDateFormatter::SHORT);
      $langstring = datefmt_format($langobject, 1658651838);
      log_debug($langstring);

To manage notifications about this bug go to:
https://bugs.launchpad.net/mahara/+bug/1982702/+subscriptions



Follow ups