Code

Opened 7 years ago

Last modified 16 months ago

#5518 new Cleanup/optimization

Capitalized verbose names for models

Reported by: Petr Marhoun <petr.marhoun@…> Owned by: nobody
Component: Internationalization Version: newforms-admin
Severity: Normal Keywords: admin, verbose_name, nfa-someday i18n-nofix
Cc: djbenji@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

There is a difference between models and forms, now the preferred format is:

class Contact(models.Model):
    email = models.CharField(verbose_name=_('email'))

class ContactForm(forms.Form):
    email = forms.CharField(label=_('Email'))

Why is once 'email' and once 'Email'? I think it is quite
inconsistent.

But it is specially bad for translators. Example: I have a model with
ten fields. I use form_for_model and form_for_instance. I realize that
I need a form with seven fields from model and some new fields. So I
have to translate the fields again - gettext doesn't know that 'email'
is similar to 'Email'.

I think it should be possible (not necessary) to use capitalized
verbose names in models. It means to uncapitalized some words in admin

  • but it is possible, I do it in my personal branch.

I thought that this kind of change should be sent to django-developers mailing list first. But there was no answer so there is a ticket.

Ticket #5426 is precondition for it.

I would like to create patch - if you think that it can be applied.

Attachments (1)

05-uncapfirst-verbose-name.diff (14.2 KB) - added by Petr Marhoun <petr.marhoun@…> 7 years ago.

Download all attachments as: .zip

Change History (21)

comment:1 Changed 7 years ago by ubernostrum

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 7 years ago by anonymous

  • Cc djbenji@… added

Changed 7 years ago by Petr Marhoun <petr.marhoun@…>

comment:3 Changed 7 years ago by Petr Marhoun <petr.marhoun@…>

Support for capitalized and uncapitalized verbose names means that everywhere in admin have to be used with capfirst or with uncapfirst.

I am sorry, my patch depends on some other patches - it is for simple merging. So my patch can't be applied without problem. But I would like to prepare proper patch, if it would be accepted.

comment:4 follow-up: Changed 7 years ago by jkocherhans

  • Resolution set to wontfix
  • Status changed from new to closed

While I agree that _('Email') and _('email') is inconsistent, I don't see _('Email') anywhere in Django's code. What's preventing you from using the lower filter where you need it, or using all lowercase in your code? Enforcing capitalization in other people's code is none of Django's business. Is there any specific code in Django itself that you find inconsistent? If so, please open new tickets regarding those inconsistencies.

comment:5 in reply to: ↑ 4 Changed 7 years ago by Petr Marhoun <petr.marhoun@…>

  • Resolution wontfix deleted
  • Status changed from closed to reopened

Replying to jkocherhans:

What's preventing you from using the lower filter where you need it, or using all lowercase in your code?

  1. Can I use "capfirst" verbose_name in my models? No, I can't - django.contrib.admin is broken in this situation. Try to use it in your models and check titles and messages in admin.
  1. Can I use "uncapfirst" labels in my forms? No, I can't - django.contrib.admin is broken again. Try to return a field with low first letter from ModelAdmin.formfield_for_dbfield (only an example, there are many methods how to use your own formfields in admin) and check labels in admin. It also breaks some utility functions from core (for example BaseForm.as_table).

(When I say "broken" I mean it doesn't look nice.)

I don't know if I can reopen the ticket it this situation (I am sorry if I can't), but I disagree with your arguments. Application django.contrib.admin prevents me to be consistent in my own code - so I want to fix the application. (This ticket is not about django core.)

