I couldn't understand why the i18n is not detecting the data in my loop:
{% trans service.title %}
anyone who can help!? Thanks in advance!
{% load i18n %}
{% for service in services %}
<div class="col-sm-3">
<div class="service bg-white">
<div class="img-block">
<img alt="" class="service-img img-fluid"
src="{{service.img.url}}">
</div>
<div class="service-feature">
<h4 class="feature-text text-center">
{% trans service.title %}
</h4>
<p>{{service.desc}}</p>
</div>
</div>
</div>
{% endfor %}
I tried several different ways such:
{% translate service.title %} no reactions
{{ service.title|trans }} no reactions
It seems like your content is coming from the database and is dynamic, traditional string-based translation won't work as intended.
Django doesn't have built-in support for database content translation, but there are third-party packages available that can help. One of the most popular is
django-modeltranslation. Here's how to use it:django-modeltranslation:INSTALLED_APPS:To add translations for the
titleanddescfields, you'd create atranslation.pyin the same app directory:django-modeltranslationalso supports integration with the Django Admin, providing tabs for each language where you can input translated content.Remember to always read the documentation of third-party packages and test them to make sure they work as expected and satisfy your requirements.