gpt4 book ai didi

python - Django 中何时使用语言环境名称和语言代码?

转载 作者:行者123 更新时间:2023-12-03 09:40:09 25 4
gpt4 key购买 nike

根据 Django Documentation :

locale name

A locale name, either a language specification of the form ll or acombined language and country specification of the form ll_CC.Examples: it, de_AT, es, pt_BR. The language part is always inlower case and the country part in upper case. The separator is anunderscore.

language code

Represents the name of a language. Browsers send the names of thelanguages they accept in the Accept-Language HTTP header using thisformat. Examples: it, de-at, es, pt-br. Language codes aregenerally represented in lower-case, but the HTTP Accept-Languageheader is case-insensitive. The separator is a dash.


问题:
  • 当我看到ites在某人的代码中,我怎么知道它是语言环境名称还是语言代码?
  • 我们什么时候应该使用区域设置代码,什么时候使用语言代码?
  • 最佳答案

    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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com