Django internationalization: prefix_default_language & language redirect

主宰稳场 提交于 2019-12-06 13:15:04

问题


I'm adding internationalization to my Django project. The idea of how it should work is the following:

  • When a user enters "/" i.e. the "homepage" we try to get his/her language preferences from our session. If it's not our default language (EN), we redirect the user to the local version, like /ES/, /RU/, /CN/, etc

  • If we have no such session data, we check Accept-Language and redirect the user to the local version if we support such

  • If we don't support user's Accept-Language OR if it's EN - we don't redirect user! we just show the "default language"

I.e. all "not default languages" should have their prefixes, but default one won't. Why the default language should have a prefix, right? )))

The issue is, I can't figure out how to set this logic. If I set prefix_default_language=False to disable the /EN/ prefix for default language, it also disables the "not default" redirect. I found a package that solves the problem: https://github.com/st4lk/django-solid-i18n-urls#behaviour settings.SOLID_I18N_USE_REDIRECTS = True but it doesn't work in Django 2+

I can't believe I'm the only one hating the default language prefixes )) Although I could not find any solution with both redirect and no prefix for the default language. Hope someone will advice something here 😅

来源:https://stackoverflow.com/questions/56393364/django-internationalization-prefix-default-language-language-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!