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

reading_time helper doesn't work with Chinese #9507

Closed
xiaochunjimmy opened this issue Mar 15, 2018 · 5 comments · Fixed by #9509
Closed

reading_time helper doesn't work with Chinese #9507

xiaochunjimmy opened this issue Mar 15, 2018 · 5 comments · Fixed by #9509
Assignees
Labels
bug [triage] something behaving unexpectedly help wanted [triage] Ideal issues for contributors to help with server / core Issues relating to the server or core of Ghost

Comments

@xiaochunjimmy
Copy link

xiaochunjimmy commented Mar 15, 2018

Issue Summary

reading_time helper does not work with Chinese.
It may always be "<1 min read"

Steps to Reproduce

  1. As I know the reading time helper is count by spaces and count by words.But in Chinese we use characters rather than words.

2.In Chinese we seldom use spaces to separate words. An Chinese word is consists of characters, we use words to express our thoughts but we write with characters.So we should count characters for Chinese reading time.

For example:
我今天在家吃了好多好多好吃的,现在的我非常开心非常满足。
This Chinese sentence contains 26 characters and 2 punctuations.
But ghost reading_time helper count it as 2 words may be.
So may be an 4000 Chinese Characters article shows "<1 min read" ,but we use about 10min to read actually.

3.Ghost reading helper might accept a parameter to count characters for Chinese.
here's a regex to count Chinese:

var reg = /[\u4e00-\u9fa5]/g;
var str = "js计算一段文本中有多少个汉字?";
console.debug(str.match(reg).length);

As I know there's other language use characters, such as Japanese.

Technical details:

  • Ghost Version: 1.21.4
  • Node Version:
  • Browser/OS:
  • Database:
@aileen aileen added i18n server / core Issues relating to the server or core of Ghost help wanted [triage] Ideal issues for contributors to help with labels Mar 16, 2018
@aileen
Copy link
Member

aileen commented Mar 16, 2018

This is something that is not yet implemented, as there is need to find a solution that works for latin languages as well as asian languages such as Chinese.

We're happy for PRs here to solve this issue!

@xiaochunjimmy
Copy link
Author

image
In fact,I found that the words counting function works good for Chinese.
We can use the number in the picture(in red rectangle)directly for Chinese word counting.
Chinese people 's read speed is 300-500 Characters(words) per min.

@kirrg001 kirrg001 added the bug [triage] something behaving unexpectedly label Mar 16, 2018
@kirrg001
Copy link
Contributor

@AileenCGN The comment in the word count utility says

This is the same code as used on the client side. See here:
/core/client/app/utils/word-count.js

I wonder why the result is different? 🤔

@rkalis
Copy link
Contributor

rkalis commented Mar 16, 2018

I think the client word-count.js is unused. The Markdown editor uses simpleMDE's wordcount function. Any objections to using that implementation in the server wordCount? I can raise a PR for that when I get home tonight.

@ErisDS
Copy link
Member

ErisDS commented Mar 16, 2018

Sounds good- should prob remove it from client as well!

kevinansfield pushed a commit to TryGhost/Admin that referenced this issue Mar 19, 2018
issue TryGhost/Ghost#9507
- Removed unused wordCount utility
aileen pushed a commit that referenced this issue Mar 22, 2018
closes #9507

- Changed the utils.wordCount implementation to the one used by simpleMDE
- Added extra À-ÿ to the regex to support diacritics characters
- Added corresponding text with Chinese text mentioned in the issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [triage] something behaving unexpectedly help wanted [triage] Ideal issues for contributors to help with server / core Issues relating to the server or core of Ghost
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants