Multilingual site

Asked

Viewed 51 times

0

I’m trying to put a site made in Python/Django as multilingual, but I could not understand how to actually do with the documentation or what I found on the Internet, I even found one here in Stackoverflow English itself and also did not understand very well. Could someone help me

As an example I would like to have:

meusite.com/pt
meusite.com/en
  • I don’t understand very well what you need, you already have the sites and need to make them work or want to know how to make multilingual sites?

  • I have site already in Portuguese, I need to make it has its English version and receive at the end of the url /en

  • Boy this theme is a bit extensive to deal with here, but to start search google about htaccess that makes the pages and index.php (if using php, of course) you must make the proper implementations of includes and Translators, you can use two compositions of pages each with your language or you can use tools like php-gettext and so on...

  • Ha, sorry I didn’t mention, but the site is in python-Django, I just put the tag on the question. I just tidied up the question.

  • So, I do it in PHP, but the logic is the same, you have to use tools for this or create the sites in different links and redirect to the page you need.

1 answer

0

So, since you didn’t post your code, I’ll put a super basic based on Django 2.0.x

In your file settings.py, you need to define 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, in your file urls.py must 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 fits.

  • 1

    Thanks, as soon as I test I give a feedback if I got.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.