forms.ModelForm django translation

Dear community,
I am trying to use the django translation built-in functions to translate the labels of the form.

I report here the code that i am using,

from django.contrib.gis.db import models
from django.contrib.auth.models import User

from farmer.models import Farmer

# Create your models here.

class Field(models.Model):
    Farmer = models.ForeignKey(Farmer,
    FieldName = models.CharField(max_length=500)
    User = models.ForeignKey(User, 
                             null=True, on_delete=models.CASCADE)

    def __str__(self):
        return f'{self.FieldName}'

from django import forms
from leaflet.forms.widgets import LeafletWidget

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Field

from .models import Field
from farmer.models import Farmer

from django.utils.translation import gettext as _

class FieldForm(forms.ModelForm):
    class Meta:
        model = Field
        fields = ('Farmer', 'FieldName')
        labels = {
            "Farmer": _("Name of the farmer company"),
            "FieldName": _("Name of the field")
        widgets = {
    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user', None)
        super(FieldForm, self).__init__(*args, **kwargs)
        if user is not None:
            self.fields['Farmer'].queryset = Farmer.objects.filter(User_id=user)

class NewFieldFarmer(LoginRequiredMixin, CreateView):
    model = Field
    form_class = FieldForm
    template_name = 'field/field_new.html'
    success_url="/registeredfield/" (app directory)

from django.urls import path

from .views import NewFieldFarmer

urlpatterns = [
    path("newfield/", NewFieldFarmer.as_view(), name="newfield")
] (project directory

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path("", include("field.urls")),


{% extends "base.html" %}
{% load crispy_forms_tags %}
{% load i18n %}

{% block content %}
<html lang="en">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    {% leaflet_js plugins="forms, geocoder, measurement" %}
    {% leaflet_css plugins="forms, geocoder, measurement" %}
    <script src=""></script>
    <title>{% trans "New Field" %}</title>
    <h3 style="text-align: center;">{% trans "New field registration" %}</h3>
    <div class="container">
        <div class="row align-items-start">
            <div class="col-8">
                <form method="POST">
                    {% csrf_token %}
                    {{ form|crispy }}
                    <input class= "btn btn-success" type="submit" value="Register the new field"/>
{% endblock %}

what am i doing wrong?

I assume that you’re not seeing the translated strings on the template.
In that case i should ask, have you written the translation to the desired language using the makemessages command, and after that runned the compilemessages command?
Also make sure you have followed the documentation on translations. There’s a important note there:

Make sure you’ve activated translation for your project (the fastest way is to check if MIDDLEWARE includes django.middleware.locale.LocaleMiddleware). If you haven’t yet, see How Django discovers language preference.

Thanks to reply @leandrodesouzadev ,
Yes i have added the middleware to the and also i have used this sequence.

  1. Insert the trans tag

  2. use

django-admin makemessages -l it
  1. translate the meaning

  2. use

django-admin compilemessages -l it

I checked if the same word is translated in another section of the site (template) and it is translated correctly.

But when I try to insert it into modelforms, it doesn’t translate for me.

Ok translation
Screenshot 2023-09-20 144942

No translation in the form

I have solved the issue by replacing in the this

from django.utils.translation import gettext as _

with this

from django.utils.translation import gettext_lazy as _