@clean-jsdoc-theme/bhasha

中文文档
5.2.1发布于 2026/10/24MITTypeScriptES Module构建来源已验证近 30 天下载 2.2万

Pure, browser-safe i18n core for clean-jsdoc-theme (catalog, t, provider, key scheme, validation)

原始使用文档
文档目录7 节
  1. What's here
  2. Chrome catalog
  3. t + provider
  4. API slot keys + staleness
  5. Validation primitives
  6. Contributors
  7. License

@clean-jsdoc-theme/bhasha

The pure, browser-safe i18n runtime. The disk-bound extract/translate/build pipeline lives in @clean-jsdoc-theme/aadesh.

The internationalization core for clean-jsdoc-theme. bhasha is isomorphic — zero node:* — because rang bundles it into the browser. It holds the translatable chrome catalog, the t translator and its fallback chain, the LanguageProvider static carrier, the API-slot key scheme, and the validation primitives. setu and aadesh import its key/hash helpers so they agree on slot identity + staleness. The full localization walkthrough is in Localize your docs.

What's here

Chrome catalog

EN_CHROME is the canonical list of UI strings, authored as a nested object and flattened to dotted chrome.* keys. The key union is derived from the catalog, so every t('chrome.…') call is compile-checked.

import { EN_CHROME, EN_CHROME_FLAT, type ChromeKey } from '@clean-jsdoc-theme/bhasha';

t + provider

LanguageProvider is a static carrier — an immutable per-render value, no setter (locale is a build dimension, not a runtime toggle). With no provider, t returns exact English (the byte-identical no-locale baseline).

import { LanguageProvider, useTranslation, createI18n } from '@clean-jsdoc-theme/bhasha';

function ThemeButton() {
  const { t } = useTranslation();
  return <button title={t('chrome.theme.toggleTitle')}>{t('chrome.theme.switchTo', { mode: 'dark' })}</button>;
}

// Seed an island root (browser) or a page render (SSR):
const i18n = createI18n({ locale: 'fr', messages: { 'chrome.theme.toggleTitle': 'Basculer le thème' } });
<LanguageProvider value={i18n}>{/* … */}</LanguageProvider>;

Fallback chain: active locale → default locale → the key (chrome) or the source text (translateSlot, API slots). An empty value counts as untranslated and falls through.

Interpolation is simple named {token} substitution (t(key, { count: 3 })); ICU plurals are deferred.

API slot keys + staleness

import { apiSlotKey, sourceHash } from '@clean-jsdoc-theme/bhasha';

apiSlotKey('Foo#bar', ['params', '0', 'description']); // 'api.Foo#bar#params.0.description'
sourceHash('The Foo class.'); // '9d6177d6' — FNV-1a; changes when source text changes

Validation primitives

Built on the theme's diagnostics spine (DiagnosticBag / suggestKey from @clean-jsdoc-theme/utils). A gap warns; a malformation errors, reported against the key.

import {
  validateCatalogShape, // missing → warn, unknown → error (+ "did you mean?")
  catalogCoverage, // { translated, total, ratio }
  lintSlotMarkdown, // unbalanced fence / {@link} / braces → error
  validateTokenParity, // dropped/added {token} → error
} from '@clean-jsdoc-theme/bhasha';

Contributors

Thanks to everyone who has helped build clean-jsdoc-theme.

Contributors

License

MIT.

版本与发布记录

@clean-jsdoc-theme/bhasha 共发布 18 个版本,首次发布于 2026/06/10;过去 12 个月发布了 18 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.2.1latest2026/10/2416 天前
5.2.02026/08/282 个月前
5.1.12026/07/293 个月前
5.1.02026/07/243 个月前
5.0.82026/07/183 个月前
5.0.72026/07/074 个月前

其他发布通道:next → 5.0.0-alpha.0。

关于 @clean-jsdoc-theme/bhasha 的常见问题

@clean-jsdoc-theme/bhasha 是什么?

Pure, browser-safe i18n core for clean-jsdoc-theme (catalog, t, provider, key scheme, validation)

如何安装 @clean-jsdoc-theme/bhasha?

在项目目录运行 npm install @clean-jsdoc-theme/bhasha,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:preact(^10.22.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@clean-jsdoc-theme/bhasha 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@clean-jsdoc-theme/bhasha 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@clean-jsdoc-theme/bhasha 可以商用吗?

@clean-jsdoc-theme/bhasha 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@clean-jsdoc-theme/bhasha 的下载量有多少?

根据 npm 官方下载统计,@clean-jsdoc-theme/bhasha 在 2026/10/10 – 2026/11/08 这 30 天内被下载 21,896 次,日均约 730 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@clean-jsdoc-theme/bhasha 还在维护吗?

最新版本 5.2.1 发布于 2026/10/24(16 天前);至今共发布 18 个版本,其中过去 12 个月发布了 18 个;首次发布于 2026/06/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。