问题描述
我正在尝试为 django-countries 只翻译一个特定的国家,而我的语言 (zh-hant) 尚未翻译。
我尝试在文档中添加示例
COUNTRIES_OVERRIDE = {
"NZ": _("Middle Earth"),"AU": None,"US": {
"names": [
_("United States of America"),_("America"),],},}
到我的 settings.py 的末尾,然后发生此错误:
CommandError: Unable to find a locale path to store translations for file manage.py
但恢复此设置没问题。
我不太明白如何添加此设置使其无法找到现有的语言环境路径。
LOCALE_PATHS = [
os.path.join(BASE_DIR,'locale')
]
不能解决我的问题
我的settings.py:
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
DEBUG = True
ALLOWED_HOSTS = []
SITE_ID = 1
# Application deFinition
INSTALLED_APPS = [
"...","django.contrib.admin","django.contrib.auth","django.contrib.contenttypes","django.contrib.sessions","django.contrib.messages","django.contrib.staticfiles","django.contrib.sites","django_countries","django_filters","django_registration","multiselectfield",]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware","django.contrib.sessions.middleware.SessionMiddleware","django.middleware.common.CommonMiddleware","django.middleware.csrf.CsrfViewMiddleware","django.contrib.auth.middleware.AuthenticationMiddleware","django.contrib.messages.middleware.MessageMiddleware","django.middleware.clickjacking.XFrameOptionsMiddleware","django.middleware.common.brokenLinkEmailsMiddleware",]
ROOT_URLconf = "mysite.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 = "mysite.wsgi.application"
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3","NAME": BASE_DIR / "db.sqlite3",}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/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.2/topics/i18n/
LANGUAGE_CODE = "zh-hant" # "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS,JavaScript,Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = "/static/"
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
from django.utils.translation import gettext_lazy as _
#I added the setting here
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)