>>> 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"))
| 280 | |
| 281 | @keep_lazy_text |
| 282 | def 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 |
no test coverage detected