Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 440
Anthrax00 Avatar asked Jun 23 '10 11:06

Anthrax00


People also ask

Is Django multilingual?

Django offers multiple language support out-of-the-box. In fact, Django is translated into more than 100 languages. This tutorial looks at how to add multiple language support to your Django project.


1 Answers

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 %}
like image 114
Anthrax00 Avatar answered Sep 28 '22 03:09

Anthrax00