Don't allow super long words if there is a word length maximum

AI-generated summary

The discussion revolves around the issue of enforcing word length limits in topic titles, particularly for non-Latin scripts like Chinese and Japanese. helperhaps reports that the TextSentinel class’s seems_unpretentious? method, which checks word length, doesn’t work well with CJK languages because they lack spaces and rely on character segmentation. Additionally, the title_max_word_length setting defaults to 0 when blank, making the check ineffective. fantasticfears explains that word segmentation for CJK is complex and context-dependent, making it impractical to enforce such checks without advanced language processing. They suggest disabling the check via locale-based settings or adding a new setting to turn it off, with the latter being preferable. helperhaps proposes checking for ASCII characters only, but fantasticfears notes this isn’t sufficient, as it doesn’t address mixed-language content and would require Unicode filtering libraries. The conversation highlights the need for better multilingual support in Discourse’s title validation system.

I got an invalid title alert when i create a topic. DIg into the code i found it raised by TextSentinel class. And I have already read this https://meta.discourse.org/t/are-very-long-words-not-allowed-in-topic-titles/29683/16. There is a related method in the class.

  def seems_unpretentious?
    # Don't allow super long words if there is a word length maximum
    @opts[:max_word_length].blank? || @text.split(/\s|\/|-|\./).map(&:size).max <= @opts[:max_word_length]
  end

I understand what it means. But for other language such as Chinese or Japanese whose word is not splited by blank or something about the patern.

Besides SiteSetting.title_max_word_length’s value is 0 when i leave it blank in the setting panel, so the expression @opts[:max_word_length].blank? is always true. it is meaningless.

My users use Chinese more, So I have to set SiteSetting.title_max_word_length as same value as SiteSetting.title_max_topic_title_length to make it work.

Is there some other way to solve it?

@fantasticfears any idea what to do here?

For CJK, it is meaningless. Word segmentation algorithm would happily chops a sentence into characters and words whenever it can. Without understanding the sentences, I’m afraid it’s not easy to identify good/bad word.

3 ways to disable it:

  1. Put some locale check
  2. Put a comment about how to disable it by setting the value to the same as topic length.
  3. Add another setting to disable it.

The latter two is much better. Although locale-based site settings should be introduced at some moment for convenience.

BTW, if my mentor @tgxworld agrees, I could ask some pointers about how this can be done at some moment in June:

How about just enabling it when all the characters in title is consisted of ASCII code?

I think would have to wait until introducing some Unicode filtering libraries instead of regex. I could take this for 1.6 and Unicode username.

It doesn’t make much sense for checking the ascii part within the Chinese sentences. The only possible use case is a multilingual forum which might need such checks based on the title sequences (still, shouldn’t look into ascii sequences in the Chinese sentences for example)