MCPcopy
hub / github.com/django/django / get_text_list

Function get_text_list

django/utils/text.py:282–304  ·  view source on GitHub ↗

>>> get_text_list(['a', 'b', 'c', 'd']) 'a, b, c or d' >>> get_text_list(['a', 'b', 'c'], 'and') 'a, b and c' >>> get_text_list(['a', 'b'], 'and') 'a and b' >>> get_text_list(['a']) 'a' >>> get_text_list([]) ''

(list_, last_word=gettext_lazy("or"))

Source from the content-addressed store, hash-verified

280
281@keep_lazy_text
282def get_text_list(list_, last_word=gettext_lazy("or")):
283 """
284 >>> get_text_list(['a', 'b', 'c', 'd'])
285 'a, b, c or d'
286 >>> get_text_list(['a', 'b', 'c'], 'and')
287 'a, b and c'
288 >>> get_text_list(['a', 'b'], 'and')
289 'a and b'
290 >>> get_text_list(['a'])
291 'a'
292 >>> get_text_list([])
293 ''
294 """
295 if not list_:
296 return ""
297 if len(list_) == 1:
298 return str(list_[0])
299 return "%s %s %s" % (
300 # Translators: This string is used as a separator between list elements
301 _(", ").join(str(i) for i in list_[:-1]),
302 str(last_word),
303 str(list_[-1]),
304 )
305
306
307@keep_lazy_text

Callers 6

hand_clean_DELETEMethod · 0.90
get_change_messageMethod · 0.90
handleMethod · 0.90
invalid_block_tagMethod · 0.90
unique_error_messageMethod · 0.90

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected