333 - 《翻译 epub》

发布于 2023年8月14日

前几天看到有人分享如何利用 Immersive Translate 翻译 epub,想起之前问同事要过相关 Shell 代码却没看过,晚上翻了下,转成 Node.js 的风格,把流程跑通了。

代码如下。

import assert from 'assert';
import 'zx/globals';

$.verbose = false;

(async () => {
  const cwd = process.cwd();
  const book = argv._[0];
  assert(book, 'book name is required');
  const bookPath = path.resolve(cwd, book);
  const targetBookPath = bookPath.replace(/\.epub$/, '.translated.epub');
  assert(fs.existsSync(bookPath), `book ${book} not found`);
  const tempDir = path.join(__dirname, 'tmp', 'translate-epub-book');
  await $`rm -rf ${tempDir}`;
  await $`mkdir -p ${tempDir}`;
  await $`unzip "${bookPath}" -d  ${tempDir}`;
  const files = globby.globbySync('**/*.(

内容预览已结束

此内容需要会员权限。请先登录以查看完整内容。