Asma Gheisari
Asma Gheisari

Reputation: 6264

The set_language redirect view for internationalization won't work

for i18n I've done these steps,but I can't yet get it worked: in settings.py:

LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
LANGUAGES = (
    ('fa', gettext('Persian')),
    ('en', gettext('English')),
)
LOCALE_PATHS = (
    'fa/LC_MESSAGES/django.po',
    'fa/LC_MESSAGES/django.mo',
    'en/LC_MESSAGES/django.po',
    'en/LC_MESSAGES/django.mo',
    '$PYTHONPATH/django/conf/locale/fa/LC_MESSAGES'
)
MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.middleware.csrf.CsrfResponseMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
)

I've built mesage fiels in my app folder and compiled theme. I have created translation strings in the template. and to switch between languages I have this in my template:

<form action="/i18n/setlang/" method="post" class="forms">
{% csrf_token %}
<input name="next" type="hidden" value="/next/page/" />
<select name="language" id="select_langauge" class="m_show hide">
{% for lang in LANGUAGES %}
    {% if lang.0 != '' %}
        <option value="{{lang.0}}">{{lang.1}}</option>
    {% endif %}
{% endfor %}
</select>
<input type="submit" value="Go" />
</form>

and in urls.py :

(r'^i18n/', include('django.conf.urls.i18n'))

but when I submit this form to switch between languages,I have this error:

Page not found (404)
Request Method:     GET
Request URL:    http://127.0.0.1:8080/next/page/

Is there anything that I've ommited?

thanks in advance :)

Upvotes: 1

Views: 974

Answers (2)

boskicthebrain
boskicthebrain

Reputation: 545

You have to give the absolute paths to the locale - the folder that contain your translations. It goes something like this:

LOCALE_PATHS = (
    'C:/abolute_path_to_your_project/.../locale/',
)

The folder locale should contain your translations like this:

.../locale/
         - en/LC_MESSAGES/django.po
                          django.mo
         - fr/LC_MESSAGES/django.po
                          django.mo

Upvotes: 1

Denis Kabalkin
Denis Kabalkin

Reputation: 508

I think Django tries redirect you to /next/page/

<input name="next" type="hidden" value="/next/page/" />

But, you have not this path in your urls, isn't it?

Upvotes: 2

Related Questions