简体   繁体   English

试图在 windows 10 中执行 django-admin makemessages

[英]Trying to execute django-admin makemessages in windows 10

I´m trying to generate translation file using command django-admin makemessages -l pt-br in Windows 10 but unfortunately the files aren´t generated.我正在尝试使用 Windows 10 中的命令django-admin makemessages -l pt-br生成翻译文件,但不幸的是这些文件没有生成。 Here the steps that I followed:这是我遵循的步骤:

  1. Installed gettext library from mlocati .mlocati安装 gettext 库。
  2. I also tried several options from django i18n: Make sure you have GNU gettext tools , this process is more manual.我还尝试了django i18n 的几个选项:确保你有 GNU gettext 工具,这个过程更加手动。

As the result when i run django-admin makemessages -l pt-br looks like that Django is executing something but the directory is not generated in the end.结果,当我运行django-admin makemessages -l pt-br时,看起来 Django 正在执行某些操作,但最终没有生成目录。

Here are some peace of code that I have这是我拥有的一些和平代码

views.py视图.py

from django.shortcuts import render
from django.utils.translation import gettext as _

def index(request):
    context = {
        'hello': _('Hello!')
    }
    return render(request, 'index.html', context)

settings.py设置.py

"""
Django settings for translation_example project.

Generated by 'django-admin startproject' using Django 3.1.7.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3^*d$5b7$r2$t-0cxmef22l5_)t^cn9i-xkq48zen$u*67)tvm'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'example',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',

]

ROOT_URLCONF = 'translation_example.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'translation_example.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale'),
)


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'

And as my template index.html并作为我的模板索引。html

{% load i18n %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <h1>{{ hello }}</h1>
    <h2>{% trans "My name is SpeedJr" %}</h2>
</body>
</html>

When I run django-admin makemessages -l pt-br shows message processing locale pt-br , but at end the directory is not generate with files.当我运行django-admin makemessages -l pt-br显示消息processing locale pt-br时,但最后该目录不是用文件生成的。

For this example I following this tutorial A Quick Intro to Translation in Django (Internationalization)对于此示例,我遵循本教程A Quick Intro to Translation in Django(国际化)

Any suggestion?有什么建议吗?

After several tryings and options.经过几次尝试和选择。 I found the error in my case.我在我的案例中发现了错误。

If you install any gettext wizard installation some dependences library could not be instaled.如果您安装任何 gettext 向导安装,则无法安装某些依赖库。 (It was my case). (这是我的情况)。 According with the post django i18n: Make sure you have GNU gettext tools in the contribution of Far the problem it was fixed.根据django i18n 的帖子:确保你有 GNU gettext 工具Far的贡献中修复了它。

According with django documentation, the command " xgettext --version " must be run to enable internationalization command.根据 django 文档,必须运行命令“ xgettext --version ”才能启用国际化命令。 In my case w64gcc_s_sjlj-1.dll it was out.在我的情况下w64gcc_s_sjlj-1.dll它已经出局了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有什么方法可以通过运行“ django-admin makemessages -l ja”来执行定制的makemessages命令? - Is there any way to execute custom makemessages command by running “django-admin makemessages -l ja”? django-admin makemessages =&gt;用我的翻译所有django包 - django-admin makemessages => translate all django package with mine “django-admin makemessages”是否有任何解决方法是不对已更新的翻译进行更改? - is there any work around for “django-admin makemessages” not to make changes to already updated translations? django-admin makemessages:如何与txt,xml和其他文件一起使用? - django-admin makemessages: how does it work with txt, xml and other files? 未检测到 Django-admin - windows - Django-admin isn't detected - windows 在 windows powershell 上使用 django-admin - Using django-admin on windows powershell 'django-admin' 不是内部或外部命令,也不是可运行的程序或批处理文件。 Windows10 - 'django-admin' is not recognized as an internal or external command, operable program or batch file. Windows10 在尝试创建 django-admin startproject 时:没有模块名称 django-admin - while trying to create django-admin startproject :No module name django-admin 运行django-admin - Run django-admin Django-admin 属性错误: - Django-admin AttributeError:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM