(text, truncate=None)
| 71 | |
| 72 | |
| 73 | def add_truncation_text(text, truncate=None): |
| 74 | if truncate is None: |
| 75 | truncate = pgettext( |
| 76 | "String to return when truncating text", "%(truncated_text)s…" |
| 77 | ) |
| 78 | if "%(truncated_text)s" in truncate: |
| 79 | return truncate % {"truncated_text": text} |
| 80 | # The truncation text didn't contain the %(truncated_text)s string |
| 81 | # replacement argument so just append it to the text. |
| 82 | if text.endswith(truncate): |
| 83 | # But don't append the truncation text if the current text already ends |
| 84 | # in this. |
| 85 | return text |
| 86 | return f"{text}{truncate}" |
| 87 | |
| 88 | |
| 89 | def calculate_truncate_chars_length(length, replacement): |
no test coverage detected