Maybe the resolution is right (I only say that arguments for this resolution aren't right). But I think that django.contrib.admin do some magic anyway - what if I want to have titles in admin with first letter low (an example - class eCommerceType)? I only ask you for a little more - it should'n hurt anyone and it could help some people.

Enforcing capitalization in other people's code is none of Django's business.

This change enforces nothing. On the contrary - now django.contrib.admin enforces not to use capitalization. With this patch django.contrib.admin don't care what other people choose.

comment:6 follow-up: Changed 7 years ago by Christopher Lenz <cmlenz@…>

If I understand this patch correctly, this would break languages where nouns are capitalized even inside sentences, such as German.

comment:7 in reply to: ↑ 6 ; follow-up: Changed 7 years ago by mir

Replying to Christopher Lenz <cmlenz@gmx.de>:

If I understand this patch correctly, this would break languages where nouns are capitalized even inside sentences, such as German.

Yes. And I doubt that every language uses capitalization in field labels. A clean solution might require:

  • verbose names be always the "raw" forms, e.g. for English lower case, for German dependant on the category (nouns are upper case)
  • a filter tag label that converts the raw form into the label form. For the languages I know, this is the same as firstcap.

comment:8 in reply to: ↑ 7 Changed 7 years ago by jkocherhans

Replying to mir:

Yes. And I doubt that every language uses capitalization in field labels. A clean solution might require:

  • verbose names be always the "raw" forms, e.g. for English lower case, for German dependant on the category (nouns are upper case)
  • a filter tag label that converts the raw form into the label form. For the languages I know, this is the same as firstcap.

Thanks mir. That sounds like a much more acceptable and flexible solution to me. Petr, would you mind starting a thread on django-i18n about this? I'm sure other languages have different capitalization issues that should be addressed as part of this ticket.

comment:9 Changed 7 years ago by Petr Marhoun <petr.marhoun@…>

I don't understand I didn't think about it. (My applications are only bilingual, but German is the most probable third language). So my solution is bad but opposite approach should work - to use "uncapfirst" expressions for labels.

I think there are two orthogonal problems:

  1. It should be possible to use the same format in models and forms - django.contrib.admin and some utility functions in core should transform it to the right format.
  2. The transformation function should work for all languages, not only for most of them.

I will try to solve point one. I want to change my verbose_name and labels to have first letter low and to fix all problems with capfirst.

The second idea (to replace capfirst with something better) is quite ambitious. I don't think that django supports localized functions and filters. Maybe mir should post to django-i18n - for me the current task is patch for problem one.

comment:10 Changed 7 years ago by jkocherhans

  • Keywords verbose_name, nfa-someday added; verbose_name removed

Marking as nfa-someday as this isn't blocking a merge of the newforms-admin branch to trunk. This ticket should be closed as wontfix at the next sprint unless someone figures out an acceptable design though.

comment:11 Changed 6 years ago by mtredinnick

The patch here isn't the right solution to any problem. For consistency and eas of use, verbose names should be in the non-title-case format (lower-case for most languages, probably initial upper case for German, etc). Then places like admin can use the capfirst filter on headings that may start with a model name. That's fixing things in the right place (the same sort of thing as the patch in #5519, which does look like it's solving the root problem).

comment:12 Changed 6 years ago by Petr Marhoun <petr.marhoun@…>

  • Resolution set to invalid
  • Status changed from reopened to closed

I think this problem is real - but more general. It is problem in all forms, not only in forms from admin. And I have created another ticket which could solved it - #6631. So I think this ticket is invalid and it should be closed.

comment:13 Changed 6 years ago by mtredinnick

  • Resolution invalid deleted
  • Status changed from closed to reopened

This ticket isn't invalid, since it describes quite a valid issue. Perhaps you meant "duplicate", but I'm going to reopen it all the same. This ticket describes a particular issue, #6631 describes a complex solution to a sort of related problem. I'm not convinced that #6631 really is the right solution to the problems it's solving, so I think that deferring this ticket's solution to that one is premature for now. We have the link between the two tickets now, so anybody looking at this will do so considering #6631 as well, but I'd like to keep this open until we have a solution in place, pleaes.

comment:14 Changed 5 years ago by garcia_marc

  • Keywords i18n-nofix added

comment:15 Changed 4 years ago by mtredinnick

  • Triage Stage changed from Design decision needed to Accepted

Design decision (after much discussion between jezdez, Russ and myself): whenever the verbose name on a model or form field is specified, we should not run the result through the capfirst filter. If we are auto-generating the label string, we should be using the equivalent of capfirst.

This is not going to be entirely simple to implement, since it moves the capfirst-ing out of the template into the form data generation, perhaps. But it's the only backwards-incompatible, let everything be possible solution we can find that is likely to work.

comment:16 Changed 3 years ago by jezdez

  • Summary changed from [newform-admin] - capitalized verbose names for models to Capitalized verbose names for models

comment:17 Changed 3 years ago by gabrielhurley

  • Severity set to Normal
  • Type set to Cleanup/optimization

comment:18 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:19 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:20 Changed 16 months ago by aaugustin

  • Status changed from reopened to new

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.