Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize i18n multilingual internationalization in Django 2.2

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to achieve i18n multilingual internationalization in Django 2.2. the content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Set up in setting.py:

# LANGUAGE_CODE = 'en-us'LANGUAGE_CODE =' the directory where the zh-hans'# translation file is located. You need to manually create LOCALE_PATHS = (os.path.join (BASE_DIR, 'locale'),) TIME_ZONE =' Asia/Shanghai'USE_I18N = TrueUSE_L10N = True

Add 'django.middleware.locale.LocaleMiddleware':' to MIDDLEWARE

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

Add 'django.template.context_processors.i18n'' to TEMPLATES

TEMPLATES = [{'BACKEND':' django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join (BASE_DIR,' templates')], 'APP_DIRS': True,' OPTIONS': {'context_processors': [' django.template.context_processors.i18n', 'django.template.context_processors.debug' 'django.template.context_processors.request',' django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages',],},},]

Mkdir-p locale

Django-admin makemessages-l zh_Hans

Django-admin compilemessages

Or

Python3 django-admin makemessages-l zh_Hans

Python3 django-admin compilemessages

The above is how to achieve i18n multilingual internationalization in Django 2.2. have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report