Open newjie opened 7 years ago
It's calling Joomla's JHtmlString::truncate()
with proper parameters (noSplit being true, other ones coming from the parameters). Looks fine to me.
With it always being true in Gantry's truncate function, users don't have a say about to split words or not, unless they modify the body of Platform.truncate(). Why shouldn't it be a problem?
It is fine with English text. But in Chinese text, which don't use space to split words, this function considers a whole passage to be one word, and the $length parameter will be of no use - while users expect this function to truncate a certain number of characters, it always truncate the characters before first space character, which will usually be the passage separator.
It looks that Gantry behavior is identical to Joomla. Joomla does not truncate Chinese properly either as it calls the truncate identically to what Gantry does. I'm wondering if there is a way to figure out languages which do not use spaces to separate words...?
Did some digging in Joomla and it looks like Joomla only truncates folders and filenames with the $noSplit = false
option turned on. Also, there's no way to detect languages like this...
The issue here is that either the feature is broken in one set of languages or in another.
Yes, I think this is essentially a Joomla issue. I am surprised that there is still no fix for this - With "$noSplit" being true, Joomla's truncate will always look for a space in the string. If there is no space, then it will return "..." (due /libraries/cms/html/string.php line 80-83):
$offset = StringHelper::strrpos($tmp, ' ');
if ($offset === false && strlen($text) > $length)
{
return '...';
}
In the above code, if no space, $offset = false.
Or did I miss anything here? I am gonna report this to Joomla anyway.
On the other hand, if I go to Gantry's Platform.php and edit line 453 to
return \JHtml::_('string.truncate', $text, $length, false, $html);
Chinese strings will be correctly trimmed. And as far as I can see, the only sacrifice is that some words in English text may be cut off by half, which is tolerable by me. Is this a good solution?
Actually, on second thought, Joomla does provide a solution, which is to set $noSplit to be false. But in Gantry, this has been prohibited unless I edit Platform.php.
Pulling this issue up in the list as a bug.
This is gantry's version of truncate:
And this is Joomla's:
public static function truncate($text, $length = 0, $noSplit = true, $allowHtml = true)
I am still working on it but I think this could be the reason why in my particle Chinese contents are not truncated correctly.