MCPcopy
hub / github.com/django/django / add_truncation_text

Function add_truncation_text

django/utils/text.py:73–86  ·  view source on GitHub ↗
(text, truncate=None)

Source from the content-addressed store, hash-verified

71
72
73def 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
89def calculate_truncate_chars_length(length, replacement):

Callers 4

handle_dataMethod · 0.85
_text_charsMethod · 0.85
_text_wordsMethod · 0.85

Calls 1

pgettextFunction · 0.90

Tested by

no test coverage detected