Commits

Anonymous committed bd9db9c

Added the change_locale view contributed by Panos Laganakos.

  • Participants
  • Parent commits 21d1594

Comments (0)

Files changed (10)

docs/.build/html/history.html

 <div class="section" id="changelog">
 <h2>Changelog<a class="headerlink" href="#changelog" title="Permalink to this headline">¶</a></h2>
 <dl class="docutils">
+<dt>Repository:</dt>
+<dd><ul class="first last simple">
+<li>Added the <tt class="docutils literal"><span class="pre">change_locale</span></tt> view, contributed by Panos Laganakos.</li>
+</ul>
+</dd>
 <dt>Release 1.3: (2009-04-06)</dt>
 <dd><ul class="first last simple">
 <li>Changed chlocale tag to strip prefix of locale-independent paths.</li>

docs/.build/html/index.html

 </ul>
 <ul>
 <li class="toctree-l1"><a class="reference external" href="usage.html">Usage</a><ul>
-<li class="toctree-l2"><a class="reference external" href="usage.html#the-locale-url-tag">The <tt class="docutils literal"><span class="pre">locale_url</span></tt> tag</a></li>
-<li class="toctree-l2"><a class="reference external" href="usage.html#the-chlocale-filter">The <tt class="docutils literal"><span class="pre">chlocale</span></tt> filter</a></li>
-<li class="toctree-l2"><a class="reference external" href="usage.html#the-rmlocale-filter">The <tt class="docutils literal"><span class="pre">rmlocale</span></tt> filter</a></li>
+<li class="toctree-l2"><a class="reference external" href="usage.html#templates">Templates</a></li>
+<li class="toctree-l2"><a class="reference external" href="usage.html#views">Views</a></li>
 </ul>
 </li>
 </ul>

docs/.build/html/installation.html

 </div>
 <div class="section" id="id1">
 <h2>Installation<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
-<p>Installation basically consists of installing the middleware. If you want to
-use the template tags and filters also add localeurl to the installed
-applications.</p>
-<ol class="arabic simple">
-<li>Place the <tt class="docutils literal"><span class="pre">localeurl</span></tt> module in your Python path. You can put it into your
-Django project directory or run <tt class="docutils literal"><span class="pre">python</span> <span class="pre">setup.py</span> <span class="pre">install</span></tt> from a shell.</li>
-<li>Add <tt class="docutils literal"><span class="pre">'localeurl.middleware.LocaleURLMiddleware'</span></tt> to
+<p>Installation basically consists of installing the middleware and adding
+<tt class="docutils literal"><span class="pre">'localeurl'</span></tt> to the installed applications list.</p>
+<ol class="arabic">
+<li><p class="first">Place the <tt class="docutils literal"><span class="pre">localeurl</span></tt> module in your Python path. You can put it into your
+Django project directory or run <tt class="docutils literal"><span class="pre">python</span> <span class="pre">setup.py</span> <span class="pre">install</span></tt> from a shell.</p>
+</li>
+<li><p class="first">Add <tt class="docutils literal"><span class="pre">'localeurl.middleware.LocaleURLMiddleware'</span></tt> to
 <tt class="docutils literal"><span class="pre">settings.MIDDLEWARE_CLASSES</span></tt>. It must come <em>before</em>
 <tt class="docutils literal"><span class="pre">'django.middleware.common.CommonMiddleware'</span></tt> or <tt class="docutils literal"><span class="pre">settings.APPEND_SLASH</span></tt>
-will not work.</li>
-<li>Add <tt class="docutils literal"><span class="pre">'localeurl'</span></tt> to <tt class="docutils literal"><span class="pre">settings.INSTALLED_APPS</span></tt>. Because the application
+will not work.</p>
+</li>
+<li><p class="first">Add <tt class="docutils literal"><span class="pre">'localeurl'</span></tt> to <tt class="docutils literal"><span class="pre">settings.INSTALLED_APPS</span></tt>. Because the application
 needs to replace the standard <tt class="docutils literal"><span class="pre">urlresolvers.reverse</span></tt> function, it is
