gpt4 book ai didi

python - Django makemessages 命令生成错误 : "xgettext: Non-ASCII string"

转载 作者:行者123 更新时间:2023-12-02 04:35:04 25 4
gpt4 key购买 nike

我有一个简单的 django 项目。我正在尝试将该网站翻译成俄语。这是我的 settings.py 文件:

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'n_gc#7lsv48h-b$)9aw6eer6z$zia#@da=bdwgova1=6u!8uvh'

# 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',
]

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 = 'omefx.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR+'/omefx/templates'],
'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',
'django.template.context_processors.i18n',
],
},
},
]

WSGI_APPLICATION = 'omefx.wsgi.application'


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

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}



LANGUAGES = (
('en', ('English')),
('ru', ('Russian')),
)

LOCALE_PATHS = (
os.path.join(BASE_DIR +'/omefx/', 'locale'),
'locale',
# os.path.join(PROJECT_DIR, 'locale'),
)
# Password validation
# https://docs.djangoproject.com/en/1.10/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/1.10/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

STATICFILES_DIRS = (os.path.join(BASE_DIR+'/omefx/', 'static'), )

在我的模板中,我有一个用于测试的 {% trans %} 标记:

<h2>{% trans '160+ TRADING INSTRUMENTS' %}</h2> 

当我运行以下命令时:

python manage.py makemessages -l ru

我收到以下错误:

xgettext: Non-ASCII string at ./myvenv/lib/python3.6/site-packages/pip/_vendor/webencodings/__init__.py:64.
Please specify the source encoding through --from-code or through a comment
as specified in http://www.python.org/peps/pep-0263.html.

旁注:我的项目中没有应用程序。我的 Locale 文件夹路径是 omefx/omefx/locale 以及我的 templates 文件夹。

最佳答案

我在类似问题中找到了解决方案。找到产生错误的文件所在目录,并在执行manage.py makemessages命令时忽略它们。

因此,如果您的 venv 文件夹产生错误,请使用 makemessages 命令,如下所示:

manage.py makemessages -l ru -i venv

链接到其他问题: Django makemessages errors Unknown encoding "utf8"

关于python - Django makemessages 命令生成错误 : "xgettext: Non-ASCII string",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45078011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com