Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-English word count is wrong (possibly) #11

Closed
mrNo0b opened this issue Sep 18, 2018 · 3 comments
Closed

Non-English word count is wrong (possibly) #11

mrNo0b opened this issue Sep 18, 2018 · 3 comments

Comments

@mrNo0b
Copy link

mrNo0b commented Sep 18, 2018

I have Hebrew text on my page, after debugging this line (ln 36 in classes/TwigReadingTimeFilters.php)
$words = str_word_count(strip_tags($content));
I found out that when I remove the strip_tags method it will give differnt (much more realistic) word count
so for one of the pages I tested it on I had:
12 - with strip_tags()
126 - without strip_tags()
I don't know if there is something wrong with my site language setup or something,
but maybe you can check the plugin...
if you need, here is a Hebrew Lorem Ispum text

btw, here is the Hebrew translation strings:

he:
  PLUGIN_READINGTIME:
    SECOND: שניה
    SECONDS: שניות
    MINUTE: דקה
    MINUTES: דקות
@oleg-sh
Copy link

oleg-sh commented Dec 10, 2018

Doesn't work for Russian either. It shows 347 word page as 0 minutes 3 seconds.

I'm not familiar with php but I was able to find a workaround.
I replaced:
$words = str_word_count(strip_tags($content));
with:
$words = count(preg_split('/\s+/', strip_tags($content)));

@stephengmatthews
Copy link
Contributor

Fix suggested by @oleg-sh appears in current release (1.3.0).

@rhukster
Copy link
Member

1.4.0 released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants