|
47 | 47 | import copy |
48 | 48 | import html.entities |
49 | 49 | import re |
| 50 | +import warnings |
50 | 51 | from html.parser import HTMLParser |
51 | 52 |
|
52 | 53 | from cloudbot.util.colors import strip_irc |
@@ -247,11 +248,65 @@ def pluralize(num=0, text=''): |
247 | 248 | Takes a number and a string, and pluralizes that string using the number and combines the results. |
248 | 249 | :rtype: str |
249 | 250 | """ |
250 | | - return "{:,} {}{}".format(num, text, "s"[num == 1:]) |
| 251 | + warnings.warn( |
| 252 | + "formatting.pluralize() is deprecated, please use one of the other formatting.pluralize_*() functions", |
| 253 | + DeprecationWarning |
| 254 | + ) |
| 255 | + return pluralize_suffix(num, text) |
251 | 256 |
|
252 | 257 |
|
253 | | -# alternate form |
254 | | -pluralise = pluralize |
| 258 | +def pluralise(num=0, text=''): |
| 259 | + """ |
| 260 | + Takes a number and a string, and pluralizes that string using the number and combines the results. |
| 261 | + :rtype: str |
| 262 | + """ |
| 263 | + warnings.warn( |
| 264 | + "formatting.pluralise() is deprecated, please use one of the other formatting.pluralise_*() functions", |
| 265 | + DeprecationWarning |
| 266 | + ) |
| 267 | + return pluralise_suffix(num, text) |
| 268 | + |
| 269 | + |
| 270 | +def pluralize_suffix(num=0, text='', suffix='s'): |
| 271 | + """ |
| 272 | + Takes a number and a string, and pluralizes that string using the number and combines the results. |
| 273 | + :rtype: str |
| 274 | + """ |
| 275 | + return pluralize_select(num, text, text + suffix) |
| 276 | + |
| 277 | + |
| 278 | +pluralise_suffix = pluralize_suffix |
| 279 | + |
| 280 | + |
| 281 | +def pluralize_select(count, single, plural): |
| 282 | + return "{:,} {}".format(count, single if count == 1 else plural) |
| 283 | + |
| 284 | + |
| 285 | +pluralise_select = pluralize_select |
| 286 | + |
| 287 | + |
| 288 | +def pluralize_auto(count, thing): |
| 289 | + if thing.endswith(('s', 'ss', 'sh', 'ch', 'x', 'z')): |
| 290 | + return pluralize_suffix(count, thing, 'es') |
| 291 | + elif thing.endswith(('f', 'fe')): |
| 292 | + return pluralize_select(count, thing, thing.rsplit('f', 1) + 'ves') |
| 293 | + elif thing.endswith('y') and thing[-2:-1].lower() not in "aeiou": |
| 294 | + return pluralize_select(count, thing, thing[:-1] + 'ies') |
| 295 | + elif thing.endswith('y') and thing[-2:-1].lower() in "aeiou": |
| 296 | + return pluralize_suffix(count, thing) |
| 297 | + elif thing.endswith('o'): |
| 298 | + return pluralize_suffix(count, thing, 'es') |
| 299 | + elif thing.endswith('us'): |
| 300 | + return pluralize_select(count, thing, thing[:-2] + 'i') |
| 301 | + elif thing.endswith('is'): |
| 302 | + return pluralize_select(count, thing, thing[:-2] + 'es') |
| 303 | + elif thing.endswith('on'): |
| 304 | + return pluralize_select(count, thing, thing[:-2] + 'a') |
| 305 | + else: |
| 306 | + return pluralize_suffix(count, thing) |
| 307 | + |
| 308 | + |
| 309 | +pluralise_auto = pluralize_auto |
255 | 310 |
|
256 | 311 |
|
257 | 312 | def dict_format(args, formats): |
|
0 commit comments