npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ai-markdown-translator

v1.0.10

Published

CLI tool to translate Markdown files using OpenAI's language models while preserving the original formatting.

Downloads

742

Readme

ai-markdown-translator

English | 中文

ai-markdown-translator is a command-line tool that translates Markdown files from one language to another using OpenAI's language models. It preserves the Markdown syntax while translating the content.

Features

  • Translate Markdown files to any language supported by OpenAI's models.
  • Preserve Markdown syntax during translation.
  • Flexible configuration through command-line arguments or environment variables.

Prerequisites

  • Node.js (v14 or later)
  • npm (usually comes with Node.js)
  • An OpenAI API key

Installation

  1. Clone this repository or download the source code.
  2. Navigate to the project directory in your terminal.
  3. Install the dependencies:
npm install
  1. Build the project:
npm run build

Scripts

  • build: Compiles TypeScript files to JavaScript.
  • start: Runs the compiled JavaScript using Node.js.
  • lint: Runs ESLint to check for code quality issues in TypeScript files.
  • lint:fix: Automatically fixes linting issues in TypeScript files.
  • format: Formats code using Prettier for various file types in the src directory.
  • format:check: Checks code formatting without making changes for various file types in the src directory.
  • postbuild: Makes the compiled index.js file executable.
  • changelog: Generates a changelog based on conventional commits.
  • version: Updates the changelog and stages it for commit when versioning.
  • test: Builds the project and runs the test.

Usage

You can run the CLI tool using Node.js, npx, or as a standalone executable (if you've packaged it).

Using Node.js

node dist/index.js --input <input-file> --output <output-file> --language <target-language> [options]

Using npx

npx ai-markdown-translator -i <input-file> -o <output-file> -l <target-language> [options]

For example:

npx ai-markdown-translator -u https://gitee.com/h7ml/ai-markdown-translator/raw/main/README.md -o output.md -l "Italian"

Using the standalone executable

./ai-markdown-translator --input <input-file> --output <output-file> --language <target-language> [options]

Options

  • --input, -i: Input Markdown file or directory (alternative to --url). This option allows you to specify the path to the Markdown file or directory you want to translate.

  • --url, -u: URL of a Markdown file to translate (alternative to --input). Use this option to provide a direct link to a Markdown file that you want to translate.

  • --extension, -e: Specify the file extension to translate (e.g., md). If not provided, all files will be processed. This option allows you to filter which files to translate based on their extension.

  • --rename: Whether to modify the file name. If true, the output file will be named <original-filename>-translated.<extension>. This option allows you to specify if you want to append a suffix to the translated file name.

  • --output, -o: Output Markdown file (if not provided, defaults to the input file name). This option allows you to specify the name of the output file where the translated content will be saved.

  • --language, -l: Target language for translation (required). This option specifies the language into which you want the Markdown content to be translated.

  • --openai-url: OpenAI API URL (default: uses OPENAI_URL environment variable). This option allows you to specify a custom URL for the OpenAI API if needed.

  • --api-key: OpenAI API Key (default: uses API_KEY environment variable). This option is used to provide your OpenAI API key for authentication.

  • --model: OpenAI Model to use (default: uses MODEL environment variable or gpt-3.5-turbo). This option allows you to specify which OpenAI model to use for translation.

  • --help, -h: Show help. This option displays the help information for the command-line tool.

  • --show-version, -v: Show version. This option displays the current version of the tool.

Note: --input and --url are mutually exclusive; you must provide one or the other.

Environment Variables

You can set the following environment variables instead of passing them as command-line arguments:

  • OPENAI_URL: The URL for the OpenAI API.
  • API_KEY: Your OpenAI API key.
  • MODEL: The OpenAI model to use (e.g., 'gpt-3.5-turbo').

You can set these in a .env file in the project root or export them in your shell.

Examples

  1. Translate a Markdown file from English to Spanish:
npx ai-markdown-translator -i english.md -o spanish.md -l "Spanish"
  1. Translate using a specific OpenAI model:
npx ai-markdown-translator -i input.md -o output.md -l "French" --model "gpt-4"
  1. Translate with custom OpenAI URL and API key:
npx ai-markdown-translator -i input.md -o output.md -l "German" --openai-url "https://api.302.ai/v1/chat/completions" --api-key "sk-302-api-key"
  1. Translate the Markdown content of a URL:
npx ai-markdown-translator -u https://gitee.com/h7ml/ai-markdown-translator/raw/main/README.md -o output.md -l "Italian"
  1. Translate all Markdown files in a directory and rename them:
npx ai-markdown-translator -i ./markdown-files -l "Chinese" --rename
  1. Translate a Markdown file and specify the output file name:
npx ai-markdown-translator -i example.md -o translated_example.md -l "Japanese"

License

MIT License

Git Information

Version Information

CI Information

This project uses GitHub Actions for continuous integration. The CI workflow includes:

  • Linting the code with ESLint
  • Running tests (if applicable)
  • Building the project
  • Caching dependencies for faster builds

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you encounter any problems or have any questions, please open an issue in this repository.