GithubHelp home page GithubHelp logo

dextersjab / gpt-arb-translator Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 12 KB

Python script that uses OpenAI GPT to translate your arb files. The script is ideal for localising Flutter apps.

Python 100.00%

gpt-arb-translator's Introduction

GPT-powered ARB Translator

GPT-ARB-Translator is a Python script that uses OpenAI GPT-3.5-turbo to translate your arb files. The script is ideal for developers working with Flutter and looking to localize their applications.

Installation

  1. Clone this repository:
git clone https://github.com/dextersjab/gpt-arb-translator.git
  1. Navigate to the cloned directory and install the required Python packages:
cd gpt-arb-translator
pip install -r requirements.txt

Usage

  1. Set your OpenAI API key as an environment variable:
export OPENAI_API_KEY='your-key-here'

Now you can run the script on the command line. The command-line arguments are:

  • indir: The directory containing your input .arb files.
  • outdir (optional): The directory where the translated .arb files will be output. Defaults to the input directory if not specified.
  • lang (optional): The base language in which the key-value pairs are provided, specified as a 2-letter ISO 639-1 code. Defaults to 'en' if not specified.
  • out_langs (optional): Languages to translate into. Defaults to all languages found in the arb files in indir.
  1. Run the script:
python translate_arbs.py --indir 'your/input/directory' --outdir 'your/output/directory' --entries key1='value1' key2='value2' --lang en

Example

Let's say you have a base .arb file (app_en.arb) with the following content in English:

{
  "hdtQuote": "The language of friendship is not words but meanings.",
  "noMoat": "We have no moat."
}

Here's how you might use the script to translate this .arb file into all other languages in your output directory:

python translate_arbs.py --indir 'your/input/directory' --outdir 'your/output/directory' --lang 'en'

Alternatively, you could specify the output languages using --out_langs. Here's how you might use the script to translate this .arb file into French and Spanish:

python translate_arbs.py --indir 'your/input/directory' --outdir 'your/output/directory' --lang 'en' --out_langs fr es

Notes

  • The translated .arb files will retain the structure of the original files, with the translated text inserted in place of the original text.
  • Make sure to provide valid .arb files in the input directory.
  • The script reads the 2-letter language codes from the .arb filenames in the input directory. It expects filenames in the format app_.arb.
  • The script uses the OpenAI GPT-3.5-turbo model for translation.
  • If the script encounters an error during translation, it will retry the request up to 3 times with an exponential backoff.
  • The OpenAI API key is required to use the OpenAI GPT-3.5-turbo model. Keep in mind that usage of the OpenAI API may incur costs according to OpenAI's pricing.

gpt-arb-translator's People

Contributors

dextersjab avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

inayet

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.