@edx/reactifex

中文文档
2.2.0发布于 2023/05/15MIT近 30 天下载 9412

A helper for moving react-intl messages to transifex and back

原始使用文档

reactifex

Helper utility designed to make it easy to upload react-intl extracted messages to transifex, with support for ICU plurals and translator comments.

dependencies license npm_version Build Status

There are two modes of usage - compilation and comment pushing.

Compilation mode

In this mode, messages that have been extracted by babel-plugin-react-intl (into individual files) are combined. The resulting json is suitable to upload to Transifex and matches their specified KEYVALUEJSON format.

usage: $(npm bin)/reactifex <input_folder> <output_file>

  • input_folder corresponds to the messagesDir option used by babel-plugin-react-intl
    • note that reactifex assumes folder structure based on this default
  • output_file will be suitable for upload to transifex

Comment pushing

This mode is why I wrote this library in the first place - I wanted the ability to use comments as PO files do, but none of the tools I found to convert react-intl messages to PO files were able to properly handle ICU pluralization. By keeping everything in a js context with KEYVALUEJSON, plurals work correctly and we now have comment support for translators (by default, Transifex's KEYVALUEJSON file format does not allow for comments to be included with strings for translation).

Usage is a little complicated, I'm sorry about that; you're going to be running this server-side as a series of bash commands. Do note that I assume $SECRET_USER and $SECRET_PWD env vars exist for basic auth purposes. See Transifex's API Introduction for more details on authentication. Here's an example, written as it would be in the Makefile of a project that makes use of reactifex:

tx_url1 = https://www.transifex.com/api/2/project/<project>/resource/<resource>/translation/<default_language_code>/strings/
tx_url2 = https://www.transifex.com/api/2/project/<project>/resource/<resource>/source/
push_translations:
    ./node_modules/reactifex/bash_scripts/get_hashed_strings.sh $(tx_url1)
    $$(npm bin)/reactifex <input_folder> --comments
    ./node_modules/reactifex/bash_scripts/put_comments.sh $(tx_url2)
  • tx_url1 and tx_url2 are just variables as defined by the Transifex API documentation, extracted for readability.

  • First, bash_scripts/get_hashed_strings.sh is called with a url argument. This will populate bash_scripts/hashmap.json with data about the strings in your resource, including the all-important string_hash.

  • Next, the main reactifex script (node js) runs with an additional --comments flag, and no output file. This has the effect of gathering up all your babel-plugin-react-intl extracted messages with their comments attached. From there, it's simple enough to match up each message with its string_hash, and save these pairs in a '|'-delimited list, for later consumption.

  • Finally, bash_scripts/put_comments.sh is run with the base PUT url as an argument (also reads the data file we created in the previous step), updating translator comments for each message on Transifex via their API.

版本与发布记录

@edx/reactifex 共发布 9 个版本,首次发布于 2021/10/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.2.0latest2023/05/153 年前
2.1.12022/09/174 年前
2.1.02022/05/124 年前
2.0.12022/04/054 年前
2.0.02022/04/014 年前
1.1.02022/03/314 年前

关于 @edx/reactifex 的常见问题

@edx/reactifex 是什么?

A helper for moving react-intl messages to transifex and back

如何安装 @edx/reactifex?

在项目目录运行 npm install @edx/reactifex,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 edx_reactifex,可以用 npx edx_reactifex 直接运行。

@edx/reactifex 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/edx__reactifex 是否存在。

@edx/reactifex 可以商用吗?

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

@edx/reactifex 的下载量有多少?

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

@edx/reactifex 还在维护吗?

最新版本 2.2.0 发布于 2023/05/15(3 年前);至今共发布 9 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/10/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。