Просмотр исходного кода

Clean up blocktrans template tags (i18n)

Jeremy Stretch 2 лет назад
Родитель
Сommit
39cb9c32d6
31 измененных файлов с 76 добавлено и 46 удалено
  1. 2 2
      docs/development/internationalization.md
  2. 7 3
      netbox/templates/circuits/circuit_terminations_swap.html
  3. 1 1
      netbox/templates/dcim/bulk_disconnect.html
  4. 1 1
      netbox/templates/dcim/cable_trace.html
  5. 8 2
      netbox/templates/dcim/devicebay_delete.html
  6. 2 2
      netbox/templates/dcim/devicebay_depopulate.html
  7. 1 1
      netbox/templates/dcim/devicetype/component_templates.html
  8. 1 1
      netbox/templates/dcim/moduletype/component_templates.html
  9. 1 1
      netbox/templates/dcim/rack/base.html
  10. 5 1
      netbox/templates/dcim/virtualchassis_add_member.html
  11. 1 1
      netbox/templates/dcim/virtualchassis_edit.html
  12. 1 1
      netbox/templates/dcim/virtualchassis_remove_member.html
  13. 2 2
      netbox/templates/exceptions/import_error.html
  14. 1 1
      netbox/templates/exceptions/permission_error.html
  15. 2 2
      netbox/templates/exceptions/programming_error.html
  16. 10 2
      netbox/templates/extras/dashboard/reset.html
  17. 1 1
      netbox/templates/extras/dashboard/widgets/bookmarks.html
  18. 5 1
      netbox/templates/extras/objectchange.html
  19. 1 1
      netbox/templates/extras/report_list.html
  20. 2 2
      netbox/templates/extras/script_list.html
  21. 1 1
      netbox/templates/generic/bulk_delete.html
  22. 6 2
      netbox/templates/generic/bulk_import.html
  23. 3 3
      netbox/templates/generic/bulk_remove.html
  24. 1 1
      netbox/templates/generic/object_edit.html
  25. 1 1
      netbox/templates/generic/object_list.html
  26. 1 1
      netbox/templates/htmx/delete_form.html
  27. 1 1
      netbox/templates/inc/missing_prerequisites.html
  28. 1 1
      netbox/templates/inc/paginator.html
  29. 1 1
      netbox/templates/inc/paginator_htmx.html
  30. 4 4
      netbox/templates/media_failure.html
  31. 1 1
      netbox/templates/virtualization/cluster_add_devices.html

+ 2 - 2
docs/development/internationalization.md

