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

  • SEARCH
  • Home
  • 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 8521017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:41:46+00:00 2026-06-11T06:41:46+00:00

from django.utils.translation import ugettext_lazy as _ _(uI am off to school at ‘%s’ o’clock

  • 0
from django.utils.translation import ugettext_lazy as _

_(u"I am off to school at '%s' o'clock" % time)

This is kind of odd, since I would get a whole line to translate like this

"I am off to school at \'%s\' o'clock"

Now if the translator removes the \’%s\’ by mistake, it would break the code.

Should I better separate the sentence into two parts? But this might give the translator trouble to understand the context of the sentence.

_(u"I am off to school at ") + '%s' + _(u"o'clock") % time

Is there a better approach to this?

  • 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-06-11T06:41:48+00:00Added an answer on June 11, 2026 at 6:41 am

    If you make use of named string interpolation as opposed to positional string interpolation, this should protect you from an exception if the translator forgets one of the parameters from his translated string.

    An example from the django docs:

    def my_view(request, m, d):
        output = _('Today is %(month)s %(day)s.') % {'month': m, 'day': d}
        return HttpResponse(output)
    

    Note the dictionary of {‘name’: ‘value’} pairs to be used in string substitution.

    For this reason, you should use named-string interpolation (e.g., %(day)s) instead of positional interpolation (e.g., %s or %d) whenever you have more than a single parameter. If you used positional interpolation, translations wouldn’t be able to reorder placeholder text.

    (django docs)

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

Sidebar

Related Questions

I have a Model and ModelForm like: from django.utils.translation import ugettext_lazy as _ class
Suppose it is the following structure given: from django.utils.translation import ugettext_lazy as _ #
In models.py : from django.db import models from django.utils.translation import ugettext as _ #
I get this error when I use simplejson from django.utils in google app engine
from django.utils.simplejson import dumps, loads # -*- coding: utf-8 -*- def index(request): return render_to_response('test2/index.html')
views.py from django.core.context_processors import csrf context.update(csrf(request)) {'csrf_token': <django.utils.functional.__proxy__ object at 0xae0f4ec>} I am trying
from django.utils.safestring import * print SafeString('\u3042') print '\u3042' \u3042 \u3042 who can give me
When using from django.utils import simplejson on objects of types that derive from db.Model
In some Django applications I encountered URL patterns with gettext such as: from django.utils.translation
I wrote a simple Django view: from django.http import HttpResponse from django.utils import simplejson

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.