Have you considered internationalization and localization as an alternative to 
what you are doing?
https://docs.djangoproject.com/en/1.11/topics/i18n/

To do what you are doing, you would need to do it in the view function, 
something like this:
context[‘title’] = getattr(artobject, “%s_%s” % (title, LANGUAGE_CODE))

And in your template:
{{ title|safe|capfirst }}


You might also be able to create your own filter that would take two arguments: 
the prefix and the language code.  You would do that if you really want that 
logic in your template and not inside the view function.  Check this out for 
information on creating your own template filters:
https://docs.djangoproject.com/en/1.11/howto/custom-template-tags/





From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Jaap van Wingerde
Sent: Tuesday, May 23, 2017 9:09 AM
To: Django users
Subject: append language-code tot variable name

In my templates I have variables as {{ artobject.title|safe|capfirst }}. I want 
the site in more languages.So in changed the model: title changed in title_nl, 
and I appended title_de, title_en, title_fr. This is more easy for me than 
po-files.

A template must work for all languages,so the variable above in the template 
must become {{ artobject.title_nl|safe|capfirst }} etc.There is a variable {{ 
LANGUAGE_CODE }}, but nesting the variables: {{ artobject.title_{{ 
LANGUAGE_CODE }}|safe|capfirst }} does not work. How can I solve this?
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5ed6725c-a77d-48c5-bdc2-4e5642b03919%40googlegroups.com<https://groups.google.com/d/msgid/django-users/5ed6725c-a77d-48c5-bdc2-4e5642b03919%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/88ea467806044a88889adfb10d7527dc%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.

Reply via email to