最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[整理]Python中设置locale时区所涉及到的国家的字符缩写的列表

Python crifan 4688浏览 0评论

折腾:

[已解决]Python中需要把时间格式化为上午下午加上时间

期间,关于设置locale:

Formatting Python Dates According to Locale | skybert.net

感觉设置local的参数:

# python3
import locale
import datetime
dt = datetime.datetime(2015, 11, 15, 16, 30)
locale.setlocale(locale.LC_ALL, “en_GB.utf8”)
print(dt.strftime(“%A, %d. %B %Y %I:%M%p”))
‘Tuesday, 15. November 2015 04:30pm’
locale.setlocale(locale.LC_ALL, “nb_NO.utf8”)
print(dt.strftime(“%A, %d. %B %Y %I:%M%p”))
‘tirsdag, 15. november 2015 04:30’

感觉是:

en_GB.utf8

nb_NO.utf8

想要设置中文应该是:

zh_cn.utf8

?

但是也看到了:

localization – What is the correct way to set Python’s locale on Windows? – Stack Overflow

-》

微软的MSDN中:

Language Strings (CRT)

Country/Region Strings (CRT)

缩写都不太一样啊。。

还是想要更完整,更权威的国家的字符缩写列表

想起来了:

去看locale函数参数,应该可以有说明

python locale setlocale

22.2. locale — Internationalization services — Python 2.7.12 documentation

->

RFC 1766 – Tags for the Identification of Languages

“In the primary language tag:

    –    All 2-letter tags are interpreted according to ISO standard

         639, “Code for the representation of names of languages” [ISO

         639].

    –    The value “i” is reserved for IANA-defined registrations

    –    The value “x” is reserved for private use. Subtags of “x”

         will not be registered by the IANA.

    –    Other values cannot be assigned except by updating this

         standard.

   The reason for reserving all other tags is to be open towards new

   revisions of ISO 639; the use of “i” and “x” is the minimum we can do

   here to be able to extend the mechanism to meet our requirements.

   In the first subtag:

    –    All 2-letter codes are interpreted as ISO 3166 alpha-2

         country codes denoting the area in which the language is

         used.

    –    Codes of 3 to 8 letters may be registered with the IANA by

         anyone who feels a need for it, according to the rules in”

22.2. locale — Internationalization services — Python 2.7.12 documentation

“locale.LC_TIME

Locale category for the formatting of time. The function time.strftime() follows these conventions.

locale.LC_ALL

Combination of all locale settings. If this flag is used when the locale is changed, setting the locale for all categories is attempted. If that fails for any category, no category is changed at all. When the locale is retrieved using this flag, a string indicating the setting for all categories is returned. This string can be later used to restore the settings.”

locale 中文 utf8

修改locale – Ubuntu中文

“编辑配置文件,将zh_US.UTF-8改为en_US.UTF-8,zh改为en

zh_CN.utf8”

ubuntu服务器中设置locale为中文仍然无效的解决方法 – Penguin

“安装中文语言包

apt-get install language-pack-zh-hans

然后添加中文支持

locale-gen zh_CN.UTF-8

zh_CN.utf8

LANG=”zh_CN.uft8″

LANGUAGE=”zh_CN.utf8″”

Locale (简体中文) – ArchWiki

-》此处并不需要去修改此处的微信公众号的Python的Flask所在的CentOS服务器中的locale

-》只是去把time格式化输出时,用到locale即可。

ISO 639

Lists of ISO 639 codes – Wikipedia, the free encyclopedia

List of ISO 639-1 codes – Wikipedia, the free encyclopedia

Language familyLanguage nameNative name639‑1639‑2/T639‑2/B639‑3639‑6Notes
Sino-TibetanChinese中文 (Zhōngwén), 汉语, 漢語zhzhochizho + 13macrolanguage

List of ISO 639-2 codes – Wikipedia, the free encyclopedia

zho / chi*zhozhChineseMacrolanguageLiving

ISO 639-3 – Wikipedia, the free encyclopedia

Chinesezhchi/zho[4][5]macrozho
Mandarinindividualcmn
Cantoneseindividualyue
Minnanindividualnan

ISO 3166 – 维基百科,自由的百科全书

“国际标准化组织的ISO 3166国际标准针对国家和地区编代码,有三部分:

ISO 3166-1有国际标准化组织(ISO)的标准国家代码。有二位字母代码、三位字母代码、以及三位数字代码。1974年首次出版。

ISO 3166-2定义国家或地区的主要行政区代码。

ISO 3166-3定义被取代的ISO 3166-1代码的代码。1998年首次出版。”

ISO 3166-1 – 维基百科,自由的百科全书

CNCHN156ISO 3166-2:CN 中国

ISO 3166-2:CN – 维基百科,自由的百科全书

ISO 3166-2:CN – Wikipedia, the free encyclopedia

ISO 639 vs 3166

c++ – Table of conversion of ISO-639/ISO-3166 based language/country locale name to Windows ones and back – Stack Overflow

截止目前,还没完全搞懂

只搞懂一部分:

CN:是ISO 3166-2中定义的,中国China的两位字母的缩写

-》对应的三位字母缩写是:CHN

有空再去深究。

转载请注明:在路上 » [整理]Python中设置locale时区所涉及到的国家的字符缩写的列表

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.187 seconds, using 22.16MB memory