簡體   English   中英

試圖在 windows 10 中執行 django-admin makemessages

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

我正在嘗試使用 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/'

並作為我的模板索引。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時,但最后該目錄不是用文件生成的。

對於此示例,我遵循本教程A Quick Intro to Translation in Django(國際化)

有什么建議嗎?

經過幾次嘗試和選擇。 我在我的案例中發現了錯誤。

如果您安裝任何 gettext 向導安裝,則無法安裝某些依賴庫。 (這是我的情況)。 根據django i18n 的帖子:確保你有 GNU gettext 工具Far的貢獻中修復了它。

根據 django 文檔,必須運行命令“ xgettext --version ”才能啟用國際化命令。 在我的情況下w64gcc_s_sjlj-1.dll它已經出局了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM