Blocktranslate setting to default to trimmed

Hi,

I recently discovered the {% blocktranslate trimmed %} option to strip extra whitespace from strings in html templates, and it seems to me so far that it is a unilaterally better option than the untrimmed version. The text is much easier to work with in translation files, and is decoupled from any formatting in templates.

Instead of updating all my template strings to use it I was hoping to be able to set something like:

settings.DEFAULT_BLOCKTRANSLATE_TRIMMED = True

But found that this option did not exist. So my questions are:

  1. Is there any reason not to support an option like this? Like is there some edge case I’m overlooking in wanting this to always be turned on by default?
  2. If not, would a contribution be accepted that added this functionality?

thanks,
Cory

1 Like

Django devs are very reluctant to add more settings to Django. It should be a use case where you have no choice but creating a new setting.

Maybe you could workaround this by having your own version of blocktranslate in some of your template tag libraries (you may have to silence a warning, though).

Claude

I’m willing to accept that this idea will be struck down because of some “no new settings” mantra of the maintainers. But I would still push back on that if it is in fact the case that this is unilaterally better behavior (something I’m still trying to figure out).

I’m sure there are plenty of ways to workaround it and I’ll probably end up using one, but I’d much rather invest that energy into making Django better for everyone if there was any possibility of making that happen.

I understand and appreciate your energy. However, I doubt (and would personally opposed to) that adding a setting is the right thing to do.
If trimming is indeed the wanted behavior in most use cases, then it would have to become the default (without a setting). However as it is a backwards-incompatible change, it would need to pass through a deprecation period, probably using a temporary opt-in setting during that period.

This sounds great to me.