Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6626799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:56:13+00:00 2026-05-25T21:56:13+00:00

In Django templates, you can use either {{ _(Hello World) }} or {% trans

  • 0

In Django templates, you can use either {{ _("Hello World") }} or {% trans "Hello World" %} to mark strings to be translated. In docs, the “official” approach seems to be the {% trans %} tag, but the _() syntax is mentioned too once.

How these approaches differ (except syntax) and why should be one preferable rather than the other?

One difference is that you obviously can’t use {% trans %} with tags and filters. But does that mean that I can just use _() everywhere, like {{ _("String") }}? It works and looks much cleaner and more consistent than using {% trans "String" %} with standalone strings and _() with tags and filters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:56:14+00:00Added an answer on May 25, 2026 at 9:56 pm

    So it seems that there’s technically no difference as of Django 1.5. Template engine internally marks a variable for translation (by setting its translate attribute) in two cases:

    • when you do {% trans VAR %} (see TranslateNode), or
    • if the name of a variable starts with _( and ends with ) (see Variable.__init__).

    Later, when the variable is being resolved, Django wraps it with ugettext or pgettext if it sees the translate attribute.

    However, as can be seen from source code, there are some flexibility considerations in favor of {% trans %} tag:

    • you can do {% trans "String" noop %}, which will put the string for translation into .po files, but won’t actually translate the output when rendering (no internal translate attribute on variable, no ugettext call);
    • you can specify message context*, like {% trans "May" context "verb" %};
    • you can put translated message into a variable for later use*, like {% trans "String" as
      translated_string %}
      .

    * As of Django 1.4.

    Please feel free to correct me or post a better answer in case I’m missing anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Django's template language, you can use {% url [viewname] [args] %} to generate
All, How Can we increment a value like the following in django templates, {{
I'm building a django app and I can't get the templates to see the
Our Django site is built using Mako templates. We want to use a third
I want to send HTML-emails, using Django templates like this: <html> <body> hello <strong>{{username}}</strong>
My Django templates use a lot of related stuff: images, style sheets, etc. Where
I want to use Mako templates with GAE instead of Django templates. I found
I use Django but I need to find the default templates and applications. I
In smarty templates you can use raw PHP code in a template by placing
As we all know (or should), you can use Django's template system to render

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.