为什么多语言在Ubuntu服务器上不起作用?

时间:2019-06-05 22:23:00

标签: python django ubuntu internationalization

为什么本地站点可以与i18n一起使用,而我却拥有类似于site.com/en类型的链接,而在Ubuntu服务器上,site.com链接不起作用并且翻译不起作用? set_language函数也不起作用。

urls.py

urlpatterns = [
path('admin/', admin.site.urls),
url(r'^i18n/', include('django.conf.urls.i18n')),

]\
          + static(settings.STATIC_URL, 
document_root=settings.STATIC_ROOT) \
          + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns += i18n_patterns(
    url(r'^$', views.index, name='index'),
)

forms.py

  <form class="lang-form" action="{% url 'set_language' %}" method="post">
        {% csrf_token %}
        <input name="next" type="hidden" value="{{ redirect_to }}" />
        <select name="language" onChange="this.form.submit();">
            {% get_current_language as LANGUAGE_CODE %}
            {% get_available_languages as LANGUAGES %}
            {% for lang in LANGUAGES %}
                <option class="decorated" value="{{ lang.0 }}" {% if 
lang.0 == LANGUAGE_CODE %} selected="selected"{% endif %}>
                    {% if lang.0 == 'uk' %}
                        ua
                    {% else %}
                       {{ lang.0 }}
                    {% endif %}
                </option>
            {% endfor %}
        </select>
  </form>

settings.py

...
LANGUAGES = (
('uk', _('Ukrainian')),
('ru', _('Russian')),
)

LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale'),
)

TIME_ZONE = 'Europe/Kiev'

USE_I18N = True

USE_L10N = True

USE_TZ = True

0 个答案:

没有答案