尝试在windows10中执行django-admin-makemessages



我正试图在Windows 10中使用命令django admin makemessages-l pt br生成翻译文件,但遗憾的是,文件没有生成。以下是我遵循的步骤:

  1. 已从mlocati安装gettext库
  2. 我还尝试了django i18n中的几个选项:确保您有GNU gettext工具,这个过程更手动

因此,当我运行django admin makemessages-l pt br时,看起来django正在执行一些东西,但最终没有生成目录。

这里有一些代码的平静,我有

视图.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)

设置.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/'

作为我的模板index.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>

当我运行django admin makemessages-l pt br时,显示消息processing locale pt-br,但最后目录不是用文件生成的。

对于这个例子,我遵循本教程Django(国际化(中的翻译快速入门

有什么建议吗?

经过多次尝试和选择。我在我的箱子里发现了错误。

如果安装任何gettext向导安装,则无法安装某些依赖关系库。(这是我的情况(。根据帖子django i18n:确保你在Far的贡献中有GNUgettext工具,这个问题已经解决了。

根据django文档,命令">xgettext——版本";必须运行才能启用国际化命令。在我的案例中,w64gcc_s_sjlj-1.dll已退出。

最新更新