Skip to content

Instantly share code, notes, and snippets.

@rririanto
Last active February 20, 2021 01:09
Show Gist options
  • Save rririanto/4f0dc259ee3c957b9b3bce6cfb668d60 to your computer and use it in GitHub Desktop.
Save rririanto/4f0dc259ee3c957b9b3bce6cfb668d60 to your computer and use it in GitHub Desktop.
Settings Django Translation v1
from django.utils.translation import gettext_lazy as _
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
INSTALLED_APPS = (
...
"translation_manager",
...
)
# Setup LocaleMiddleware to enable translations using ugettext_lazy and ugettext
# Make sure that LocaleMiddleware comes after SessionMiddleware and before CommonMiddleware
MIDDLEWARE = [
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.locale.LocaleMiddleware",
"django.middleware.common.CommonMiddleware",
]
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
# True if you want to support localization
USE_I18N = True
# Default languages
LANGUAGE_CODE = "vi"
# Provide a lists of languages which your site supports.
LANGUAGES = (
('vi', _('Viet Nam')),
('en', _('English')),
)
# If you set this to False, Django will not format dates, numbers and
# Use calendars according to the current locale.
USE_L10N = True
# Contains the path list where Django should look into for django.po files for all supported languages
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment