资源说明:Multi-language experiment for django applications
And experimental multilang structure for django applications. The key is to define a kwarg on every view that supports multilanguage. On views that are not supposed to have multilanguage version, use the @nomultilang decorator. As an example, see the main utls.py file where thete is two mapping to the same django-application view. For example, here we have a "blog" app. This blog decalres some views and some URL mapping in blog/urls.py. In the main urls.py we map the twice: * One for the URL without the language * Another with a regex that extracts the language into the "lang" parameter Based on this and supposing we attached the "blog" app at /blog we can access: * /blog/* * /en/blog/* * /pt_BR/blog/* and the language will be passed as a keywork argument to the specified view. Check the views at blog/views.py For views that "do not support" multi lingual results you can use, for example, a decorator that removes the "lang" keyword argument. This is needed because as we mapped the blog app twice, we don't know with of the URLS the will access. That's it! this is just an idea that can be implemented so one can have multi-lang URLS on any django-app. Things to test * How do we maintain a user on the same language as he clicks around on the site? If we came to the site with /en/blog/post/3, if he clicks on another link he must be sent to /en/blog/* and not just /blog/*. Don't know how {%url%} will behave with the idea of a view being mapped twice on urls.py R: Create a custom templatetag to resolve urls. It uses reverse() internally but adds the lang prefix. For this we *must* include the value of the current lang into the template context. Maybe a new "render_to_response" that adds the lang and calls the original render_to_response. This way the templatetag will have access to the lang value and will be able to remount the url. Take special care of applications not depolyed on the root of the webservice. Maybe an app attached at: /myapp/pt. {%mytagurl blog%}, must return /myapp/pt/blog, and not /pt/myapp/blog. This could be hard to do because the original reverse() will return the full URL, *already* containing /myapp. So maybe we need to add to the context the request.path_info, so the templatetag can "inject" the language between the "path_info" and the remaining URL.
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。