在django项目中管理多个语言目录的简单脚本。

django-modular-languages的Python项目详细描述


Django模块化语言

当前版本:0.5

此脚本自动创建和维护多个语言目录 在一个Django项目上。django中包含的当前语言维护工具 不管理通过django项目树保留的多个目录,此 剧本结束了。将此脚本与transifex客户端一起使用是一个非常好的选择。

如何安装

若要安装此脚本,必须将其复制到项目根目录中(同 目录为settings.py),或者您可以在 投影根并复制脚本。

配置django以使用脚本

Django(在我看来)有个坏习惯,把所有的应用程序都包含在 相同的变量:安装的应用程序,这不是一件好事,因为它不是 隔离用户应用程序。

你需要做的就是,将你的应用程序与django应用程序隔离开来, 创建另一个变量,例如myproject_apps,然后将它们联合到 已安装应用程序中的django。在本例中,项目应用程序具有 被分为三类:DjangoApApple,PixdPaTyl Apple应用程序(应用程序) 包括在项目中,但不是由团队开发)和myproject_apps,包括 只是我们开发的项目应用程序。

DJANGO_APPS = (
    # This list is from the builtin applications in django. Watch out for
    # applications that need some specific order, like django-grappelli in
    # this case. It's a third part app, but due to the load order, we must
    # put it here.
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.messages',
    'grappelli.dashboard',
    'grappelli',
    'django.contrib.admin',
    'django.contrib.comments',
)

THIRDPARTY_APPS = (
    # This list is from the third party software included in the project or
    # system-wide dependencies.
    'django_wysiwyg',
    'myproject.apps.userprofile',
    'myproject.apps.tagging',
    #'django_extensions',
)

MYPROJECT_MODULES = (
    # Modules created for the project and installed by default. You can add
    # here your own modules.
    'myproject.apps.accounts',
    'myproject.apps.proposals',
    'myproject.apps.news',
    'myproject.apps.debate',
    'myproject.apps.spaces',
    'myproject.apps.staticpages',
    'myproject.apps.cal',
)

INSTALLED_APPS = DJANGO_APPS + THIRDPARTY_APPS + MYPROJECT_MODULES

配置完应用程序变量后,必须声明 您将在项目中使用的语言和语言。如果你已经有了 多语言django项目很可能您已经有了这个 定义。如果没有,则必须使用lang_code:lang_name定义一个python字典。例如:

LANGUAGES = (
    ('es_ES', 'Espanol'),
    ('en_GB', 'English'),
    ('gl_ES', 'Galego'),
)

如何使用脚本

此脚本从命令行、项目根目录或脚本中运行 目录。如果你不把它排除在外,它就找不到 settings.py文件。它有三个基本命令:

  • make Creates (or updates) all the language catalogs in your project
  • compile Compiles after translation all the language catalogs
  • clean Removes all the language catalogs from the project. Asks for confirmation first

还有一个“帮助”命令,输出为:

$ ./generate_languages.py --help
usage: generate_languages.py [-h] {make,compile,clean} ...

e-cidadania language catalog generator. This script manages all the .po and
.mo files from templates, python code and javascript i18n (if used).

positional arguments:
    {make,compile,clean}
    make                Create all the language catalogs for translation,
                        including JavaScript.
    compile             Compile all the language catalogs for use.
    clean               Delete all the language catalogs. After this you will
                        have to rebuild the catalogs and translate them.

optional arguments:
-h, --help            show this help message and exit

例如,要创建或更新语言目录,命令为:

$ python generate_languages.py make

哪个输出应该是(我们以e-cidania项目为例):

>> Languages to generate:
 - Espanol
 - English
 - Galego

>> Installed applications:
 - accounts
 - proposals
 - news
 - debate
 - spaces
 - staticpages
 - cal

>> Generating language catalog: accounts
processing language es_ES
processing language en_GB
processing language gl_ES

>> Generating language catalog: proposals
processing language es_ES
processing language en_GB
processing language gl_ES

(after ending the standard catalogs it starts with JavaScript ones)

>> Generating JavaScript language catalog: accounts
processing language es_ES
processing language en_GB
processing language gl_ES

>> Generating JavaScript language catalog: proposals
processing language es_ES
processing language en_GB
processing language gl_ES

(etc., etc.)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用唯一的按钮标签单击按钮   代码生成如何使用Java codeModel为数组的特定索引赋值   java如何批量执行Camel SQL插入   java iText 7将ltv添加到现有签名   内存管理Java应用程序突然停止几天后(810)   带MySQL的java注册表单JavaFX在intellij中失败   如何使用eclipse为windows azure java项目启用远程调试   一种通用的java输入输出设计模式   java Android XML(RSS)忽略引号(“”)   java帮助:安卓中的8 X 10 2维按钮数组   java启动Android项目   JWrapper构建java应用程序   java如何在Android应用程序中设置基于日期/时间的默认页面加载?   java循环程序在完成后返回到起点   java Hibernate:更好的整体类还是多类映射?   回溯数独解算器的递归问题[Java]   java查找类用法   java如何在SpringWebFlow中将多个模型绑定到一个视图?