2

I am trying to translate a django app using the built in i18n. I have already marked the text to be translated and created and compiled the language files (.po/.mo) according to the tutorial and with out errors. I've also changed the USE_I18N to true in the settings file and added the following line into the urls.py as the tutorial instructed:

(r'^i18n/', include('django.conf.urls.i18n')),

I also defined a list of allowed languages in the settings.py, as instructed by the tutorial.

then i created a new page html template and copied in the code the tutorial gave for a language select page:

<form action="/i18n/setlang/" method="post">
 {% csrf_token %}
 <input name="next" type="hidden" value="{{ redirect_to }}" />
 <select name="language">
  {% get_language_info_list for LANGUAGES as languages %}
  {% for language in languages %}
   <option value="{{ language.code }}">{{ language.name_local }} ({{ language.code }})</option>
  {% endfor %}
 </select>
 <input type="submit" value="Go" />
</form>

that page works perfectly too, but when i click on "Go", it tells me there was an error loading the page:

Failed to load resource:http://localhost:8000/i18n/setlang/ 
the server responded with a status of 404 (NOT FOUND)

I tried changing the redirect by replacing the variable with the link, but that gave me the same result. I tried changing the form action path and the urls.py in case there was some double naming, which gave me the same error.

I have been reading through the tutorial and the readmes, as well as some of the i18n files and can't seem to find a reason for it not to work, and i would really appreciate an answer. thankyou

t-urban
  • 21
  • 3

1 Answers1

2

Are you sure you used the correct urls.py, i.e. the one in your project root, and not in a subdirectory?

What happens if you change it to:

from django.http import HttpResponse
...
(r'^i18n/', lambda x: HttpResponse("Test")),

Can you go to http://localhost:8000/i18n/ after that?

FrederikVds
  • 551
  • 4
  • 11
  • Thank you very much for your answer, although i had just found another solution 2 min before reading your post. I went around the included django code and included a direct link to the view in urls.py, although i had to rename it and take out the slashes: `url(r'^setlang', 'django.views.i18n.set_language'), `
    `(select_language.html) thank you again for your efforts.
    – t-urban Jun 07 '12 at 08:32