-important to place it high in the list.</li>
-<li>Make sure <tt class="docutils literal"><span class="pre">settings.LANGUAGE_CODE</span></tt> or its root language is in
+important to place it at the top of the list:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="n">INSTALLED_APPS</span> <span class="o">=</span> <span class="p">(</span>
+    <span class="s">&#39;localeurl&#39;</span><span class="p">,</span>
+    <span class="o">...</span>
+<span class="p">)</span>
+</pre></div>
+</div>
+</li>
+<li><p class="first">If you want to use the view, include the localeurl URLconf module in your
+project:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
+    <span class="o">...</span>
+    <span class="p">(</span><span class="s">r&#39;^localeurl/&#39;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s">&#39;localeurl.urls&#39;</span><span class="p">)),</span>
+    <span class="o">...</span>
+<span class="p">)</span>
+</pre></div>
+</div>
+</li>
+<li><p class="first">Make sure <tt class="docutils literal"><span class="pre">settings.LANGUAGE_CODE</span></tt> or its root language is in
 <tt class="docutils literal"><span class="pre">settings.LANGUAGES</span></tt>. For example, if <tt class="docutils literal"><span class="pre">LANGUAGE_CODE</span> <span class="pre">==</span> <span class="pre">'en-us'</span></tt> then
 <tt class="docutils literal"><span class="pre">LANGUAGES</span></tt> must contain either <tt class="docutils literal"><span class="pre">'en-us'</span></tt> or <tt class="docutils literal"><span class="pre">'en'</span></tt>. If you have not
-changed either option you do not have to do anything.</li>
+changed either option you do not have to do anything.</p>
+</li>
 </ol>
 </div>
 <div class="section" id="id2">

docs/.build/html/searchindex.js

