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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:18:37+00:00 2026-05-24T11:18:37+00:00

What is the best way to store language constants in django project? For example,

  • 0

What is the best way to store language constants in django project?

For example, we know, that for translation we need to do:

from django.utils.translation import gettext_lazy as _

class MyThing(models.Model):
    name = models.CharField(help_text=_('This is the help text'))

If we have a lot of variants, we can use dictionary like this:

from django.utils.translation import gettext_lazy as _
MYTRANSLATION = { 
    'term1':_('term1'), 
    'term2':_('term2'),
    ...
}

So, my question is, where to store dictionary with language constants… Directly in view, in model, in separate file in app folder, in root folder of project, etc… What is the best way? And where do you store your language consts?

  • 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-24T11:18:38+00:00Added an answer on May 24, 2026 at 11:18 am

    I think it really depends. If you have a big public-facing site that you want to translate into N languages, then they aren’t constant and will require updates from dedicated translators whenever the content changes. For a project like that, gettext is wholly unsuitable because gettext is to hard for non-technical persons to use. The site will also require a recompile and redeploy to update the translations which are major dealbreakers if the content is to change often. gettext works for desktop applications (kind of, it is still a major pita for translators) but it does not for web sites.

    Instead, use https://github.com/ojii/django-nani. Create a table to hold all translatable strings in your templates:

    class I18NString(TranslatableModel):
        key = models.SlugField(unique = True)
        translations = TranslatedFields(
            text = models.TextField(),
        )
    

    For each piece of text you need, add it as a row in I18NString. For example, you could add a row with the key “short-introduction-text” and add the English and German versions of the introduction texts there.

    Then for each page load, load all translations for the current language:

    # For performance, memcached should be used.   
    strings = I18NString.objects.language(request.COUNTRY_CODE).all()
    trans = dict((s.key, s.text) for s in strings)
    

    Pass the trans dictionary to the template and render the translated strings:

    {{ trans.short-introduction-text }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to store string data across postback. I need to
What's the best way to store language data? Keep it as variables in some
What's the best way to store large JSON files in a database? I know
What is the best way to store an in-app-purchase on a device, so that
What is the best way to store data on the server, that can be
The best way to store images into MySQL is by storing the image location
What is the best way to store international addresses in a database? Answer in
What is the best way to store a large amount of text in a
What's the best way to store a linked list in a MySQL database so
What's the best way to store tags for a record? Just use a varchar

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.