As @g-andrade said, we can use cowlib
.
accept_language = "ja,en-US;q=0.9,en;q=0.8,zh-CN;q=0.7,zh;q=0.6"
:cow_http_hd.parse_accept_language(accept_language)
This code returns [{"ja", 1000}, {"en-us", 900}, {"en", 800}, {"zh-cn", 700}, {"zh", 600}]
.
Note that the cowlib
converts all letters in the country code to lowercase.