-Search.setIndex({desctypes:{},terms:{"default":[0,1,2,3],multilingu:3,code:[0,1,3],help:0,show:0,german:0,thi:[0,2,3],move:3,"\u00feorbj\u00f6rnsson":3,all:1,localeurlmiddlewar:2,prefix:[0,1,2,3],localemiddlewar:0,follow:0,pano:3,languag:[0,1,2],redirect:[0,1,2],albrecht:3,menu:0,configur:[1,2],except:0,should:[0,1],blog:3,add:[0,1,2],suppos:1,under:1,els:0,subsequ:1,local:[0,2,3],match:2,media_url:2,applic:[0,1,2],them:0,sourc:3,everi:1,contribut:3,thei:0,get:1,python:[0,2],express:2,malet:3,"fran\u00e7ai":0,becaus:[1,2],context_processor:0,game:2,"new":[0,3],ticket:1,now:3,discuss:3,requir:2,enabl:0,document:[1,3],like:[0,1],specif:0,changelog:[1,3],edit:2,revers:[0,2,3],list:[2,3],resolv:2,patch:3,provid:0,common:2,have:[0,1,2],each:1,found:3,locale_independent_path:2,higher:[2,3],page:[0,1,2],remov:[0,3],mean:1,compil:2,www:1,set:[0,1,2,3],laganako:3,deutsch:0,replac:[0,2],multipl:1,some:1,uniqu:1,see:[1,3],atli:3,instal:[1,2],christian:3,user:[0,3],click:0,index:1,announc:3,localeurl:[0,1,2,3],section:2,prefix_default_local:[0,2,3],discoveri:0,profil:1,version:[0,3],middlewar:[0,2,3],casse:3,dutch:0,inspir:3,"import":2,refer:[0,3],core:0,full:2,run:2,ifequ:0,gener:0,contain:2,usag:[0,1],here:[0,3],standard:[0,2],reason:[1,2],base:[0,3],french:0,prerequisit:[1,2,3],releas:3,path:[0,2,3],post:[1,3],come:2,chlocal:[0,1,3],search:1,mailinglist:3,would:[0,2],anyth:2,ajax:2,filter:[0,1,2],credit:[1,3],place:2,behav:0,fals:0,chang:[0,2,3],view:[0,1],com:1,licens:1,urlconf:0,lambda:0,load:0,pleas:0,diomin:3,own:1,joost:3,endifequ:0,render:0,feel:1,localeurl_tag:0,modul:[0,2],independ:[0,2,3],put:2,append_slash:2,href:0,done:1,strip:[0,3],language_cod:[0,2],txt:1,your:[0,2],select:[0,2],yann:3,differ:[0,1],andi:3,describ:2,convent:0,addition:2,top:0,two:0,websit:1,start:2,splash:2,monkei:3,basic:2,taken:3,urlresolv:[0,2,3],artiom:3,includ:3,"function":[0,2],from:[0,2,3],shell:2,option:[2,3],nederland:0,installed_app:2,tupl:2,about:[0,2],specifi:[0,1],site:2,partli:3,intern:0,i18n:0,compani:1,exactli:0,"true":2,must:2,"case":0,also:[0,2,3],redirect_locale_independent_path:3,consist:2,whether:2,might:1,setup:2,work:[0,2,3],tree:3,displai:0,histori:[1,3],project:[2,3],url:[0,1,2,3],can:[0,2,3],behavior:0,root:2,welcom:1,locale_url:[0,1],featur:3,want:[1,2],creat:3,pass:2,argument:0,templat:[0,2],template_context_processor:0,high:2,tag:[0,1,2,3],exist:0,file:[0,1,2],need:[0,2],"return":0,articl:0,string:2,engin:1,googl:3,manipul:0,perform:2,majewski:3,make:2,transpar:0,same:0,note:2,how:2,jona:3,exampl:[0,1,2],take:0,you:[0,1,2],piotr:3,mit:1,either:[0,2],sure:2,http:1,distribut:1,previou:0,middleware_class:2,befor:2,regular:2,path_info:0,help_url:0,develop:3,"class":0,commonmiddlewar:2,lang:0,internationalis:3,off:0,ani:[0,1,2],directori:2,rmlocal:[0,1],request:[0,1],object:2,django:[0,1,2,3],influenc:1,without:[0,1],allow:[0,1],endfor:0,english:0,link:0,model:3,unchang:2,usual:0},titles:["Usage","Welcome to the localeurl documentation","Installation","History"],modules:{},descrefs:{},filenames:["usage","index","installation","history"]})
+Search.setIndex({desctypes:{},terms:{"default":[0,1,2,3],multilingu:3,code:[0,1,3],help:0,show:0,german:0,thi:[0,2,3],move:3,"\u00feorbj\u00f6rnsson":3,all:1,localeurlmiddlewar:2,python:[0,2],prefix:[0,1,2,3],localemiddlewar:0,ani:[0,1,2],follow:0,pano:3,languag:[0,1,2],endifequ:0,redirect:[0,1,2],albrecht:3,menu:0,configur:[1,2],except:0,should:[0,1],blog:3,add:[0,1,2],suppos:1,unchang:2,under:1,els:0,subsequ:1,local:[0,2,3],match:2,media_url:2,applic:[0,1,2],them:0,sourc:3,everi:1,contribut:3,thei:0,get:1,fals:0,express:2,malet:3,"fran\u00e7ai":0,becaus:[1,2],context_processor:0,game:2,"new":[0,3],ticket:1,now:3,discuss:3,requir:2,enabl:0,document:[1,3],like:[0,1],specif:0,changelog:[1,3],edit:2,drop:0,list:[2,3],resolv:2,patch:3,provid:0,common:2,have:[0,1,2],each:1,found:3,locale_independent_path:2,higher:[2,3],page:[0,1,2],mean:1,compil:2,www:1,set:[0,1,2,3],laganako:3,deutsch:0,replac:[0,2],strip:[0,3],some:1,uniqu:1,see:[1,3],design:0,atli:3,instal:[1,2],christian:3,user:[0,3],click:0,ifequ:0,index:1,shown:0,announc:3,djangoproject:[],localeurl:[0,1,2,3],pattern:2,section:2,prefix_default_local:[0,2,3],discoveri:0,profil:1,version:[0,3],middlewar:[0,2,3],casse:3,dutch:0,"import":2,method:0,refer:[0,3],core:0,multipl:1,full:2,run:2,urlpattern:2,locale_switch:0,gener:0,contain:2,usag:[0,1],french:0,standard:[0,2],reason:[1,2],base:[0,3],here:[0,3],repositori:3,set_languag:0,releas:3,path:[0,2,3],post:[0,1,3],come:2,valu:0,box:0,chlocal:[0,3],search:1,revers:[0,2,3],mailinglist:3,would:[0,2],english:0,anyth:2,ajax:2,filter:0,credit:[1,3],place:2,behav:0,action:0,chang:[0,2,3],view:[0,1,2,3],com:1,licens:1,urlconf:[0,2],onchang:0,load:0,pleas:0,diomin:3,own:1,joost:3,prerequisit:[1,2,3],render:0,feel:1,localeurl_tag:0,modul:[0,2],inspir:3,down:0,put:2,append_slash:2,href:0,done:1,url:[0,1,2,3],suppli:0,language_cod:[0,2],txt:1,your:[0,2],select:[0,2],yann:3,differ:[0,1],andi:3,describ:2,convent:0,addition:2,top:[0,2],two:0,submit:0,name:0,websit:1,start:2,splash:2,monkei:3,change_local:[0,3],basic:2,taken:3,urlresolv:[0,2,3],artiom:3,type:0,includ:[2,3],"function":[0,2],from:[0,2,3],shell:2,option:[0,2,3],form:0,installed_app:2,tupl:2,about:[0,2],specifi:[0,1],site:2,partli:3,intern:0,input:0,i18n:0,compani:1,exactli:0,"true":2,must:2,"case":0,also:[0,2,3],redirect_locale_independent_path:3,consist:2,whether:2,might:1,remov:[0,3],work:[0,2,3],tree:3,displai:0,dev:[],histori:[1,3],project:[2,3],independ:[0,2,3],jona:3,can:[0,2,3],behavior:0,root:2,welcom:1,locale_url:0,featur:3,want:[1,2],creat:3,pass:2,argument:0,templat:[0,1],template_context_processor:0,topic:[],tag:[0,3],exist:0,file:[0,1,2],abov:0,need:[0,2],"return":0,articl:0,string:2,engin:1,nederland:0,manipul:0,perform:2,majewski:3,make:2,transpar:0,"switch":0,same:0,note:2,how:2,high:[],exampl:[0,1,2],take:0,instead:0,you:[0,1,2],piotr:3,mit:1,either:[0,2],sure:2,http:1,distribut:1,commonmiddlewar:2,previou:0,middleware_class:2,befor:2,regular:2,path_info:0,help_url:0,develop:3,"class":0,googl:3,lang:0,internationalis:3,off:0,setup:2,directori:2,doc:[],rmlocal:0,request:[0,1],object:2,django:[0,1,2,3],influenc:1,mimic:0,without:[0,1],allow:[0,1],endfor:0,noscript:0,link:0,model:3,lambda:0,localeurl_change_local:0,usual:0},titles:["Usage","Welcome to the localeurl documentation","Installation","History"],modules:{},descrefs:{},filenames:["usage","index","installation","history"]})