@@ -97,7 +97,7 @@ class CircuitTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
 
 1. Ensure translation support is enabled by including `{% load i18n %}` at the top of the template.
 2. Use the [`{% trans %}`](https://docs.djangoproject.com/en/stable/topics/i18n/translation/#translate-template-tag) tag (short for "translate") to wrap short strings.
-3. Longer strings may be enclosed between [`{% blocktrans %}`](https://docs.djangoproject.com/en/stable/topics/i18n/translation/#blocktranslate-template-tag) and `{% endblocktrans %}` tags to improve readability and to enable variable replacement.
+3. Longer strings may be enclosed between [`{% blocktrans %}`](https://docs.djangoproject.com/en/stable/topics/i18n/translation/#blocktranslate-template-tag) and `{% endblocktrans %}` tags to improve readability and to enable variable replacement. (Remember to include the `trimmed` argument to trim whitespace between the tags.)
 4. Avoid passing HTML within translated strings where possible, as this can complicate the work needed of human translators to develop message maps.
 
 ```
@@ -107,7 +107,7 @@ class CircuitTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
 <h5 class="card-header">{% trans "Circuit List" %}</h5>
 
 {# A longer string with a context variable #}
-{% blocktrans with count=object.circuits.count %}
+{% blocktrans trimmed with count=object.circuits.count %}
   There are {count} circuits. Would you like to continue?
 {% endblocktrans %}
 ```

+ 7 - 3
netbox/templates/circuits/circuit_terminations_swap.html

@@ -4,14 +4,18 @@
 {% block title %}{% trans "Swap Circuit Terminations" %}{% endblock %}
 
 {% block message %}
-    <p>{% blocktrans %}Swap these terminations for circuit {{ circuit }}?{% endblocktrans %}</p>
+    <p>
+      {% blocktrans trimmed %}
+        Swap these terminations for circuit {{ circuit }}?
+      {% endblocktrans %}
+    </p>
     <ul>
         <li>
             <strong>{% trans "A side" %}:</strong>
             {% if termination_a %}
                 {{ termination_a.site }} {% if termination_a.interface %}- {{ termination_a.interface.device }} {{ termination_a.interface }}{% endif %}
             {% else %}
-                {{ ''|placeholder }}
+                {% trans "None" %}
             {% endif %}
         </li>
         <li>
@@ -19,7 +23,7 @@
             {% if termination_z %}
                 {{ termination_z.site }} {% if termination_z.interface %}- {{ termination_z.interface.device }} {{ termination_z.interface }}{% endif %}
             {% else %}
-                {{ ''|placeholder }}
+                {% trans "None" %}
             {% endif %}
         </li>
     </ul>

+ 1 - 1
netbox/templates/dcim/bulk_disconnect.html

@@ -6,7 +6,7 @@
 
 {% block message %}
     <p>
-      {% blocktrans with count=selected_objects|length %}
+      {% blocktrans trimmed with count=selected_objects|length %}
         Are you sure you want to disconnect these {{ count }} {{ obj_type_plural }}?
       {% endblocktrans %}
     </p>

+ 1 - 1
netbox/templates/dcim/cable_trace.html

@@ -3,7 +3,7 @@
 {% load i18n %}
 
 {% block title %}
-  {% blocktrans with object_type=object|meta:"verbose_name"|bettertitle %}
+  {% blocktrans trimmed with object_type=object|meta:"verbose_name"|bettertitle %}
     Cable Trace for {{ object_type }} {{ object }}
   {% endblocktrans %}
 {% endblock %}

+ 8 - 2
netbox/templates/dcim/devicebay_delete.html

@@ -2,8 +2,14 @@
 {% load form_helpers %}
 {% load i18n %}
 
-{% block title %}{% blocktrans %}Delete device bay {{ devicebay }}?{% endblocktrans %}{% endblock %}
+{% block title %}
+  {% blocktrans %}Delete device bay {{ devicebay }}?{% endblocktrans %}
+{% endblock %}
 
 {% block message %}
-    <p>{% blocktrans %}Are you sure you want to delete this device bay from <strong>{{ devicebay.device }}</strong>?{% endblocktrans %}</p>
+  <p>
+    {% blocktrans trimmed %}
+      Are you sure you want to delete this device bay from <strong>{{ devicebay.device }}</strong>?
+    {% endblocktrans %}
+  </p>
 {% endblock %}

+ 2 - 2
netbox/templates/dcim/devicebay_depopulate.html

@@ -3,14 +3,14 @@
 {% load i18n %}
 
 {% block title %}
-  {% blocktrans with device=device_bay.installed_device %}
+  {% blocktrans trimmed with device=device_bay.installed_device %}
     Remove {{ device }} from {{ device_bay }}?
   {% endblocktrans %}
 {% endblock %}
 
 {% block message %}
   <p>
-    {% blocktrans with device=device_bay.installed_device %}
+    {% blocktrans trimmed with device=device_bay.installed_device %}
       Are you sure you want to remove <strong>{{ device }}</strong> from <strong>{{ device_bay }}</strong>?
     {% endblocktrans %}
   </p>

+ 1 - 1
netbox/templates/dcim/devicetype/component_templates.html

@@ -27,7 +27,7 @@
                 <div class="float-end">
                     <a href="{% url table.Meta.model|viewname:"add" %}?device_type={{ object.pk }}&return_url={{ return_url }}" class="btn btn-primary btn-sm">
                         <i class="mdi mdi-plus-thick" aria-hidden="true"></i>
-                        {% blocktrans %}Add {{ title }}{% endblocktrans %}
+                        {% trans "Add" %} {{ title }}
                     </a>
                 </div>
                 <div class="clearfix"></div>

+ 1 - 1
netbox/templates/dcim/moduletype/component_templates.html

@@ -27,7 +27,7 @@
                 <div class="float-end">
                     <a href="{% url table.Meta.model|viewname:"add" %}?module_type={{ object.pk }}&return_url={{ return_url }}" class="btn btn-primary btn-sm">
                         <i class="mdi mdi-plus-thick" aria-hidden="true"></i>
-                        {% blocktrans %}Add {{ title }}{% endblocktrans %}
+                        {% trans "Add" %} {{ title }}
                     </a>
                 </div>
                 <div class="clearfix"></div>

+ 1 - 1
netbox/templates/dcim/rack/base.html

@@ -1,7 +1,7 @@
 {% extends 'generic/object.html' %}
 {% load i18n %}
 
-{% block title %}{% blocktrans %}Rack {{ object }}{% endblocktrans %}{% endblock %}
+{% block title %}{% trans "Rack" %} {{ object }}{% endblock %}
 
 {% block breadcrumbs %}
   {{ block.super }}

+ 5 - 1
netbox/templates/dcim/virtualchassis_add_member.html

@@ -2,7 +2,11 @@
 {% load form_helpers %}
 {% load i18n %}
 
-{% block title %}{% blocktrans %}Add New Member to Virtual Chassis {{ virtual_chassis }}{% endblocktrans %}{% endblock %}
+{% block title %}
+  {% blocktrans trimmed %}
+    Add New Member to Virtual Chassis {{ virtual_chassis }}
+  {% endblocktrans %}
+{% endblock %}
 
 {% block content %}
     <form action="" method="post" enctype="multipart/form-data" class="form-object-edit">

+ 1 - 1
netbox/templates/dcim/virtualchassis_edit.html

@@ -4,7 +4,7 @@
 {% load i18n %}
 
 {% block title %}
-  {% blocktrans with name=vc_form.instance %}
+  {% blocktrans trimmed with name=vc_form.instance %}
     Editing Virtual Chassis {{ name }}
   {% endblocktrans %}
 {% endblock %}

+ 1 - 1
netbox/templates/dcim/virtualchassis_remove_member.html

@@ -6,7 +6,7 @@
 
 {% block message %}
   <p>
-    {% blocktrans with name=device.virtual_chassis %}
+    {% blocktrans trimmed with name=device.virtual_chassis %}
       Are you sure you want to remove <strong>{{ device }}</strong> from virtual chassis {{ name }}?
     {% endblocktrans %}
   </p>

+ 2 - 2
netbox/templates/exceptions/import_error.html

@@ -8,7 +8,7 @@
   <p>
     <i class="mdi mdi-alert"></i>
     <strong>{% trans "Missing required packages" %}.</strong>
-    {% blocktrans %}
+    {% blocktrans trimmed %}
       This installation of NetBox might be missing one or more required Python packages. These packages are listed in
       <code>requirements.txt</code> and <code>local_requirements.txt</code>, and are normally installed as part of the
       installation or upgrade process. To verify installed packages, run <code>pip freeze</code> from the console and
@@ -18,7 +18,7 @@
   <p>
     <i class="mdi mdi-alert"></i>
     <strong>{% trans "WSGI service not restarted after upgrade" %}.</strong>
-    {% blocktrans %}
+    {% blocktrans trimmed %}
       If this installation has recently been upgraded, check that the WSGI service (e.g. gunicorn or uWSGI) has been
       restarted. This ensures that the new code is running.
     {% endblocktrans %}

+ 1 - 1
netbox/templates/exceptions/permission_error.html

@@ -8,7 +8,7 @@
   <p>
     <i class="mdi mdi-alert"></i>
     <strong>{% trans "Insufficient write permission to the media root" %}.</strong>
-    {% blocktrans with media_root=settings.MEDIA_ROOT %}
+    {% blocktrans trimmed with media_root=settings.MEDIA_ROOT %}
       The configured media root is <code>{{ media_root }}</code>. Ensure that the user NetBox runs as has access to
       write files to all locations within this path.
     {% endblocktrans %}

+ 2 - 2
netbox/templates/exceptions/programming_error.html

@@ -8,7 +8,7 @@
   <p>
     <i class="mdi mdi-alert"></i>
     <strong>{% trans "Database migrations missing" %}.</strong>
-    {% blocktrans %}
+    {% blocktrans trimmed %}
       When upgrading to a new NetBox release, the upgrade script must be run to apply any new database migrations. You
       can run migrations manually by executing <code>python3 manage.py migrate</code> from the command line.
     {% endblocktrans %}
@@ -16,7 +16,7 @@
   <p>
     <i class="mdi mdi-alert"></i>
     <strong>{% trans "Unsupported PostgreSQL version" %}.</strong>
-    {% blocktrans %}
+    {% blocktrans trimmed %}
       Ensure that PostgreSQL version 12 or later is in use. You can check this by connecting to the database using
       NetBox's credentials and issuing a query for <code>SELECT VERSION()</code>.
     {% endblocktrans %}

+ 10 - 2
netbox/templates/extras/dashboard/reset.html

@@ -4,6 +4,14 @@
 {% block title %}{% trans "Reset Dashboard" %}?{% endblock %}
 
 {% block message %}
-  <p>{% blocktrans %}This will remove <strong>all</strong> configured widgets and restore the default dashboard configuration.{% endblocktrans %}</p>
-  <p>{% blocktrans %}This change affects only <i>your</i> dashboard, and will not impact other users.{% endblocktrans %}</p>
+  <p>
+    {% blocktrans trimmed %}
+      This will remove <strong>all</strong> configured widgets and restore the default dashboard configuration.
+    {% endblocktrans %}
+  </p>
+  <p>
+    {% blocktrans trimmed %}
+      This change affects only <i>your</i> dashboard, and will not impact other users.
+    {% endblocktrans %}
+  </p>
 {% endblock %}

+ 1 - 1
netbox/templates/extras/dashboard/widgets/bookmarks.html

@@ -11,6 +11,6 @@
 {% else %}
   <p class="text-center text-muted">
     <i class="mdi mdi-information-outline"></i>
-    {% blocktrans %}No bookmarks have been added yet.{% endblocktrans %}
+    {% trans "No bookmarks have been added yet." %}
   </p>
 {% endif %}

+ 5 - 1
netbox/templates/extras/objectchange.html

@@ -153,7 +153,11 @@
         {% include 'inc/panel_table.html' with table=related_changes_table heading='Related Changes' panel_class='default' %}
         {% if related_changes_count > related_changes_table.rows|length %}
             <div class="float-end">
-                <a href="{% url 'extras:objectchange_list' %}?request_id={{ object.request_id }}" class="btn btn-primary">{% blocktrans with count=related_changes_count|add:"1" %}See All {{ count }} Changes{% endblocktrans %}</a>
+                <a href="{% url 'extras:objectchange_list' %}?request_id={{ object.request_id }}" class="btn btn-primary">
+                  {% blocktrans trimmed with count=related_changes_count|add:"1" %}
+                    See All {{ count }} Changes
+                  {% endblocktrans %}
+                </a>
             </div>
         {% endif %}
     </div>

+ 1 - 1
netbox/templates/extras/report_list.html

@@ -117,7 +117,7 @@
         <h4 class="alert-heading">{% trans "No Reports Found" %}</h4>
         {% if perms.extras.add_reportmodule %}
           {% url 'extras:reportmodule_add' as create_report_url %}
-          {% blocktrans %}
+          {% blocktrans trimmed %}
             Get started by <a href="{{ create_report_url }}">creating a report</a> from an uploaded file or data source.
           {% endblocktrans %}
         {% endif %}

+ 2 - 2
netbox/templates/extras/script_list.html

@@ -41,7 +41,7 @@
           {% if not module.scripts %}
             <div class="alert alert-warning d-flex align-items-center" role="alert">
               <i class="mdi mdi-alert"></i>
-              {% blocktrans with file_path=module.full_path %}
+              {% blocktrans trimmed with file_path=module.full_path %}
                 Script file at <code>{{ file_path }}</code> could not be loaded.
               {% endblocktrans %}
             </div>
@@ -91,7 +91,7 @@
         <h4 class="alert-heading">{% trans "No Scripts Found" %}</h4>
         {% if perms.extras.add_scriptmodule %}
           {% url 'extras:scriptmodule_add' as create_script_url %}
-          {% blocktrans %}
+          {% blocktrans trimmed %}
             Get started by <a href="{{ create_script_url }}">creating a script</a> from an uploaded file or data source.
           {% endblocktrans %}
         {% endif %}

+ 1 - 1
netbox/templates/generic/bulk_delete.html

@@ -24,7 +24,7 @@ Context:
       <h4 class="alert-heading">{% trans "Confirm Bulk Deletion" %}</h4>
       <hr />
       <strong>{% trans "Warning" context "Noun" %}:</strong>
-      {% blocktrans with count=table.rows|length type_plural=model|meta:"verbose_name_plural" %}
+      {% blocktrans trimmed with count=table.rows|length type_plural=model|meta:"verbose_name_plural" %}
         The following operation will delete <strong>{{ count }}</strong> {{ type_plural }}. Please
         carefully review the objects to be deleted and confirm below.
       {% endblocktrans %}

+ 6 - 2
netbox/templates/generic/bulk_import.html

@@ -189,11 +189,15 @@ Context:
     </div>
     <p class="small text-muted">
       <i class="mdi mdi-check-bold text-success"></i>
-      {% blocktrans %}Required fields <strong>must</strong> be specified for all objects.{% endblocktrans %}
+      {% blocktrans trimmed %}
+        Required fields <strong>must</strong> be specified for all objects.
+      {% endblocktrans %}
     </p>
     <p class="small text-muted">
       <i class="mdi mdi-information-outline"></i>
-      {% blocktrans with example="vrf.rd" %}Related objects may be referenced by any unique attribute. For example, <code>{{ example }}</code> would identify a VRF by its route distinguisher.{% endblocktrans %}
+      {% blocktrans trimmed with example="vrf.rd" %}
+        Related objects may be referenced by any unique attribute. For example, <code>{{ example }}</code> would identify a VRF by its route distinguisher.
+      {% endblocktrans %}
     </p>
     {% endif %}
 

+ 3 - 3
netbox/templates/generic/bulk_remove.html

@@ -12,13 +12,13 @@
   <div class="alert alert-danger" role="alert">
     <h4 class="alert-heading">{% trans "Confirm Bulk Removal" %}</h4>
     <p>
-      {% blocktrans with count=table.rows|length %}
+      {% blocktrans trimmed with count=table.rows|length %}
         <strong>Warning:</strong> The following operation will remove {{ count }} {{ obj_type_plural }} from {{ parent_obj }}.
       {% endblocktrans %}
     </p>
     <hr />
     <p class="mb-0">
-      {% blocktrans %}
+      {% blocktrans trimmed %}
         Please carefully review the {{ obj_type_plural }} to be removed and confirm below.
       {% endblocktrans %}
     </p>
@@ -35,7 +35,7 @@
     {% endfor %}
     <div class="text-center">
       <button type="submit" name="_confirm" class="btn btn-danger">
-        {% blocktrans with count=table.rows|length %}
+        {% blocktrans trimmed with count=table.rows|length %}
           Delete these {{ count }} {{ obj_type_plural }}
         {% endblocktrans %}
       </button>

+ 1 - 1
netbox/templates/generic/object_edit.html

@@ -16,7 +16,7 @@ Context:
   {% if object.pk %}
     {% trans "Editing" %} {{ object|meta:"verbose_name" }} {{ object }}
   {% else %}
-    {% blocktrans with object_type=object|meta:"verbose_name" %}
+    {% blocktrans trimmed with object_type=object|meta:"verbose_name" %}
       Add a new {{ object_type }}
     {% endblocktrans %}
   {% endif %}

+ 1 - 1
netbox/templates/generic/object_list.html

@@ -91,7 +91,7 @@ Context:
                 <div class="form-check">
                   <input type="checkbox" id="select-all" name="_all" class="form-check-input" />
                   <label for="select-all" class="form-check-label">
-                    {% blocktrans with count=table.rows|length object_type_plural=table.data.verbose_name_plural %}
+                    {% blocktrans trimmed with count=table.rows|length object_type_plural=table.data.verbose_name_plural %}
                       Select <strong>all {{ count }} {{ object_type_plural }}</strong> matching query
                     {% endblocktrans %}
                   </label>

+ 1 - 1
netbox/templates/htmx/delete_form.html

@@ -8,7 +8,7 @@
   </div>
   <div class="modal-body">
     <p>
-      {% blocktrans %}
+      {% blocktrans trimmed %}
         Are you sure you want to <strong class="text-danger">delete</strong> {{ object_type }} <strong>{{ object }}</strong>?
       {% endblocktrans %}
     </p>

+ 1 - 1
netbox/templates/inc/missing_prerequisites.html

@@ -4,7 +4,7 @@
 <div class="alert alert-warning text-end" role="alert">
   <div class="float-start">
     <i class="mdi mdi-alert"></i>
-    {% blocktrans with model=model|meta:"verbose_name" prerequisite_model=prerequisite_model|meta:"verbose_name" %}
+    {% blocktrans trimmed with model=model|meta:"verbose_name" prerequisite_model=prerequisite_model|meta:"verbose_name" %}
       Before you can add a {{ model }} you must first create a <strong>{{ prerequisite_model }}</strong>.
     {% endblocktrans %}
   </div>

+ 1 - 1
netbox/templates/inc/paginator.html

@@ -46,7 +46,7 @@
         </ul>
       </div>
       <small class="text-end text-muted">
-        {% blocktrans with start=page.start_index end=page.end_index total=page.paginator.count %}
+        {% blocktrans trimmed with start=page.start_index end=page.end_index total=page.paginator.count %}
           Showing {{ start }}-{{ end }} of {{ total }}
         {% endblocktrans %}
       </small>

+ 1 - 1
netbox/templates/inc/paginator_htmx.html

@@ -66,7 +66,7 @@
         </ul>
       </div>
       <small class="text-end text-muted">
-        {% blocktrans with start=page.start_index end=page.end_index total=page.paginator.count %}
+        {% blocktrans trimmed with start=page.start_index end=page.end_index total=page.paginator.count %}
           Showing {{ start }}-{{ end }} of {{ total }}
         {% endblocktrans %}
       </small>

+ 4 - 4
netbox/templates/media_failure.html

@@ -26,13 +26,13 @@
         <p>{% trans "Check the following" %}:</p>
         <ul>
             <li class="tip">
-              {% blocktrans %}
+              {% blocktrans trimmed %}
                 <code>manage.py collectstatic</code> was run during the most recent upgrade. This installs the most
                 recent iteration of each static file into the static root path.
               {% endblocktrans %}
             </li>
             <li class="tip">
-              {% blocktrans with docs_url="https://docs.netbox.dev/en/stable/installation/" %}
+              {% blocktrans trimmed with docs_url="https://docs.netbox.dev/en/stable/installation/" %}
                 The HTTP service (e.g. nginx or Apache) is configured to serve files from the <code>STATIC_ROOT</code>
                 path. Refer to <a href="{{ docs_url }}">the installation documentation</a> for further guidance.
               {% endblocktrans %}
@@ -44,7 +44,7 @@
               </ul>
             </li>
             <li class="tip">
-              {% blocktrans %}
+              {% blocktrans trimmed %}
                 The file <code>{{ filename }}</code> exists in the static root directory and is readable by the HTTP
                 server.
               {% endblocktrans %}
@@ -52,7 +52,7 @@
         </ul>
         <p>
           {% url 'home' as home_url %}
-          {% blocktrans %}
+          {% blocktrans trimmed %}
             Click <a href="{{ home_url }}">here</a> to attempt loading NetBox again.
           {% endblocktrans %}
         </p>

+ 1 - 1
netbox/templates/virtualization/cluster_add_devices.html

@@ -6,7 +6,7 @@
 {% render_errors form %}
 
 {% block title %}
-  {% blocktrans %}
+  {% blocktrans trimmed %}
     Add Device to Cluster {{ cluster }}
   {% endblocktrans %}
 {% endblock %}