In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to carry out the international analysis of openstack horizon. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Concept
I18N internationalization, is the abbreviation of "Internationalization"
G11N Globalization is the abbreviation of "Globalization"
L10N Localization, short for "Localization"
Principle
The translation mechanism of Django is to use GNU gettext (http://www.gnu.org/software/gettext/)), specifically the Python standard module gettext.
Verify availability through gettext-- version
Start internationalization
Openstack_dashboard\ setting.py
MIDDLEWARE_CLASSES = ('django.contrib.sessions.middleware.SessionMiddleware',' django.middleware.locale.LocaleMiddleware', # needs to be placed after SessionMiddleware 'django.middleware.common.CommonMiddleware',) TEMPLATE_CONTEXT_PROCESSORS = (' django.core.context_processors.i18n', # enable i18n' django.contrib.auth.context_processors.auth',) LANGUAGES = (('en',' English')) ('zh-cn',' Simplified Chinese') LANGUAGE_CODE = 'zh-cn' # website default language LANGUAGE_COOKIE_NAME =' horizon_language' USE_I18N = True # enable i18n USE_L10N = True # enable l10n LOCALE_PATHS = ['django_start/locale',] step:
TEMPLATE_CONTEXT_PROCESSORS joins django.core.context_processors.i18n
Add django.middleware.locale.LocaleMiddleware to MIDDLEWARE_CLASSES. Note:
It should be placed behind SessionMiddleware and CacheMiddleware, and in front of other middleware.
LANGUAGE_CODE sets the default website language, such as en, zh-cn,it, de-at, es, pt-br
LANGUAGES sets all the languages supported by the website, such as ('en', utilising English'), ('zh-cn',u' Chinese'))
USE_I18N is set to True
Enable i18n Learning Center {% trans "Welcome You"%}-Learn Center {% blocktrans%} This will have {{value}} inside. {% endblocktrans%} using {% load i18n%} # in html
Variables in templates are not allowed in {% trans%}, only strings in single or double quotes can be used. If you need variables (placeholders) for translation, you can use {% blocktrans%}
In py, use from django.utils.translation import ugettext_lazy as _ CONSUMER_CHOICES = ('back-end', _ (' back-end')),)
Please refer to: openstack_dashboard/api/cinder.py
Used in js
Urls.py file
Urlpatterns = [url (r'^ admin/', include (admin.site.urls)), url (r'^ jsi18n/ (? P\ slots?) / $', 'django.views.i18n.javascript_catalog'), # define i18n on js]
In the html file
# introduce js file, and separate multiple app with +
In the js file
Var i18njs = gettext ('Welcome'); # directly use the global gettext to generate the language
Execute the following command in the django app directory to automatically retrieve the files that need to be translated and generate the corresponding po files
Django-admin.py makemessages-l zh_CN # django-admin.py makemessages-d djangojs-l zh_CN
Differences between django.po and djangojs.po files:
Strings in py and html files that need to be translated will be automatically recognized and added to the django.po file by running the above command
The string that needs to be translated in the external js file needs to be manually created in the djangojs.po file and written in the translation string.
Language compilation
After the language translation is complete, compile django.po and djangojs.po into a .mo file with the following command
Cd horizon & & django-admin compilemessagescd openstack_dashboard & & django-admin compilemessages
After the compilation is complete, you need to restart the project for multiple languages to take effect.
Language switching {% csrf_token%} {% get_language_info_list for LANGUAGES as languages%} {% for language in languages%} {{language.name_local}} ({{language.code}}) {% endfor%} Supplementary session db
You need to save the session in the database and generate the django_session by executing the following command in the project directory.
Python manage.py syncdb determines the language steps
LocaleMiddleware determines the user's language according to the following algorithm:
1. Find the django_ page key in the session of the current user; you can change it through LANGUAGE_COOKIE_NAME, for example: LANGUAGE_COOKIE_NAME = 'horizon_language'
It will look for a cookie.
3. If you can't find it yet, it will look for Accept-Language in the HTTP request header, which is sent by your browser and tell the server your language preference in order of priority.
Django will try every language in the header until it finds an available translation.
4. If all of the above fails, use the global LANGUAGE_CODE setting value.
This is the end of the international analysis on how to carry out openstack horizon. I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.