Heuristic:AI Builder Club Skills CJK Text Detection
| Knowledge Sources | |
|---|---|
| Domains | Subtitling, Internationalization |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Detect CJK (Chinese/Japanese/Korean) characters in text to switch between space-separated and no-space word grouping for caption rendering.
Description
CJK languages do not use spaces between words, while Latin/Cyrillic scripts do. When generating karaoke captions or wrapping text in diagrams, the word separator must adapt: CJK text uses an empty string separator, while Latin text uses a space. Without detection, CJK phrases would either have artificial spaces inserted (breaking readability) or Latin phrases would be concatenated without spaces (illegible). The detection uses Unicode range checks for CJK ideographs and Hiragana/Katakana.
Usage
Apply this heuristic when generating ASS subtitles (gen_ass.py) or wrapping text in diagram rendering (render_animated_gif.py). Use whenever text from multiple languages may be processed and the separator behavior must adapt automatically.
The Insight (Rule of Thumb)
- Action: Check if text contains characters in CJK Unicode ranges before choosing a separator.
- Value:
gen_ass.py:sep = "" if is_cjk(all_text) else " "— no space between CJK words, space between Latin words.render_animated_gif.py:separator = "" if contains_cjk(text) else " "for text wrapping;tokens = list(text) if contains_cjk(text) else text.split()for tokenization.
- Trade-off: Unicode range check is fast but may miss rare CJK extension blocks; the ranges checked cover the most common blocks (U+3400–U+9FFF, U+3040–U+30FF).
- Tokenization: CJK text is tokenized character-by-character (
list(text)); Latin text is tokenized by whitespace (text.split()).
Reasoning
CJK languages (Chinese, Japanese, Korean) do not use spaces as word delimiters — words and characters flow together. Inserting spaces between CJK words in captions would break the visual flow and readability. Conversely, not inserting spaces between Latin words would make them illegible. The Unicode ranges checked are: CJK Unified Ideographs (U+3400–U+9FFF, covering both Extension A and the main block) and Japanese kana (U+3040–U+30FF, covering Hiragana and Katakana). This covers the vast majority of CJK text in practice.