Excerpt not properly working with Chinese content

I am currently trying to get an excerpt from Chinese content but this is not working (working for English content, though)… For Chinese, it is either showing the full length text or none.

I found this entry with a similar issue but am working with Kirby 3.

Any suggestions for fixing this problem?

Could you post your excerpt() method and locale settings please?

Sure

$block->bodytext()->excerpt(150)->kt()

As mentioned before this works fine for the English texts but not Chinese.

Also it is behaving differently for different posts… Some posts will give me no Chinese text at all, others will just give me the whole text instead of an excerpt.

excerpt() method makes shortening process according to the gaps/spaces between words. There is no space between words in Chinese, I guess, right?

According to this link it is cutting between characters: https://getkirby.com/docs/reference/templates/field-methods/excerpt

Is there any way to make it work with Chinese texts?

It is shortened by spaces with counting chars to make it look more meaningful when cut. If there is no space in your sentence, it will not be able to abbreviate. Is there no space between words in Chinese?

No, there are no spaces in Chinese

Maybe you can use Str::short() instead? https://getkirby.com/docs/reference/tools/str/short

1 Like

If there is no space, definitely the solution short() method as @texnixe said. Also you can use with $field

You can try following line:

$block->bodytext()->short(150)->kt();

$field->short() works like a charm!