{"_id":"@1-/oslang","_rev":"3-4c849099a8fde60f5e08884b58a1035c","name":"@1-/oslang","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.0":{"name":"@1-/oslang","version":"0.1.0","keywords":["i18n","internationalization","language-detection","locale","oslang"],"author":{"name":"x-at-01@googlegroups.com"},"license":"MulanPSL-2.0","_id":"@1-/oslang@0.1.0","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/webc-site/npm/tree/main/oslang","bugs":{"url":"https://github.com/webc-site/npm/issues"},"dist":{"shasum":"66272336fb8c4e4da5189a74692790cb2a0331d9","tarball":"https://registry.npmjs.org/@1-/oslang/-/oslang-0.1.0.tgz","fileCount":6,"integrity":"sha512-PSNH1xXsbALUsJg+Z1gS5gmqlBesAAuO44cs5Vfo2z2ImjYoJqMLJa+jmFEO/VI08s6tu9wR2a763qQJRkZ6vg==","signatures":[{"sig":"MEYCIQDUekt9a/UvMkmFM2EgWkumUB5E0ePOYED7QqsKtHNfFAIhAJQNZOQ12mwWL1s3POvxdWGfqqoWcwiWCCInZoLk3cQP","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":6206},"type":"module","exports":{".":"./_.js","./*":"./*"},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/webc-site/npm.git","type":"git"},"_npmVersion":"11.16.0","description":"OS language detection utility. 操作系统语言检测工具","directories":{},"_nodeVersion":"26.2.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/oslang_0.1.0_1783076109119_0.17024936002009006","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@1-/oslang","version":"0.1.1","keywords":["i18n","internationalization","language-detection","locale","oslang"],"author":{"name":"x-at-01@googlegroups.com"},"license":"MulanPSL-2.0","_id":"@1-/oslang@0.1.1","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://github.com/webc-site/npm/tree/main/oslang","bugs":{"url":"https://github.com/webc-site/npm/issues"},"dist":{"shasum":"c7f70961c62180fd7d606e06ed6fcda27334de98","tarball":"https://registry.npmjs.org/@1-/oslang/-/oslang-0.1.1.tgz","fileCount":6,"integrity":"sha512-au7TbCJIlJLUD6sOssFzqQJIuZMQh8g99EIIywSyeoEW05WeY0tTRuLyIRmaEoc7gSRmu4T1Ha2wsoYfXqjbCg==","signatures":[{"sig":"MEYCIQDqMnpZnE2wJGp06kkQdk4yzip/rlteeUrXujifzj2xEgIhANp9Imqox2tUDFg1gx/I6PHK6SObar1amBLD2hsHF3dt","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":7522},"type":"module","exports":{".":"./_.js","./*":"./*"},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://github.com/webc-site/npm.git","type":"git"},"_npmVersion":"11.16.0","description":"OS language detection utility. 操作系统语言检测工具","directories":{},"_nodeVersion":"26.2.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/oslang_0.1.1_1783083403972_0.15131116494103614","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@1-/oslang","version":"0.1.2","description":"OS language detection utility. 操作系统语言检测工具","keywords":["i18n","internationalization","language-detection","locale","oslang"],"homepage":"https://github.com/webc-site/npm/tree/main/oslang","license":"MulanPSL-2.0","author":{"name":"x-at-01@googlegroups.com"},"repository":{"type":"git","url":"git+https://github.com/webc-site/npm.git"},"type":"module","exports":{".":"./_.js","./*":"./*"},"dependencies":{},"_id":"@1-/oslang@0.1.2","bugs":{"url":"https://github.com/webc-site/npm/issues"},"_nodeVersion":"26.2.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-i0+J6lcuhShDAJ5KJcO/m6+FnjYucv0Hu+bWPWQIEfwlEsqKr4mzIfyjAyVN9iw4Od880Ep1MySjwam+Br2gWA==","shasum":"787789a0eaad90efe87701a6cf77dd23b80266e7","tarball":"https://registry.npmjs.org/@1-/oslang/-/oslang-0.1.2.tgz","fileCount":6,"unpackedSize":7462,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIG2l7wagTNTBTMhRxkmQZ6VdxvJMoBapMU3V9fHBMkrFAiBLpuP87mY6ZufxydFYb9tyUSvtZJ0pCaPncz1BPzzxgA=="}]},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"directories":{},"maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/oslang_0.1.2_1783083899507_0.4593090630272507"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-03T10:55:08.872Z","modified":"2026-07-03T13:04:59.778Z","0.1.0":"2026-07-03T10:55:09.257Z","0.1.1":"2026-07-03T12:56:44.115Z","0.1.2":"2026-07-03T13:04:59.641Z"},"bugs":{"url":"https://github.com/webc-site/npm/issues"},"author":{"name":"x-at-01@googlegroups.com"},"license":"MulanPSL-2.0","homepage":"https://github.com/webc-site/npm/tree/main/oslang","keywords":["i18n","internationalization","language-detection","locale","oslang"],"repository":{"type":"git","url":"git+https://github.com/webc-site/npm.git"},"description":"OS language detection utility. 操作系统语言检测工具","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"readme":"[English](#en) | [中文](#zh)\n\n---\n\n<a id=\"en\"></a>\n# @1-/oslang : OS language detection utility\n\n- [@1-/oslang : OS language detection utility](#1-oslang-os-language-detection-utility)\n  - [Functionality](#functionality)\n  - [Usage demonstration](#usage-demonstration)\n  - [Design rationale](#design-rationale)\n  - [Technology stack](#technology-stack)\n  - [Code structure](#code-structure)\n  - [Historical context](#historical-context)\n  - [About](#about)\n\n## Functionality\n\nDetects user's preferred language from operating system environment variables and browser/system locale settings, with normalization and hierarchical matching support. Implements multi-level fallback (e.g., `zh-CN` → `zh`) to reliably select the best-fit language in internationalized applications.\n\n## Usage demonstration\n\n```bash\nnpm install @1-/oslang\n```\n\n```javascript\nimport oslang from \"@1-/oslang\";\nimport match from \"@1-/oslang/match.js\";\n\n// Get all normalized, deduplicated language tags, including parent languages\nconsole.log([...oslang]); // ['en-US', 'en', 'zh-CN', 'zh']\n\n// Match against a list of available languages\nconst available = [\"en\", \"zh\", \"ja\", \"ko\"];\nconst preferred = match(available).next().value;\nconsole.log(preferred); // 'zh' (if system is zh-CN) or undefined (if no match)\n```\n\n## Design rationale\n\nThe library uses a deterministic priority order: sources are tried sequentially, then results are normalized and expanded to include parent locales:\n\n![](https://fastly.jsdelivr.net/gh/webc-fs/-@05/KkimxJYpt2RAxO0otd9g.svg)\n\n## Technology stack\n\n- Node.js runtime (ESM modules)\n- Standard JavaScript (zero external dependencies)\n- `Intl.DateTimeFormat().resolvedOptions().locale` API\n- `node:process.env` for environment variable access\n\n## Code structure\n\n```\nsrc/\n├── _.js        # Main export: yields raw language sources (env + Intl + fallback)\n├── all.js      # Normalized set: deduplicated, lowercase, hyphen-separated, with auto-added parent languages (e.g., en-US → en)\n├── match.js    # Matching function: returns iterator yielding first matched item (original input)\n└── parse.js    # Normalization utility: strips encoding suffixes, replaces `_` with `-`, lowercases\n```\n\n## Historical context\n\nThe POSIX standard, first published in 1988 (IEEE Std 1003.1-1988), formally standardized `LC_*` environment variables (e.g., `LC_MESSAGES`, `LC_TIME`) to provide portable localization on Unix systems. `LANG` served as the default fallback, while `LANGUAGE` was later extended by GNU to support ordered language preference lists (e.g., `zh_CN:zh_TW`). This library carries forward that four-decade tradition, re-implementing its core semantics in modern JavaScript.\n\n## About\n\nThis library is developed by [WebC.site](https://webc.site).\n\n[WebC.site](https://webc.site): A new paradigm of web development for AI\n\n\n---\n\n<a id=\"zh\"></a>\n# @1-/oslang : 操作系统语言检测工具\n\n- [@1-/oslang : 操作系统语言检测工具](#1-oslang-操作系统语言检测工具)\n  - [功能介绍](#功能介绍)\n  - [使用演示](#使用演示)\n  - [设计思路](#设计思路)\n  - [技术栈](#技术栈)\n  - [代码结构](#代码结构)\n  - [历史故事](#历史故事)\n  - [关于](#关于)\n\n## 功能介绍\n\n从操作系统环境变量与浏览器/系统区域设置中检测用户首选语言，提供标准化处理与层级匹配能力。支持多级语言回退（如 `zh-CN` → `zh`），确保在国际化应用中可靠选择最适配的语言。\n\n## 使用演示\n\n```bash\nnpm install @1-/oslang\n```\n\n```javascript\nimport oslang from \"@1-/oslang\";\nimport match from \"@1-/oslang/match.js\";\n\n// 获取所有已标准化、去重且含父语言的语言标识符\nconsole.log([...oslang]); // ['en-US', 'en', 'zh-CN', 'zh']\n\n// 在可用语言列表中匹配最优项\nconst available = [\"en\", \"zh\", \"ja\", \"ko\"];\nconst preferred = match(available).next().value;\nconsole.log(preferred); // 'zh'（若系统为 zh-CN）或 undefined（若无匹配）\n```\n\n## 设计思路\n\n本库采用确定性优先级策略，按顺序尝试多种来源，并对结果进行标准化与层级扩展：\n\n![](https://fastly.jsdelivr.net/gh/webc-fs/-@ji/qto5w4WzYYganWuNzNEQ.svg)\n\n## 技术栈\n\n- Node.js 运行时（ESM 模块）\n- 标准 JavaScript（无外部依赖）\n- `Intl.DateTimeFormat().resolvedOptions().locale` API\n- `node:process.env` 环境读取\n\n## 代码结构\n\n```\nsrc/\n├── _.js        # 主导出：生成原始语言源（环境变量 + Intl + fallback）\n├── all.js      # 标准化集：去重、小写、短横线分隔，并自动添加父语言（如 en-US → en）\n├── match.js    # 匹配函数：返回迭代器，yield 首个匹配项（原始输入项）\n└── parse.js    # 标准化工具：移除编码后缀、下划线转短横线、转小写\n```\n\n## 历史故事\n\nPOSIX 标准于 1988 年首次发布（IEEE Std 1003.1-1988），正式将 `LC_*` 环境变量（如 `LC_MESSAGES`, `LC_TIME`）纳入规范，为 Unix 系统提供可移植的本地化机制。`LANG` 变量作为默认兜底，`LANGUAGE` 则被 GNU 系统扩展用于多语言优先级列表（如 `zh_CN:zh_TW`）。本库延续这一四十年传统，在现代 JavaScript 环境中轻量复现其核心语义。\n\n## 关于\n\n本库由 [WebC.site](https://webc.site) 开发。\n\n[WebC.site](https://webc.site) : 面向人工智能的网站开发新范式\n\n","readmeFilename":"README.md"}