用django创建多语言网站的一套工具
yawd-translations的Python项目详细描述
雅致翻译,创建多语种django网站
yawd-translations 提供一组工具,用于创建多语言网站 django。
应用程序包括以下工具:
通过管理界面管理网站的已安装语言
使用管理界面(无需重新启动web服务器)为所有已安装的应用程序和定义的语言生成翻译消息(makemessages和compilemessages)。
可翻译数据库模型api
管理数据库翻译的自定义admin inline
替换django.middleware.locale.LocaleMiddleware并实现以下功能的自定义中间件:
- Change the way django detects language preference and use the db default language (set through the admin interface)
- Redirects to language-dependant URLs are permanent (301) and not temporary (302).
一个patterns函数(其行为与django自己的i18n_patterns()非常相似)可以实现以下功能:
- Match root URL paths as default language URLs: If your default language is English (^{tt3}$), ^{tt4}$ will not match the ^{tt5}$ URL as the english homepage and the django middleware would redirect pages to their ^{tt6}$ equivalent (e.g. your homepage would be http://example.com/en/ and all requests to http://example.com/ would be redirected to http://example.com/en/). The custom patterns function implements the exact opposite, which is a common practice to web development. Therefore http://example.com/ will be matched as the real permalink (instead of http://example.com/en/). For non-default languages, the custom patterns function behaves like ^{tt7}$ does.
一个上下文处理器可以访问模板中的可用语言,一个简单的模板标记可以轻松地在前端网站中的页面可用翻译之间切换。
注意
yawd translations v0.5.2是最新版本 Django 1.4.目前的硕士学位是在django 1.5下积极开发的。 并且不适用于旧的django版本。对于那些还在使用 django 1.4,您可以签出0.5.x分支或使用yawd翻译 V0.5.2 PYPI包。新功能将不会被移植到0.5.x 分支因为我们中的许多人都运行与django 1.4相关的生产系统,所以 最新的文档将在readthedocs.org上在线发布。
使用和演示
见yawd-translations v0.5.2 documentation 有关如何安装演示和使用yawd翻译的信息。