Skip to content

translate Markdown into specified multiple languages automatically based on openAI.

Notifications You must be signed in to change notification settings

xieyezi/genji-i18n

Repository files navigation

genji i18n

genji i18n is a tool for automatically translating markdown documents based on openAI.

简体中文 ・ English ・ にほんご ·

Features

  • Automatically translate markdown documents using openAI
  • Support automatic segmentation of large files, no need to worry about openAI token limits
  • Support custom OpenAI models, API proxies, and temperature

Installation

To install genji i18n, run the following command:

pnpm add @xieyezi/genji-i18n -D

It is recommended to install globally:

npm install -g @xieyezi/genji-i18n

Please ensure that the Node.js version is >= 18

Usage

genji-i18n translate -c path/to/genji.config.ts

Configuration

Create a genji.config.ts in the root directory of your document. genji-i18n provides the defineConfig function. Here is an example:

// genji.config.ts
import { defineConfig, LanguageModel } from "@xieyezi/genji-i18n";

export default defineConfig({
  model: LanguageModel.GPT3_5,
  entryLocale: "zh-CN",
  entrySuffix: ".zh-CN.md",
  outputLocales: ["en-US", "ja-JP"],
  entry: ["./index.zh-CN.md"],
  outputCustom: (locale, { getDefaultSuffix }) => {
    if (locale === "en-US") return ".md";
    return getDefaultSuffix(locale);
  }
});

Complete Type of genji.confit.ts

export interface GenjiI18nConfig {
  /**
   * @description ChatGPT model to use
   */
  model?: LanguageModel;
  /**
   * @description Number of concurrently pending promises returned
   */
  concurrency?: number;
  /**
   * @description Provide some context for a more accurate translation
   */
  reference?: string;
  /**
   * @description Split locale JSON by token
   */
  splitToken?: number;
  /**
   * @description Sampling temperature to use
   */
  temperature?: number;
  /**
   * @description The entry file or folder, support glob
   */
  entry: string[];
  /**
   * @description The language that will use as translation ref
   */
  entryLocale: string;
  /**
   * @description Markdown Suffix
   */
  entrySuffix?: string;
  /**
   * @description The markdown that will ignore, support glob
   */
  exclude?: string[];
  /**
   * @description All languages that need to be translated
   */
  outputLocales: string[];
  /**
   * @description IS use json mode
   */
  experimental?: {
    jsonMode?: boolean;
  };
  /**
   * @description Markdown extension generator function
   */
  outputCustom?: (
    locale: string,
    config: {
      fileContent: string;
      filePath: string;
      getDefaultSuffix: (locale: string) => string;
    }
  ) => string;
}

Examples

Refer to the Examples folder for detailed usage examples.

About

translate Markdown into specified multiple languages automatically based on openAI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published