docs/.build/html/usage.html

   <table class="pmeta toc" cellpadding=5><tr><td>
 	<ul>
 <li><a class="reference external" href="">Usage</a><ul>
+<li><a class="reference external" href="#templates">Templates</a><ul>
 <li><a class="reference external" href="#the-locale-url-tag">The <tt class="docutils literal"><span class="pre">locale_url</span></tt> tag</a><ul>
+<li><a class="reference external" href="#example">Example</a></li>
+</ul>
+</li>
+<li><a class="reference external" href="#the-chlocale-filter">The <tt class="docutils literal"><span class="pre">chlocale</span></tt> filter</a><ul>
 <li><a class="reference external" href="#examples">Examples</a></li>
 </ul>
 </li>
-<li><a class="reference external" href="#the-chlocale-filter">The <tt class="docutils literal"><span class="pre">chlocale</span></tt> filter</a><ul>
-<li><a class="reference external" href="#id1">Examples</a></li>
+<li><a class="reference external" href="#the-rmlocale-filter">The <tt class="docutils literal"><span class="pre">rmlocale</span></tt> filter</a><ul>
+<li><a class="reference external" href="#id1">Example</a></li>
 </ul>
 </li>
-<li><a class="reference external" href="#the-rmlocale-filter">The <tt class="docutils literal"><span class="pre">rmlocale</span></tt> filter</a><ul>
-<li><a class="reference external" href="#id2">Examples</a></li>
+</ul>
+</li>
+<li><a class="reference external" href="#views">Views</a><ul>
+<li><a class="reference external" href="#the-change-locale-view">The <tt class="docutils literal"><span class="pre">change_locale</span></tt> view</a><ul>
+<li><a class="reference external" href="#id2">Example</a></li>
+</ul>
+</li>
 </ul>
 </li>
 </ul>
 <tt class="docutils literal"><span class="pre">settings.LANGUAGE_CODE</span></tt>. So a request for <tt class="docutils literal"><span class="pre">/about/</span></tt> would be redirected to
 <tt class="docutils literal"><span class="pre">/fr/about/</span></tt> if French is the default language. (This behavior can be changed
 using <tt class="docutils literal"><span class="pre">settings.PREFIX_DEFAULT_LOCALE</span></tt>.)</p>
