-
Notifications
You must be signed in to change notification settings - Fork 134
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
Words counting issue for mixed languages #21
Comments
This is a tough one. I've been reading through TryGhost/Ghost#2656 and cgiffard/Downsize#15 and this stuff just completely blows my mind. I don't speak any non-latin language so I will need all the help I can get on this one. I'll keep up with the two issues mentioned above and I will do my best to figure out a usable solution. |
Hi, not sure if you come up with a solution or not. but I've done a small quick fix for at least Chinese language, you can have a look at here: https://github.com/iamzifei/gust/blob/master/assets/countable.js |
Thanks for the input. It looks quite interesting, but could you please explain how your solution works exactly? |
Hi, it's a little bit tricky and not quite completed actually, but hopefully could give some ideas here. so I defined 3 regex for different unicode range, for asian languages. I replace r1, r2, r3 with one English word. the rest is counting as it is. so 敏捷的棕毛 will become " {CJK} {CJK} {CJK} {CJK} {CJK} ", which would count as 5 words. some references: |
see how they did this https://github.com/AAlakkad/jQuery-smsHelper/blob/master/jquery-smshelper.js any jQuery support ? |
It is very common that we could have content of mixed languages such as a paragraph mixed of English and Chinese. A big difference of counting English and CJK words is that CJK does not separate words with spaces (actually "word" and "character" are the same concept in CJK) but they are just adjacent.
For example
The quick brown fox jumps over the lazy dog will be counted as 9 words.
The Chinese translation of that sentence is 敏捷的棕毛狐狸从懒狗身上跃过 it should be counted as 14 words, but the actual result is 1.
This results the issue like TryGhost/Ghost#2656 when writing a blog post of mixed languages.
The text was updated successfully, but these errors were encountered: