Ticket #2204: options.py.diff

File options.py.diff, 2.1 KB (added by Poromenos, 18 years ago)

Pluralization patch.

  • options.py

     
    4141        self.object_name = cls.__name__
    4242        self.module_name = self.object_name.lower()
    4343        self.verbose_name = get_verbose_name(self.object_name)
     44        vowels = "aeiou"
     45        consonants = "bcdfghjklmnpqrstvwxyz"
     46        # If the word ends in a 'y' and is preceded by a vowel, add 'ies'.
     47        if self.verbose_name.endswith('y') and self.verbose_name[-2] in consonants:
     48            verbose_name_plural = self.verbose_name[:-1] + 'ies'
     49        elif self.verbose_name.endswith('is'):
     50            verbose_name_plural = self.verbose_name[:-2] + 'es'
     51        elif self.verbose_name.endswith('us'):
     52            verbose_name_plural = self.verbose_name[:-2] + 'i'
     53        elif self.verbose_name.endswith('o') and self.verbose_name[-2] in consonants:
     54            verbose_name_plural = self.verbose_name + 'es'
     55        elif self.verbose_name[-2:] in ('ch', 'sh') or self.verbose_name[-1] in ('s', 'x', 'z'):
     56            verbose_name_plural = self.verbose_name + 'es'
     57        else:
     58            verbose_name_plural = self.verbose_name + 's'
    4459        # Next, apply any overridden values from 'class Meta'.
    4560        if self.meta:
    4661            meta_attrs = self.meta.__dict__
     
    5065                setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name)))
    5166            # verbose_name_plural is a special case because it uses a 's'
    5267            # by default.
    53             setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', self.verbose_name + 's'))
     68            setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', verbose_name_plural))
    5469            # Any leftover attributes must be invalid.
    5570            if meta_attrs != {}:
    5671                raise TypeError, "'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())
    5772        else:
    58             self.verbose_name_plural = self.verbose_name + 's'
     73            self.verbose_name_plural = verbose_name_plural
    5974        del self.meta
    6075
    6176    def _prepare(self, model):
Back to Top