根据 Django Documentation :
locale name
A locale name, either a language specification of the form
ll
or a combined language and country specification of the formll_CC
. Examples:it
,de_AT
,es
,pt_BR
. The language part is always in lower case and the country part in upper case. The separator is an underscore.language code
Represents the name of a language. Browsers send the names of the languages they accept in the Accept-Language HTTP header using this format. Examples:
it
,de-at
,es
,pt-br
. Language codes are generally represented in lower-case, but the HTTP Accept-Language header is case-insensitive. The separator is a dash.
问题:
it
或 es
在某人的代码中,我怎么知道它是语言环境名称还是语言代码? 最佳答案
setlocale(3)
可以理解区域设置代码调用和配置几种众所周知的格式的本地化,例如日期、时间和货币以及错误消息的语言。可用的语言环境取决于平台和系统。
语言代码建立在语言环境之上,但用于网络通信。在实践中,您应该在应用程序中处理请求和响应层的语言代码和区域设置代码,但区别并不严格,因为它们解决了相同的问题:本地化和国际化。
举个例子:Django 根据 Accept-Language header 设置语言,它使用语言代码格式,然后为应用程序设置相应的语言环境,从而选择与语言代码对应的语言环境代码。
因此可以肯定地说“语言代码是语言环境代码的序列化格式”:nl_NL.ISO-8859-15
序列化为 Accept-language: nl-NL
+ Accept-Charset: iso-8859-15
.重要的部分是在正确的情况下使用正确的形式,但 es
的含义总是 Spanish
,不管出身。
关于python - Django 中何时使用语言环境名称和语言代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43934963/