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

标签 python django localization internationalization django-i18n

根据 Django Documentation :

locale name

A locale name, either a language specification of the form ll or a combined language and country specification of the form ll_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.


问题:
  • 当我看到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/

    相关文章:

    django - 在 Django Rest 中使用中间模型序列化多对多关系

    jquery - 我自己的点赞按钮: Django + Ajax -- How?

    django - 使用 Django Rest Framework 测试 CSRF 验证

    ios - 如何覆盖应用程序内部使用的当前语言

    Python - 如果或如果无效语法错误

    python - 使用 pytest_postgresql 进行测试时无法在测试数据库中创建表

    Python:将 JSON 对象转换为 JSON 数组

    python - 如何使用python在 Telegram 上发送照片

    ios - 使用 Localizable.strings 而不是 Root.strings 本地化 Settings.bundle

    ios - 新翻译不会在 iOS 8 中自动显示