Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-14149

day names, month names and am/pm appear garbled in Chinese and Japanese on Windows servers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • 1.7.4, 1.8.4, 1.9
    • Language
    • None
    • Windows 2003 server (English OS and Japanese OS both exhibit same behavior)
      Apache 2.2
      PHP 5.2.4 (mbstring and iconv enabled with default settings)
      database is not relevant
      browser is not relevant
    • Any
    • MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE

      Dates in Japanese and Chinese appear garbled on Moodle sites running on a Windows server. By "garbled" I mean the date and the text around it on the page in the browser are morphed into irrelevant characters and question marks (see screenshot)

      Apparently PHP's strftime() function used by Moodle's "userdate()" function (in lib/moodlelib.php") is where the text gets mangled.

      In Japanese, date strings containing %A, %a, %B, %b, %p are consistently mangled by strftime().

      In Chinese, dates strings ending in a multibyte character cause the mangling:
      $string['strftimedate'] = '%%Y?%%m?%%d?';
      $string['strftimedateshort'] = '%%m?%%d?';
      $string['strftimemonthyear'] = '%%Y?%%m?';

      I experimented with many values for ...
      (1) the Moodle site locale (Language -> Language settings -> Sitewide locale)
      (2) the 'locale' string in the language pack
      (3) the 'localewin' string in the language pack
      (4) the 'localewincharset' string in the language pack

      but I could not find values for the above settings to fix the multibyte dates.

      In the end I modified the userdate() function to fix %A, %a, %B, %b, %p in a similar that %d is fixed. Firstly, replace with "AA", "aa", "BB", "bb", or "pp", then format the date, then replace "AA" with %A that has been correctly converted to utf8, "aa" with a% that has been converted to utf8, and so on.

      As well as replacing the userdate function in moodlelib.php with the function in the attached file, "userdate.txt", it is also necessary to modify "get_string()" as follows:

      (1) locate the following line in the "get_string()" function (in "lib/moodlelib.php"):
      'localewin', 'localewincharset', 'oldcharset',

      (2) replace the above line with the following line:
      'localewin', 'localewincharset', 'localewincharsetdaymonth', 'oldcharset',

      The fixing will only be triggered by the presence of a new string in the language pack: 'localewincharsetdaymonth'. This string needs to be added as an empty string in the English language pack and as a non-empty value in the relevant language packs on sites where the fixing is required.

      During testing the last year on a live university Moode site in Japan, I have found that with the following language settings in the language pack and the modified userdate() and get_string() functions, the dates in Japanese display as requried:
      $string['localewincharset'] = '';
      $string['localewincharsetdaymonth'] = 'CP932';

      Similarly, for Chinese dates, I use:
      $string['localewincharset'] = '';
      $string['localewincharsetdaymonth'] = 'CP936';

      The same function and fix was recently confirmed for a Chinese site in Hong Kong:
      http://moodle.org/mod/forum/discuss.php?d=93697#p414588

      many thanks
      Gordon

        1. dates.chinese.gif
          dates.chinese.gif
          13 kB
        2. dates.english.gif
          dates.english.gif
          6 kB
        3. dates.japanese.gif
          dates.japanese.gif
          13 kB
        4. language.php
          16 kB
        5. MDL-14149-p.diff
          0.8 kB
        6. screenshot-1.jpg
          screenshot-1.jpg
          125 kB
        7. strftime_p_en.png
          strftime_p_en.png
          134 kB
        8. strftime_p_es.png
          strftime_p_es.png
          126 kB
        9. userdate.txt
          5 kB
        10. userdate.txt
          5 kB

            moodle.com Moodle HQ
            xxxxxxx Gordon Bateson
            Votes:
            5 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.