-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
locale / i18n #158
Comments
node humanize durationTLDR
const locale = new Intl.DateTimeFormat().resolvedOptions().locale
const lang = locale.startsWith('zh')
? locale.replace(/-/, '_')
: locale.split('-')[0]
// use humanize
import humanize from 'humanize-duration'
export function getDurationDisplay(costms: number) {
return humanize(costms, {
language: lang,
fallbacks: ['en'],
round: true,
})
}
// or use humanizer
// 在 type:module 项目中用上面 `humanize` , cjs dep in esm project
import {humanizer} from 'humanize-duration'
export const getDurationDisplay = humanizer({
language: lang,
fallbacks: ['en'],
round: true,
}) with
|
获取 localenode
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
规范
https://unicode-org.github.io/icu/userguide/locale/#the-locale-concept
ISO 639: language code
细分
zh
zho
或者chi
ISO 3166: country / region code
https://www.iso.org/obp/ui/#search
locale
Intl
APIDOC https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_%E5%8F%82%E6%95%B0
BCP-47
https://datatracker.ietf.org/doc/html/rfc5646#appendix-A
大小写不敏感, 只是习惯将
Script
/REGION
zh-Hans
:zh
是 language-code,Hans
是 script (书写形式)zh-Hans-CN
:CN
是 country-region-code, 在中国大陆地区使用简体书写的中文zh-CN
: 在中国大陆地区使用的中文zh-Hans-TW
: 这个有没有呢~库
humanize-duration
https://www.npmjs.com/package/humanize-duration#supported-languages
这是个简单的库, 写死了一些 language 的翻译, 需要传一个 ISO 639-1 的 language code, 但是中文特殊
zh_CN
/zh_TW
中文这两个不是language code
, 更像 localeThe text was updated successfully, but these errors were encountered: