In typical Django development style, to form a complete picture of what to do, I am using a combination of
- The Django docs on localization (which actually only describes how to set up language files) https://docs.djangoproject.com/en/1.1/topics/i18n/localization/#
- This tutorial: http://devdoodles.wordpress.com/2009/02/14/multi-language-support-in-a-django-project/
- An SO question: django internationalization and translations issue
I have set up a fresh Django 1.4 site with a working "home" app and template with the following:
{% load i18n %}
{% trans "hello" %}
My settings.py file follows the 2nd tutorial. Here are my middleware classes:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
and my views.py file looks like this:
from django.template import Context, loader, RequestContext
from django.http import HttpResponse
from django.shortcuts import render_to_response
def index(request):
c = Context({})
return render_to_response('home/index.html', c, context_instance=RequestContext(request))
What is really perplexing is how to edit the django.py files in my locale folder. The tutorial says "edit them," the Django docs don't mention them, and the SO question says to get rid of the #, fuzzy
line.
here is what that file looks like (at the top)
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid "hello"
msgstr "Bonjour le Monde"
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-12-08 19:16+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"