0.0.1 • Published 1 month ago

transmart v0.0.1

Weekly downloads
-
License
-
Repository
-
Last release
1 month ago

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: 'src',
  targetFoldersName: '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

NameTypeDescriptionRequired
baseLocalestringThe language that Transmart will use as translation ref.Yes
localesstring[]All languages that need to be translatedYes
localePathstringWhere you store your locale filesYes
openAIApiKeystringThe OpenAI API Key.Yes
contextstringProvide some context for a more accurate translation.No
openAIApiModelstringOpenAI API model, default to gpt-3.5-turbo-16k-0613No
overridesRecord<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
namespaceGlobstring|string[]Glob for namespace(s) to process, useful to include or exclude some files, learn more globNo
openAIApiUrlstringOptional base url of OpenAI API, useful with proxyNo
openAIApiUrlPathstringOptional URL endpoint of OpenAI API, useful with proxyNo
modelContextLimitnumberOptional max context window that the model supports. For example for gpt-4-32k, the context is 32768 tokens. Default to 4096 (gpt-3.5-turbo)No
modelContextSplitnumberOptional ratio to split between number of input / output tokens. For example, if the input language is English and output is Spanish, you may expect 1 input token to produce 2 output tokens. In this case, the variable is set to 1/2. By default, modelContextSplit is set to 1/1No
systemPromptTemplatefunction(For advanced usage) Custom prompt template. See "translate.ts" for the default prompt.No
additionalReqBodyParamsany(For advanced usage) Custom parameters to be passed into request body. Useful if you use a self-hosted model and you want to customize model parameters. For example, see llama.cpp server exampleNo

Contributing

To contribute to Transmart,refer to contributing.md

Inspired by

0.0.1

1 month ago