AICodeHunt / transmart

Automate your i18n localization with AI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Transmart - Automate your i18n localization with AI.

English | 简体中文

alt

npm Open in CodeSandbox

Transmart is an open-source developer tool that utilizes ChatGPT to automate i18n translation. Given a base language and specifying all the languages that need to be output, running it will generate all i18n locale files.

It consists of two parts: Cli and Core. Core is the NodeJS core implementation of Transmart, while Cli is a command-line tool that encapsulates Core. In most cases, only Cli is used.

This project is currently under active development,PRs are welcome,reach me at Twitter

Features

  • Supports large size files,don't worry about the 4096 tokens limit
  • Supports all languages that can be displayed using Intl.DisplayNames and can be processed by ChatGPT.
  • Supports override AI translated values
  • Supports i18next
  • Supports vue-i18n
  • Supports Chrome.i18n
  • Supports Glob namespace matching
  • Supports customizing OpenAI Model、API endpoint
  • Supports custom locale file structure
  • Supports iOS
  • Supports Android

Setup

Transmart requires Node version 13 or higher.

1. Installation

To install Transmart, run:

npm install @transmart/cli -D

# or

yarn add @transmart/cli

2. Project setup

First, create a transmart.config.js file in the root of your project. or any others file format cosmiconfig can search for

transmart.config.js

module.exports = {
  baseLocale: 'en',
  locales: ['fr', 'jp', 'de'],
  localePath: 'public/locales',
  openAIApiKey: 'your-own-openai-api-key',
  overrides: {
    'zh-CN': {
      common: {
        create_app: 'Create my Application',
      },
    },
  },
}

All Options Reference

3. Translate.

Add transmart command to your npm scripts

{
  "translate": "transmart"
}

And then execute

npm run translate

Or you can execute directly with npx prefix in command line

npx transmart

If you are not satisfied with the result of AI translation,use overrides option to overwrite the generated JSON partially

🎉🎉 Enjoy i18n

Examples

Options

Name Type Description Required
baseLocale string The language that Transmart will use as translation ref. Yes
locales string[] All languages that need to be translated Yes
localePath string Where you store your locale files Yes
openAIApiKey string The OpenAI API Key. Yes
context string Provide some context for a more accurate translation. No
openAIApiModel string OpenAI API model, default to gpt-3.5-turbo-16k-0613 No
overrides Record<string, Record<string, Record<string, any>>> used to overwrite the generated JSON if you are not satisfied with the result of AI translation (locale-namespace-key:value) No
namespaceGlob string|string[] Glob for namespace(s) to process, useful to include or exclude some files, learn more glob No
openAIApiUrl string Optional base url of OpenAI API, useful with proxy No
openAIApiUrlPath string Optional URL endpoint of OpenAI API, useful with proxy No

Contributing

To contribute to Transmart,refer to contributing.md

Inspired by

About

Automate your i18n localization with AI

License:MIT License


Languages

Language:TypeScript 96.9%Language:JavaScript 3.1%