Format internal topic keys into user-facing labels.
(direction: str)
| 183 | |
| 184 | |
| 185 | def format_direction_label(direction: str) -> str: |
| 186 | """Format internal topic keys into user-facing labels.""" |
| 187 | formatter = getattr(direction_lexicon, "format_direction_label", None) |
| 188 | if callable(formatter): |
| 189 | return str(formatter(direction, prefer_chinese=True) or direction) |
| 190 | entry = get_direction_entry(direction) |
| 191 | if entry: |
| 192 | return str(entry.get("name_cn") or entry.get("name") or direction) |
| 193 | if direction in DIRECTION_TRANSLATIONS: |
| 194 | return DIRECTION_TRANSLATIONS[direction] |
| 195 | if any(separator in direction for separator in ("-", "_")): |
| 196 | return direction.replace("_", " ").replace("-", " ").title() |
| 197 | if re.fullmatch(r"[a-z0-9]+", direction): |
| 198 | return direction.upper() if len(direction) <= 4 else direction.title() |
| 199 | return direction |
| 200 | |
| 201 | |
| 202 | def is_displayable_author_name(author_name: str) -> bool: |
no test coverage detected