@betteroffice/docx-i18n

中文文档
0.5.1发布于 2026/10/27Apache-2.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 8.5万

UI locale strings and types for the @betteroffice/docx-react editor.

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. Locales
  4. Helpers
  5. Documentation

@betteroffice/docx-i18n

UI strings, locale types and translation helpers for the @betteroffice/docx-react editor. en defines the strings; the other locales override them.

Install

bun add @betteroffice/docx-i18n

Usage

Pass a locale to the editor's i18n prop:

import { de } from '@betteroffice/docx-i18n';
import { DocxEditor } from '@betteroffice/docx-react';

export function Editor({ file }: { file: File }) {
  return <DocxEditor documentBuffer={file} i18n={de} />;
}

Override individual strings by spreading a locale. Keys that are missing or null fall back to English.

const custom = { ...de, formattingBar: { ...de.formattingBar, bold: 'Fettdruck' } };

Locales

en (source), de, fr, he, hi, id, pl, pt-BR, tr and zh-CN. The exports for pt-BR and zh-CN are ptBR and zhCN.

Each locale is also its own subpath, for example @betteroffice/docx-i18n/pl, so an app that picks the locale at runtime can load only the one it needs. locales maps every tag to its strings and bundles all of them.

Helpers

The package exports the types LocaleStrings, PartialLocaleStrings, Translations, TranslationKey, LocaleCode and TFunction, and the functions createT and deepMerge. Outside React, build a typed t() directly:

import { createT, deepMerge, en, de, type LocaleStrings } from '@betteroffice/docx-i18n';

const t = createT(deepMerge(en, de) as LocaleStrings, 'de');
t('formattingBar.bold'); // 'Fett'

Documentation

版本与发布记录

@betteroffice/docx-i18n 共发布 14 个版本,首次发布于 2026/07/19;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.1latest2026/10/2712 天前
0.5.02026/10/2613 天前
0.4.32026/10/031 个月前
0.4.22026/10/031 个月前
0.4.12026/10/011 个月前
0.4.02026/10/011 个月前

关于 @betteroffice/docx-i18n 的常见问题

@betteroffice/docx-i18n 是什么?

UI locale strings and types for the @betteroffice/docx-react editor.

如何安装 @betteroffice/docx-i18n?

在项目目录运行 npm install @betteroffice/docx-i18n,或使用 pnpm add / yarn add / bun add。

@betteroffice/docx-i18n 支持 TypeScript 吗?

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

@betteroffice/docx-i18n 支持 ESM 还是 CommonJS?

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

@betteroffice/docx-i18n 可以商用吗?

@betteroffice/docx-i18n 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@betteroffice/docx-i18n 的下载量有多少?

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

@betteroffice/docx-i18n 还在维护吗?

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