Skip to content

Commit

Permalink
Add Middleware section to README
Browse files Browse the repository at this point in the history
  • Loading branch information
silviolleite committed Nov 30, 2018
1 parent ae7c954 commit 4fb6b81
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,25 @@ LANGUAGES = [
Only languages listed in the `LANGUAGES` setting can be selected.
This example restricts languages that are available for automatic selection to German, English and Brazilian Portuguese

2. Markup the text to translation:
2. Add Middleware

To use LocaleMiddleware, add 'django.middleware.locale.LocaleMiddleware' to your MIDDLEWARE setting. Because middleware order matters, follow these guidelines:

- Make sure it’s one of the first middleware installed.
- It should come after SessionMiddleware, because LocaleMiddleware makes use of session data. And it should come before CommonMiddleware because CommonMiddleware needs an activated language in order to resolve the requested URL.
If you use CacheMiddleware, put LocaleMiddleware after it.

For example, your MIDDLEWARE might look like this:

```python
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
]
```

3. Markup the text to translation:

The format of `.po` files is straightforward. Each `.po` file contains a small bit of metadata, such as the translation maintainer’s contact information, but the bulk of the file is a list of messages – simple mappings between translation strings and the actual translated text for the particular language.

Expand All @@ -49,7 +67,7 @@ msgstr ""
```

3. Generate and compile it using the commands bellow:
4. Generate and compile it using the commands bellow:

- The first step is to create a message file for a new language:
```bash
Expand All @@ -63,6 +81,8 @@ django-admin compilemessages

For more detailed information on how to create language files it is suggested to read the documentation: [https://docs.djangoproject.com/en/2.1/topics/i18n/translation/#how-to-create-language-files](https://docs.djangoproject.com/en/2.1/topics/i18n/translation/#how-to-create-language-files)



Install
=====
Install from PyPI:
Expand Down

0 comments on commit 4fb6b81

Please sign in to comment.