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 8389059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:37:11+00:00 2026-06-09T18:37:11+00:00

I have weird problem with django translations that i need help figuring out. Problem

  • 0

I have weird problem with django translations that i need help figuring out. Problem is that instead of getting translated string every time i seem to get randomly either translated string or default string.

I have created a class for putting “action” buttons on several pages. Many of those buttons are reusable so why should i put

<a href="something">blabla</a>

into several templates when i can create simple toolbar and use

toolbar.add(tool)

in view and then just use templatetag for rendering all the tools…. anyway.

This is example of one tool:

class NewUserGroupButton(MyTool):
    tool_id = 'new-user-group'
    button_label = ugettext(u'Create new user group')
    tool_href = 'new/'
    js = ()

    def render(self):
        s = '<a id="%(tool_id)s" href="%(tool_href)s" class="button blue">%(button_label)s</a>'
        return s % {'tool_id': self.tool_id, 'tool_href': self.tool_href, 'button_label':self.button_label}

The tools are rendered like this:

class ToolbarTools:
    def __init__(self):
        self.tools = []

    def add(self, tool):
        self.tools.append(tool)

    def render(self):
        # Organize tools by weight
        self.tools.sort(key=lambda x: x.weight)

        # Render tools
        output = '<ul id="toolbar" class="clearfix">'

        for tool in self.tools:
            output += '<li id="%s">' % ('tool-'+ tool.tool_id)
            output += tool.render() if tool.renderable else ''
            output += '</li>'

        output += '</ul>'

        # Reset tools container
        self.tools = []

        return mark_safe(output)

im using ugettext to translate the string. using (u)gettext=lambda s:s or ugettext_lazy gives me either no translations or proxy object corresponding to function choices.

And like i said – while rest of the page is in correct language the toolbar buttons seem to be randomly either translated or not. The faulty behaviour remains consistent if i move between different pages with different “tools” or even refresh the same page several times.

Could someone please help me to figure out what is causing this problem and how to fix it?

  • 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-09T18:37:13+00:00Added an answer on June 9, 2026 at 6:37 pm

    Problem solved.

    The issue itself (random translating) was perhaps caused by using ugettext. But at the same time i should have used ugettext_lazy instead.

    And thus the problem really came from ugettext_lazy returning proxy object not translated string… and that is caused by this:

    [Quote]
    Working with lazy translation objects
    The result of a ugettext_lazy() call can be used wherever you would use a unicode string (an object with type unicode) in Python. If you try to use it where a bytestring (a str object) is expected, things will not work as expected, since a ugettext_lazy() object doesn’t know how to convert itself to a bytestring. You can’t use a unicode string inside a bytestring, either, so this is consistent with normal Python behavior. For example:

    This is fine: putting a unicode proxy into a unicode string.
    u"Hello %s" % ugettext_lazy("people")
    This will not work, since you cannot insert a unicode object
    into a bytestring (nor can you insert our unicode proxy there)
    "Hello %s" % ugettext_lazy("people")
    

    [/Quote]

    taken from here:
    https://docs.djangoproject.com/en/dev/topics/i18n/translation/#working-with-lazy-translation-objects

    Alan

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

Sidebar

Related Questions

I have a weird problem, I need to parse a date string that looks
I have a weird problem that I am hoping someone can help me with.
today a weird problem occurred to me: I have a model class in Django
I have a weird problem. I develop my sites on localhost and after that
I have a weird problem building a release of an erlang application that I'm
I have a weird problem. I have a script that loads images into the
I have a weird problem... I use this code: String text = new String(values[0]);
I have a weird problem that only started recently. When I run the app
I have a weird problem with Magento cache. I have an extension that have
I have a weird problem when running an application that uses GNOME's libxml2 under

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.