Brian Park
Brian Park

Reputation: 1

Why is the error occur when trying to chang language in django settings.py?

import os
#added to change LANGUAGES
from django.utils.translation import ugettext_lazy as _

#added to change LANGUAGES
LANGUAGES = [
    ('ko', _('Korean')),
    ('en', _('English')),
]
# 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/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '7)30po8g=7ex!bz-(&*$y84ewejhu$t4zf^$mnja&b2ibg52-&'

# 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',
    'CheckbomOX.apps.CheckbomoxConfig'
]

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

ROOT_URLCONF = 'Checkbom.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 = 'Checkbom.wsgi.application'


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

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


# Password validation
# https://docs.djangoproject.com/en/3.0/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.0/topics/i18n/

#LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'ko-kr'

#added to change LANGUAGES
LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale'),
)
#TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Seoul'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'

This is the my settings.py

I added

django.middleware.locale.LocaleMiddleware

at middleware

and also added

from django.utils.translation import ugettext_lazy as _

and also added

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

I also installed gettext 0.20.1.

I executed

python manage.py makemessages -l en

and

python manage.py makemessages -l ko

when I run django server,

?: (translation.E004) You have provided a value for the LANGUAGE_CODE setting that is not in the LANGUAGES setting.

error pops up. How do I fix this? I installed gettext static 0.20.1. in the local folder, en and kr folder was created and in both of those folder, there are django.po and django.mo.

Upvotes: 0

Views: 478

Answers (2)

youngminz
youngminz

Reputation: 1444

The LANGUAGE_CODE setting has changed since Django 3.0: To set the language to Korean, you should set the LANGUAGE_CODE setting to 'ko', not 'ko-KR'.

See also: https://devlog.jwgo.kr/2019/12/24/django-3-language-code-error/ (korean link)

Upvotes: 0

Jordan Brière
Jordan Brière

Reputation: 1070

The error is quite explicit:

?: (translation.E004) You have provided a value for the LANGUAGE_CODE setting that is not in the LANGUAGES setting.

LANGUAGE_CODE = 'ko-kr'

Is not in:

LANGUAGES = [
    ('ko', _('Korean')),
    ('en', _('English')),
]

Upvotes: 1

Related Questions