+<div class="section" id="templates">
+<h2>Templates<a class="headerlink" href="#templates" title="Permalink to this headline">¶</a></h2>
 <p>The application adds one template tag and two filters. Add the following at the
 top of a template to enable them:</p>
 <div class="highlight-python"><pre>{% load localeurl_tags %}</pre>
 </div>
 <div class="section" id="the-locale-url-tag">
-<h2>The <tt class="docutils literal"><span class="pre">locale_url</span></tt> tag<a class="headerlink" href="#the-locale-url-tag" title="Permalink to this headline">¶</a></h2>
+<h3>The <tt class="docutils literal"><span class="pre">locale_url</span></tt> tag<a class="headerlink" href="#the-locale-url-tag" title="Permalink to this headline">¶</a></h3>
 <p>The localeurl application replaces the <tt class="docutils literal"><span class="pre">urlresolvers.reverse</span></tt> function to
 return locale-specific URLs, so existing templates should not need to be
 changed. To manipulate the language on rendered URLs you can use the
 <tt class="docutils literal"><span class="pre">locale_url</span></tt> tag. This tag behaves exactly like the standard <tt class="docutils literal"><span class="pre">url</span></tt> tag,
 except you specify a language.</p>
-<div class="section" id="examples">
-<h3>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h3>
+<div class="section" id="example">
+<h4>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h4>
 <p>You can refer to a specific URL in a specified language like this:</p>
 <div class="highlight-python"><pre>&lt;a href="{% locale_url "de" articles.views.display id=article.id %}"&gt;Show article in German&lt;/a&gt;</pre>
 </div>
 </div>
 </div>
 <div class="section" id="the-chlocale-filter">
