seratch / notion-translator

CLI tool to translate Notion pages into a different language
MIT License
71 stars 20 forks source link
cli deepl machine-translation nodejs notion

Notion Translator

npm version

Notion Translator is a CLI tool that enables Notion users to translate Notion pages into a different language by leveraging the DeepL's text translation API.

You can install this tool just by running:

npm install -g notion-translator

How It Works

Let's say you'd like to translate a Notion page template written in English into a differen language such as Japanese, Spainish, and French. All you need to do with notion-translator are:

notion-translator \
  --from en \
  --to ja \
  --url https://www.notion.so/acme/Blog-Post-ABC123

Live Demo

Once you create your integration for translation and set the Notion / DeepL credentials in env variables, you can run the command to translate with the Notion page URL:

When the translated page is ready, the CLI opens the page in the default web browser for you. The CLI generates the page as a child page of the original one, but you can move it anywhere else if you would like to do so!

Prerequisites

To run this CLI tool, the following are required:

Notion Internal Integration

You can configure your integration by the following steps:

Once the integration is created, you can find your Internal Integration Token under Secrets section. The string value should start with secret_. You will use this value as NOTION_API_TOKEN when configuring the CLI later.

DeepL API Account

You can configure your DeepL API account by the following steps:

Once your account is activated, you can find your DeepL API token on your account page. YOu will use this value as DEEPL_API_TOKEN when configuring the CLI later.

Configure the CLI

You can install the CLI via npm command.

npm install -g notion-translator

Let's hit notion-translator -h to check if the command is now available for you.

$ notion-translator  -h
Usage: notion-translator [options]

CLI to translate a Notion page to a different language

Options:
  -u, --url <https://www.notion.so/...>
  -f, --from <bg,cs,da,de,el,en,es,et,fi,fr,hu,id,it,ja,lt,lv,nl,pl,pt,ro,ru,sk,sl,sv,tr,zh>
  -t, --to <bg,cs,da,de,el,en-gb,en-us,es,et,fi,fr,hu,id,it,ja,lt,lv,nl,pl,pt-pt,pt-br,ro,ru,sk,sl,sv,tr,zh>
  -d, --debug
  -h, --help                                                                                                  display help for command

Prior to running the command, set two env variables:

If you prefer using .env file, it also works as long as the file exists in the current directory.

Run the CLI Command

Please don't forget to share the original Notion page with your integration. You can find Share link at the top of a Notion page. From there, you can invite your Notion Translator integration to the page.

Okay, everything should be ready! Let's run the command now :)

notion-translator \
  --from en \
  --to ja \
  --url https://www.notion.so/acme/Blog-Post-ABC123

If your credentails are not properly set, the CLI opens Notion / DeepL configuration page in the default browser for you. Double-check the settings and token string values.

Also, if you are unsure about the language code to pass as from/to languages, please refer to DeepL's official document.

I hope that this tool will help you save time!

Contributions

If you have any feedback or suggestions to this tool, please feel free to write in in this GitHub repository's issue tracker. Pull requests are welcome too!

License

The MIT License