Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
When using this module for trimming text on a specified amount of words, it works only on texts with latin characters, because it uses php's str_word_count function to determine the number of words. This function does not truly support utf-8 characters.
While it's not a perfect solution for all alphabets maybe it is better to split words by a regex looking for space characters.
Comment | File | Size | Author |
---|---|---|---|
#9 | smart_trim-2268671-9.patch | 935 bytes | jigish.addweb |
#2 | smart_trim-split-words-2268671-2.patch | 952 bytes | drupov |
Comments
Comment #1
drupov CreditAttribution: drupov commentedI am adding a patch that tries to solve this. Please review. Thanks!
Comment #2
drupov CreditAttribution: drupov commentedJust saw that the module is using preg_split to put the words into an array on order to trim it, so why not reuse this logic for the count of words too.
I am updating the patch to use that logic.
Comment #3
judapriestHello,
Could you provide a example of what you mean by "latin characters" and "utf-8 characters" ? Because your patch seems to be fine, but without it, it seems to work fine too (I do prefer your version with preg_split :p). But I think with preg_split you should also take into account returns (\n\r, \n).
Here how I did my test , http://generator.lorem-ipsum.info/ :
- Cyrillic
- Hindi
- Japanese
I tested smart trim with those 3 languages, on a fresh drupal 7.30 and simplytest.me, with lastest dev version (Note that japanese don't have much space when written). Cannot reproduce your probleme for now.
Comment #4
Jieyyal CreditAttribution: Jieyyal commentedDo not work with Chinese, number, symbol mixed string!
Comment #5
Bensbury CreditAttribution: Bensbury as a volunteer commentedDoesn't word with Japanese - it won't obey the trim length for character or word.
Fresh Drupal 7.38
-- Patch worked by the way.
Comment #6
egontinno CreditAttribution: egontinno commentedPatch #2 also needed for Russian text.
Comment #7
RogerRogers CreditAttribution: RogerRogers commentedThis patch doesn't apply cleanly any longer. However, I've manually applied the lines and can confirm this works. It would be great if this can make it into the release cycle because it is required for non latin languages, in this case Persian.
Comment #8
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 5 year old patch in #2 to smart_trim.module does not apply to the latest smart_trim 7.x-1.x-dev and needs to be re-rolled.
Comment #9
jigish.addweb CreditAttribution: jigish.addweb at AddWeb Solution Pvt. Ltd. commented@Chris Matthews, Here's the patch on the same kindly review it.
Comment #10
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commented