Django:LocaleMiddleware 检查哪个 url?

Django: which url does the LocaleMiddleware check?

我们公司提供 API 和少量通过 Iframe 嵌入客户网站的小部件。

现在我们有一位比利时客户希望使用我们的小部件。如您所知,比利时是双语国家,因此我们自由使用 LocaleMiddleware{% trans 'string' %} 标签。

现在我理解正确了,中间件会检查 URL 以查看要使用的语言。当您第一次访问我们的客户网站时,您会看到一个大型弹出窗口,您可以在其中选择您的语言。在此弹出窗口后,您的 url 更改为此格式:www.clientorg.be/fr_BE/rest-of-the-url,因此(希望)应该可以正常工作。

但是,我们的小部件是通过 Iframe 提供的。 (src = s2.oururl.com) 不包含语言值。

所以我的问题是:Django 能够检测用户的语言吗?或者它只能检查 'our' s2.url,这意味着我们需要联系我们的客户并向他提供 2 url 以粘贴到 iframe 中,具体取决于用户选择的语言.

这正是 LocalMiddleware 试图确定语言的方式: https://docs.djangoproject.com/en/2.0/topics/i18n/translation/

LocaleMiddleware tries to determine the user’s language preference by following this algorithm:

First, it looks for the language prefix in the requested URL. This is only performed when you are using the i18n_patterns function in your root URLconf. See Internationalization: in URL patterns for more information about the language prefix and how to internationalize URL patterns.

Failing that, it looks for the LANGUAGE_SESSION_KEY key in the current user’s session.

Failing that, it looks for a cookie.

The name of the cookie used is set by the LANGUAGE_COOKIE_NAME setting. (The default name is django_language.)

Failing that, it looks at the Accept-Language HTTP header. This header is sent by your browser and tells the server which language(s) you prefer, in order by priority. Django tries each language in the header until it finds one with available translations.

Failing that, it uses the global LANGUAGE_CODE setting.