Moodle

function shorten_text fails in languages without latin spaces or periods

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.5.2
  • Fix Version/s: 1.8.4, 1.9, 2.0
  • Component/s: General
  • Labels:
    None
  • Environment:
    All
  • Affected Branches:
    MOODLE_15_STABLE
  • Fixed Branches:
    MOODLE_18_STABLE, MOODLE_19_STABLE, MOODLE_20_STABLE

Description

function shorten_text creates very long lines in Japanese (unicode), probably because there are no latin style spaces or periods. $stopzone is looking for space or periods to determin where to truncate the text, but there are none, so it ends up including the entire original text.

The extremely long lines creates a rather serious interface problem in the assignment module. (online assignments; online/assignments.class.php)

http://moodle.cvs.sourceforge.net/moodle/moodle/lib/moodlelib.php

line 5430

Activity

Hide
Martin Dougiamas added a comment -

From Paul Shew (thetrinity at shew.jp) Friday, 30 September 2005, 04:32 PM:

I made a temporary, rough fix for my site (which is all Japanese) by changing the last line of the function as follows.

Here's the original return line:

return substr($text, 0, $truncate).$ellipse;

Here's my greatly simplified solution with a unicode-safe cutoff at the ideal point.

return mb_substr($text, 0, $ideal).$ellipse;

Of course, this renders the function useless for its original intention, but for other sites in languages like Japanese, it is a quick fix.

From Paul Shew (thetrinity at shew.jp) Saturday, 1 October 2005, 10:09 AM:

Haruhiko Okumura in the Japanese forum, suggests this solution:

I couldn't reproduce the bug so I'm not sure if this helps; my idea is to change

if ($char == '.' or $char == ' ')

to

if ($char == '.' or $char == ' ' or $char >= 0x80)

and

substr($text, 0, $truncate)

to

mb_strcut($text, 0, $truncate, get_string(thischarset))

Show
Martin Dougiamas added a comment - From Paul Shew (thetrinity at shew.jp) Friday, 30 September 2005, 04:32 PM: I made a temporary, rough fix for my site (which is all Japanese) by changing the last line of the function as follows. Here's the original return line: return substr($text, 0, $truncate).$ellipse; Here's my greatly simplified solution with a unicode-safe cutoff at the ideal point. return mb_substr($text, 0, $ideal).$ellipse; Of course, this renders the function useless for its original intention, but for other sites in languages like Japanese, it is a quick fix. From Paul Shew (thetrinity at shew.jp) Saturday, 1 October 2005, 10:09 AM: Haruhiko Okumura in the Japanese forum, suggests this solution: I couldn't reproduce the bug so I'm not sure if this helps; my idea is to change if ($char == '.' or $char == ' ') to if ($char == '.' or $char == ' ' or $char >= 0x80) and substr($text, 0, $truncate) to mb_strcut($text, 0, $truncate, get_string(thischarset))
Hide
Yu Zhang added a comment -

This has been fixed some time ago.

Show
Yu Zhang added a comment - This has been fixed some time ago.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: