Contents

Hugo | Wrong Wordcount with Chinese in Posts (#.WordCount)

isnanx commented on 30 Apr 2019

Hi, as I write both Chinese and English in my posts, I found it that Chinese characters were not included when counting the words, I doubt if there is something wrong of my usage or it’s truly not supported by now, any reference? Thanks.

Chinese characters may not supported by variable Wordcount · Issue #5913 · gohugoio/hugo (github.com)

Solution Found

It’s really simple. Just configure the value of hasCJKLanguage to true (default is false ).

hasCJKLanguage

Default value: false

If true, auto-detect Chinese/Japanese/Korean Languages in the content. This will make .Summary and .WordCount behave correctly for CJK languages.

https://miro.medium.com/max/1400/1*YPAsbSKUwYEIV98Y2YZ3vw.png

Example: 新南向國家見實習-新飛菲律賓遊學行銷企劃 HsinFei intern in The Philippines — Hung, Chien-Hsiang 洪健翔 | Blog (chienhsiang-hung.github.io)

See: Configure Hugo | Hugo (gohugo.io)

When we work with strings in Hugo, we often want to get some basic information like its length. We can then show that information in our theme for readers or use it with other string operations. Let’s see how we can measure the length of text in Hugo.

3 ways to get the length of a string of text in Hugo

More

Hugo’s word count is wrong in the HTML content written in Japanese even if hasCJKLanguage is true. · Issue #9335 · gohugoio/hugo (github.com)