-<h2>The <tt class="docutils literal"><span class="pre">chlocale</span></tt> filter<a class="headerlink" href="#the-chlocale-filter" title="Permalink to this headline">¶</a></h2>
+<h3>The <tt class="docutils literal"><span class="pre">chlocale</span></tt> filter<a class="headerlink" href="#the-chlocale-filter" title="Permalink to this headline">¶</a></h3>
 <p>To add or change the locale prefix of a path use <tt class="docutils literal"><span class="pre">chlocale</span></tt>. It takes one
 argument: the new locale. If the path is locale-independent any prefix on the
 path will be stripped. This is also the case if
 <tt class="docutils literal"><span class="pre">settings.PREFIX_DEFAULT_LOCALE</span> <span class="pre">==</span> <span class="pre">False</span></tt> and the locale argument is the
 default locale.</p>
-<div class="section" id="id1">
-<h3>Examples<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
+<div class="section" id="examples">
+<h4>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h4>
 <p>To change the language of a URL to Dutch:</p>
 <div class="highlight-python"><pre>Please click &lt;a href="{{ help_url|chlocale:"nl" }}"&gt;here&lt;/a&gt; for Dutch help.</pre>
 </div>
 </div>
 <p>... then you can add a language selection menu in templates like this:</p>
 <div class="highlight-python"><pre>{% for lang in LANGUAGES %}
-        {% ifequal lang.0 LANGUAGE_CODE %}
-            &lt;li class="selected"&gt;{{ lang.1 }}&lt;/li&gt;
-        {% else %}
-            &lt;li&gt;&lt;a href="{{ request.path|chlocale:lang.0 }}"&gt;{{ lang.1 }}&lt;/a&gt;&lt;/li&gt;
-        {% endifequal %}
+    {% ifequal lang.0 LANGUAGE_CODE %}
+        &lt;li class="selected"&gt;{{ lang.1 }}&lt;/li&gt;
+    {% else %}
+        &lt;li&gt;&lt;a href="{{ request.path|chlocale:lang.0 }}"&gt;{{ lang.1 }}&lt;/a&gt;&lt;/li&gt;
+    {% endifequal %}
 {% endfor %}</pre>
 </div>
 </div>
 </div>
 <div class="section" id="the-rmlocale-filter">
-<h2>The <tt class="docutils literal"><span class="pre">rmlocale</span></tt> filter<a class="headerlink" href="#the-rmlocale-filter" title="Permalink to this headline">¶</a></h2>
+<h3>The <tt class="docutils literal"><span class="pre">rmlocale</span></tt> filter<a class="headerlink" href="#the-rmlocale-filter" title="Permalink to this headline">¶</a></h3>
 <p>You can use the <tt class="docutils literal"><span class="pre">rmlocale</span></tt> filter to remove the locale prefix from a path. It
 takes no arguments.</p>
-<div class="section" id="id2">
-<h3>Examples<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
+<div class="section" id="id1">
+<h4>Example<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h4>
 <p>To remove the language prefix for a URL:</p>
 <blockquote>
 The language-independent URL for this page is &lt;tt&gt;{{ request.path|rmlocale }}&lt;/tt&gt;.</blockquote>
 </div>
 </div>
 </div>
+<div class="section" id="views">
+<h2>Views<a class="headerlink" href="#views" title="Permalink to this headline">¶</a></h2>
+<p>The application supplies a view to change the locale.</p>
+<div class="section" id="the-change-locale-view">
+<h3>The <tt class="docutils literal"><span class="pre">change_locale</span></tt> view<a class="headerlink" href="#the-change-locale-view" title="Permalink to this headline">¶</a></h3>
+<p>Instead of the language selection menu shown in the <tt class="docutils literal"><span class="pre">chlocale</span></tt> example above,
+you can use the <tt class="docutils literal"><span class="pre">localeurl_change_locale</span></tt> view to switch to a different
+language. It is designed to mimic the Django <tt class="docutils literal"><span class="pre">set_language</span></tt> <a class="reference external" href="http://docs.djangoproject.com/en/dev/topics/i18n/#the-set-language-redirect-view">redirect view</a>.</p>
+<div class="section" id="id2">
+<h4>Example<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h4>
+<p>This form shows a drop-down box to change the page language:</p>
+<div class="highlight-python"><pre>{% load i18n %}
+
+&lt;form id="locale_switcher" method="POST" action="{% url localeurl_change_locale %}"&gt;
+    &lt;select name="language" onchange="$('#locale_switcher').submit()"&gt;
+        {% for lang in LANGUAGES %}
+            &lt;option value="{{ lang.0 }}" {% ifequal lang.0 LANGUAGE_CODE %}selected="selected"{% endifequal %}&gt;{{ lang.1 }}&lt;/option&gt;
+        {% endfor %}
+    &lt;/select&gt;
+    &lt;noscript&gt;
+        &lt;input type="submit" value="Set" /&gt;
+    &lt;/noscript&gt;
+&lt;/form&gt;</pre>
+</div>
+</div>
+</div>
+</div>
+</div>
 
 
    
 Changelog
 ---------
 
