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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:14:29+00:00 2026-06-10T01:14:29+00:00

I’m looking for a solution to have translatable database fields in Django, and the

  • 0

I’m looking for a solution to have translatable database fields in Django, and the solution needs to be compatible with South.

I already found django-transmeta and transdb. Only the latter seems to be compatible with South, but I’m not sure about that. Also, transdb values don’t look nice in the database (something the customer actually cares about).

Has anybody worked with such a combination? I’m not particaluary focussed on South, but it seems to be the way to go for schema migration in Django.

  • 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-10T01:14:30+00:00Added an answer on June 10, 2026 at 1:14 am

    Because we did know that the number of languages will never change, we switched to having fields for each language and a simple mechanism for automatically reading the correct field for the current language. Our implementation is used like this:

    class Question(models.Model):
        __metaclass__ = LocalizeModelBase
    
        text_de = models.TextField(verbose_name=_(u"question text (german)"))
        text_en = models.TextField(verbose_name=_(u"question text (english)"))
        text = Translate
    

    Question().text then automatically returns the correct field, based on the current language with a fallback to the default language.

    The implementation behind it should be pretty much self-explaining:

    from django.db.models.base import ModelBase
    from django.utils.translation import get_language
    from django.conf import settings
    
    __all__ = ('Translate', 'LocalizeModelBase')
    
    # a dummy placeholder object
    Translate = object()
    
    
    class LocalizeModelBase(ModelBase):
        """This meta-class provides automatically translated content properties. Set
        a model field to `Translate` and it will automatically return the property
        with the name of the current language. E.g. if there is a normal member
        `text_de`, a member `text = Translate` and the current language is `de`, then
        an object will return the content of `text_de` when it is asked for the value
        of `text`.
        """
        def __new__(metacls, classname, bases, classDict):
            # find all classDict entries that point to `Translate`
            for key in classDict.keys():
                if classDict[key] is Translate:
                    # replace them with a getter that uses the current language
                    classDict[key] = make_property(key)
            return super(LocalizeModelBase, metacls).__new__(metacls, classname, bases, classDict)
    
    
    def make_property(k):
        """Creates a new property that implements the automatic translation
        described above. Every use of `Translate` in a class definition will be
        replaces with a property returned by this function."""
        def pget(self):
            try:
                # try to return the attribute for the current language
                return getattr(self, "%s_%s" % (k, get_language()))
            except AttributeError:
                # use the default language if the current language is not available
                return getattr(self, "%s_%s" % (k, settings.LANGUAGE_CODE))
        return property(pget)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.