Multilingual website

0

I'm trying to put a Python / Django site as a multilanguage, but I could not understand how to actually do the documentation or what I found on the Internet, I even found one here in StackOverflow itself and I did not quite understand it either. Someone could help me

As an example I would like to have:

meusite.com/pt
meusite.com/en
    
asked by anonymous 03.04.2018 / 14:36

1 answer

0

So, as you have not posted your code, I'm going to put a very basic Django 2.0.x-based

In your settings.py file, you need to set the following values:

LANGUAGE_CODE = 'en'
USE_I18N = True
LANGUAGES = [
    ('en', 'English'),
    ('pt-br', 'Português'),
]
TEMPLATES = [
    {
        # outras definições
        'OPTIONS': {
            'context_processors': [
                # outras definições
                'django.template.context_processors.i18n',
            ],
        },
    },
]
MIDDLEWARE = [
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
]

Now, your urls.py file should contain:

urlpatterns = [
    # todas as suas urls aqui que NÃO precisam do prefixo do prefixo de idioma
    url(r'^i18n/', include('django.conf.urls.i18n')),
]

urlpatterns += i18n_patterns(
    # AQUI entram suas urls que precisam do prefixo de idioma
)

This is the super basic. I hope it works.

    
04.04.2018 / 11:23