+Repository:
+  * Added the ``change_locale`` view, contributed by Panos Laganakos.
+
 Release 1.3: (2009-04-06)
   * Changed chlocale tag to strip prefix of locale-independent paths.
   * Moved the monkey-patching of urlresolvers.reverse to models.py.

docs/installation.rst

 Installation
 ------------
 
-Installation basically consists of installing the middleware. If you want to
-use the template tags and filters also add localeurl to the installed
-applications.
+Installation basically consists of installing the middleware and adding
+``'localeurl'`` to the installed applications list.
 
 #. Place the ``localeurl`` module in your Python path. You can put it into your
    Django project directory or run ``python setup.py install`` from a shell.
 
 #. Add ``'localeurl'`` to ``settings.INSTALLED_APPS``. Because the application
    needs to replace the standard ``urlresolvers.reverse`` function, it is
-   important to place it high in the list.
+   important to place it at the top of the list::
+
+     INSTALLED_APPS = (
+         'localeurl',
+         ...
+     )
+
+#. If you want to use the view, include the localeurl URLconf module in your
+   project::
+
+     urlpatterns = patterns('',
+         ...
+         (r'^localeurl/', include('localeurl.urls')),
+         ...
+     )
 
 #. Make sure ``settings.LANGUAGE_CODE`` or its root language is in
    ``settings.LANGUAGES``. For example, if ``LANGUAGE_CODE == 'en-us'`` then
 ``/fr/about/`` if French is the default language. (This behavior can be changed
 using ``settings.PREFIX_DEFAULT_LOCALE``.)
 
+Templates
+=========
+
 The application adds one template tag and two filters. Add the following at the
 top of a template to enable them::
 
 
 
 The ``locale_url`` tag
-----------------------
+~~~~~~~~~~~~~~~~~~~~~~
 
 The localeurl application replaces the ``urlresolvers.reverse`` function to
 return locale-specific URLs, so existing templates should not need to be
 ``locale_url`` tag. This tag behaves exactly like the standard ``url`` tag,
 except you specify a language.
 
-Examples
-^^^^^^^^
+Example
+-------
 
 You can refer to a specific URL in a specified language like this::
 
 
 
 The ``chlocale`` filter
------------------------
+~~~~~~~~~~~~~~~~~~~~~~~
 
 To add or change the locale prefix of a path use ``chlocale``. It takes one
 argument: the new locale. If the path is locale-independent any prefix on the
 default locale.
 
 Examples
-^^^^^^^^
+--------
 
 To change the language of a URL to Dutch::
 
-	Please click <a href="{{ help_url|chlocale:"nl" }}">here</a> for Dutch help.
+    Please click <a href="{{ help_url|chlocale:"nl" }}">here</a> for Dutch help.
 
 This filter can be used to allow users to go to a different language version of
 the same page. If you have this in your settings file::
 
