/tranzlate

Automatic string catalog translation w/ OpenAI's Chat Completion APIs

Primary LanguageJavaScriptMIT LicenseMIT

tranzlate logo

A command line interface tool to automatically translate .xcstring catalogs using OpenAI.

English · Chinese (Simplified) · French · Spanish · German

Setup · Usage · Configuration · Markdown · Common Issues · Motivation · Contributing · Contributors

tranzlate_demo.mov

Tranzlate CLI Interface

Setup

The minimum supported version of Node.js is v14

  1. Install tranzlate globally:

    npm install -g tranzlate.js
  2. Retrieve your API key from OpenAI

    Note: If you haven't already, you'll have to create an account and set up billing.

  3. Set the key so tranzlate can use it. You can do this by running:

    echo export OPENAI_API_KEY=<your token> >> ~/.bashrc

    or alternatively, provide the key when running the command

Usage

tranzlate

Then you will get a output like this, which takes you through the process of translating a string catalog:

┌   tranzlate: automatic string translation
│
◇  Enter input file
│  Localizable.xcstrings
│
◇  Enter the output file
│  Localizable.xcstrings
│
◆  Select languages to translate to.
│  ◻ Arabic
│  ◻ Catalan
│  ◻ Chinese (Simplified)
│  ◻ Chinese (Traditional)
│  ◻ Croatian
│  ◼ Czech
│  ◼ Danish
│  ◻ Dutch
│  ◻ English
│  ◻ English (Australia)
│  ◻ English (Canada)
│  ◻ English (U.K.)
│  ◻ English (U.S.)
│  ◻ Finnish
│  ◻ French
│  ◻ French (Canada)
│  ◻ German
│  ◻ Greek
│  ◻ Hebrew
│  ◻ Hindi
│  ◻ Hungarian
│  ◼ Indonesian
│  ◻ Italian
│  ◻ Japanese
│  ◻ Korean
│  ◻ Malay
│  ◻ Norwegian
│  ◻ Polish
│  ◼ Portuguese (Brazil)
│  ◻ Portuguese (Portugal)
│  ◻ Romanian
│  ◻ Russian
│  ◻ Slovak
│  ◻ Spanish (Mexico)
│  ◼ Spanish (Spain)
│  ◻ Swedish
│  ◻ Thai
│  ◻ Turkish
│  ◼ Ukrainian
└  ◻ Vietnamese

Configuration

multiple-languages.mov

Because only supporting a single language would be ironic as a translation utility, we support changing your configuration language. You can set your language by running:

tranzlate set-language <language>

Where <language> is one of the following:

Language Key
Englishen
Simplified Chinesezh-Hans
Traditional Chinesezh-Hant
Spanishes
Japaneseja
Koreanko
Frenchfr
Germande
Russianru
Ukrainianuk
Vietnamesevi
Arabicar
Portuguesept-BR
Turkishtr

For instance, if you want to switch to Simplified Chinese, you can do so by setting the LANGUAGE value to zh-Hans:

tranzlate set-language zh-Hans

This will set your language to Simplified Chinese.

Markdown

Support for markdown translations is supported. To enter markdown mode, run:

tranzlate markdown

You will be prompted for a markdown file or glob to translate. Output translations append the ISO language code to the end of each file name. For instance, if you translate README.md to Simplified Chinese (zh-Hans), the output file will be README.zh-Hans.md.

┌   tranzlate: automatic markdown translation

◇  Enter a markdown file or glob
│  ./README.md

◇  Select languages to translate to
│  fi - Finnish, hu - Hungarian, pl - Polish, ru - Russian

◇  Select a model
│  gpt-3.5-turbo
◆  Translating README.md...

Note: Markdown translation is in beta. Please report any issues you encounter.

Common Issues

429 error

Some users are reporting a 429 from OpenAI. This is due to incorrect billing setup or excessive quota usage. Please follow this guide to fix it.

You can activate billing at this link. Make sure to add a payment method if not under an active grant from OpenAI.

Motivation

I am not a language expert. My proficiency in translation extends only to middle-school level Spanish. However, I believe in software and its importance. Who software is developed for matters. Localization is not nor never should be an afterthought. By utilizing AI translation tools, conversations about the impact software has on different communities can be had earlier in product development, not later.

Accelerating conversations about software's impact leads to meaningful change before feature sets are locked in. This is why I believe in the power of, often imperfect, AI translation tools. Do not let perfect be the enemy of good.

Easy translation, of string catalogs, and hopefully many more file formats to come is why I created tranzlate.

Contributing

If you want to help fix a bug or implement a feature in Issues, please do so. Swift development is somewhat new to me, so I would appreciate community feedback.

Contributors

Alt

Thanks to the ai-shell for their README which I used as a template.