On Mon, May 5, 2008 at 8:20 AM, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
wrote:

>
> Thank you for your replies.
>
> Just to confirm, I am not referring to a perfect automatic pluralize
> solution. I am very well aware that a silver bullet solution would be
> very difficult, if even possible.
>
> I will try make myself more clear now. What I am specifically
> referring to is the 'verbose_name_plural' of the model.
> This is what I have in mind:
> 1. Django initializes (contributes) the 'verbose_name_plural' on model
> class with a call to the pluralize logic to attempt find the relevant
> plural for the given singular.
> 2. If need be, developer overrides the 'verbose_name_plural' in the
> model to define specialized plural.


So you still need to allow for the developer (me) to override the generated
plural.  Only now it isn't as clear when I need to do that.  With the
current rule, it is straightforward: if the word isn't pluralized by adding
an 's', I need to provide the proper plural myself.  With this proposal, I
have no idea under what circumstances I need to provide the plural.  Seems
like I have to go look at the pluralization rules file and try to figure out
if my exception is covered.  Or just try it out with the default and see if
it comes out right.  Both seem like more work, and more error-prone, than
just providing the proper plural if it isn't formed by adding an 's'.

Karen



> 3. Developer calls model_obj.verbose_name_plural in template.
>
> Here is an example adapted from the "Diving into Python" book
> regarding the pluralization that I have in mind:
>
> ######### plural.py #########
> import re
>
>
> def _regex_rules(lang):
>    rules_file = file("manager/pluralrules/%s" % lang)
>    for line in rules_file:
>        pattern, search, replace = line.split()
>        yield lambda word: re.search(pattern, word) and re.sub(search,
> replace, word)
>    rules_file.close()
>
>
> def pluralize(noun, lang='en'):
>    """Returns a plural of a given noun"""
>    for rule in _regex_rules(lang):
>        result = rule(noun)
>        if result: return result
>
> ######### end - plural.py #########
>
> ######### ./pluralrules/en #########
> [ml]ouse$               ([ml])ouse$     \1ice
> child$                  child$          children
> booth$                  booth$          booths
> foot$                   foot$           feet
> ooth$                   ooth$           eeth
> l[eo]af$                l([eo])af$      l\1aves
> sis$                    sis$            ses
> man$                    man$            men
> ife$                    ife$            ives
> eau$                    eau$            eaux
> lf$                     lf$             lves
> [sxz]$                  $               es
> [^aeioudgkprt]h$        $               es
> (qu|[^aeiou])y$         y$              ies
> $                       $               s
> ######### end - ./pluralrules/en #########
>
> Change in the Django code
>
> ######### django/db/models/options.py ##########
> Replace:
> -------------------
> setattr(self, 'verbose_name_plural',
> meta_attrs.pop('verbose_name_plural', string_concat(self.verbose_name,
> 's')))
>
> With something like:
> -------------------
> setattr(self, 'verbose_name_plural',
> meta_attrs.pop('verbose_name_plural', pluralize(self.verbose_name,
> get_locale_code())))
>
> *Note: get_locale_code() would return the current locale code (e.g.
> 'en' for English).
>
> #############################################
>
> As you can see in the django/db/models/options.py, a model class
> contribution is made by adding the attribute 'verbose_name_plural'
> with a simple 's' character append logic.
> I believe we can handle more than just 's' on initialization with a
> similar example as above. (Was very tempted to use the word 'simple'
> again. Can't stand the heat though. :-))
>
> Regards,
> -Alen Ribic
>
>
> On May 5, 4:57 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
> wrote:
> > On Mon, May 5, 2008 at 1:16 AM, [EMAIL PROTECTED]
> >
> > <[EMAIL PROTECTED]> wrote:
> >
> > >  > Is it?  Maybe.  I don't know if anyone has proposed smartening-up
> Django's
> > >  > pluralization rules in the past
> >
> > >  I had a look through the mailing-list archive and couldn't spot
> > >  anything directly related.
> >
> > Then you haven't looked too hard. Pluralization comes up regularly,
> > both in the context of the pluralize filter, and the
> > verbose_name/verbose_name_plural option. And if you're calling
> > pluralization a simple task, you _really_ haven't done your research.
> >
> > The short version is that pluralization is _hard_. Automatic
> > pluralization, which seems to be what you want, is an effectively
> > impossible task, especially in English. English doesn't have regular
> > rules for pluralization for anything but trivial cases. About the only
> > way to do it effectively is to have a dictionary of all possible
> > plurals - and then you hit the religious wars over whether the plural
> > of octopus is octopus, octopuses, or octopodes.
> >
> > Even if you could get English sorted out, then you get the i18n
> > problem. A few eastern European languages have some very interesting
> > pluralization rules which further complicates the dream of an
> > automatic solution.
> >
> > So, we have settled with the a naive solution, manually assisted, with
> > template helpers that cover 95% of cases. "Add an s" works for a good
> > majority of cases - if that isn't correct, you can manually correct it
> > in verbose_name_plural. The template filter can handle all the english
> > cases (worst case being different extensions for 1 and many). This
> > doesn't cover the needs of the previously mentioned eastern European
> > languages, but accommodating those languages while keeping the simple
> > case simple is almost impossible, so users of those languages can
> > write a custom template tag if they need one.
> >
> > Yours,
> > Russ Magee %-)
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to