-	_ = lambda s: s
-	LANGUAGES = (
-	    ('en', _(u'English')),
-	    ('nl', _(u'Nederlands')),
-	    ('de', _(u'Deutsch')),
-	    ('fr', _(u'Français')),
-	)
-	TEMPLATE_CONTEXT_PROCESSORS = (
-	    'django.core.context_processors.request',
-	    'django.core.context_processors.i18n',
-	    ...
-	)
+    _ = lambda s: s
+    LANGUAGES = (
+        ('en', _(u'English')),
+        ('nl', _(u'Nederlands')),
+        ('de', _(u'Deutsch')),
+        ('fr', _(u'Français')),
+    )
+    TEMPLATE_CONTEXT_PROCESSORS = (
+        'django.core.context_processors.request',
+        'django.core.context_processors.i18n',
+        ...
+    )
 
 ... then you can add a language selection menu in templates like this::
 
-	{% for lang in LANGUAGES %}
-		{% ifequal lang.0 LANGUAGE_CODE %}
-		    <li class="selected">{{ lang.1 }}</li>
-		{% else %}
-		    <li><a href="{{ request.path|chlocale:lang.0 }}">{{ lang.1 }}</a></li>
-		{% endifequal %}
-	{% endfor %}
+    {% for lang in LANGUAGES %}
+        {% ifequal lang.0 LANGUAGE_CODE %}
+            <li class="selected">{{ lang.1 }}</li>
+        {% else %}
+            <li><a href="{{ request.path|chlocale:lang.0 }}">{{ lang.1 }}</a></li>
+        {% endifequal %}
+    {% endfor %}
 
 The ``rmlocale`` filter
------------------------
+~~~~~~~~~~~~~~~~~~~~~~~
 
 You can use the ``rmlocale`` filter to remove the locale prefix from a path. It
 takes no arguments.
 
-Examples
-^^^^^^^^
+Example
+-------
 
 To remove the language prefix for a URL:
 
-	The language-independent URL for this page is <tt>{{ request.path|rmlocale }}</tt>.
+    The language-independent URL for this page is <tt>{{ request.path|rmlocale }}</tt>.
+
+Views
+=====
+
+The application supplies a view to change the locale.
+
+The ``change_locale`` view
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Instead of the language selection menu shown in the ``chlocale`` example above,
+you can use the ``localeurl_change_locale`` view to switch to a different
+language. It is designed to mimic the Django ``set_language`` `redirect view`_.
+
+.. _`redirect view`: http://docs.djangoproject.com/en/dev/topics/i18n/#the-set-language-redirect-view
+
+Example
+-------
+
+This form shows a drop-down box to change the page language::
+
+  {% load i18n %}
+
+  <form id="locale_switcher" method="POST" action="{% url localeurl_change_locale %}">
+      <select name="language" onchange="$('#locale_switcher').submit()">
+          {% for lang in LANGUAGES %}
+              <option value="{{ lang.0 }}" {% ifequal lang.0 LANGUAGE_CODE %}selected="selected"{% endifequal %}>{{ lang.1 }}</option>
+          {% endfor %}
+      </select>
+      <noscript>
+          <input type="submit" value="Set" />
+      </noscript>
+  </form>

localeurl/urls.py

+from django.conf.urls.defaults import *
+from localeurl.views import change_locale
+
+urlpatterns = patterns('',
+	url(r'^change/', change_locale, name='localeurl_change_locale'),
+)

localeurl/views.py

+from urlparse import urlsplit
+from django import http
+from django.utils.translation import check_for_language
+from localeurl import utils
+
+def change_locale(request):
+    """
+    Redirect to a given url while changing the locale in the path
+    The url and the locale code need to be specified in the
+    request parameters.
+    """
+    next = request.REQUEST.get('next', None)
+    if not next:
+        next = request.META.get('HTTP_REFERER', None)
+    if not next:
+        next = '/'
+    next = urlsplit(next).path
+    _, path = utils.strip_path(next)
+    if request.method == 'POST':
+        locale = request.POST.get('locale', None)
+        if locale and check_for_language(locale):
+            path = utils.locale_path(path, locale)
+
+    response = http.HttpResponseRedirect(path)
+    return response