Search code examples
djangomultilingual

The easiest way to have a multilingual django sites?


I have and old django site (0.97-pre-SVN-7457) and I'm about to make some changes and get the site running on the current development code of django.

I have a lot of content that needs to be intact. When I started the site, I made an ugly "hack" to get a dual lingual site, so the result is not pretty:

Here is my model:

class Entry(models.Model):
title_NO = models.CharField(max_length=500)
teaser_NO = models.TextField(blank=True, null=True,)
body_NO = models.TextField(blank=True, null=True,)
title_EN = models.CharField(max_length=500, blank=True, null=True)
teaser_EN = models.TextField(blank=True, null=True,)
body_EN = models.TextField(blank=True, null=True,)
...

In my templates I have written:

<div id="language_NO">
<h1>{{object.title_NO}}</h1>
.....
</div>
<div id="language_EN">
<h1>{{object.title_EN}}</h1>
 .....
</div>

And using a simple JavaScript to determine which div to show (Printing the content twice in the template is very ugly, I know!)

So, now that I want to make some changes, what is the best way to go?

I have tried to read the documentation on the subject, but I cant find anything explaining what to do with the urls and templates.

The only current thing I have found is how to change the language correct


Solution

  • The answer I was looking for is this:

    in my template:

    {% load i18n %}{% get_current_language as LANGUAGE_CODE %}
    
    {% ifequal LANGUAGE_CODE "en" %}                    
    <h2>{{object.title_EN }}</h2>
    {% else %}
    <h2>{{object.title_NO }}</h2>
    {% endifequal %}