Giter Site home page Giter Site logo

mpanius / gpt-translate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from techlove/gpt-translate

0.0 0.0 0.0 4.25 MB

A Laravel package to create a base translation file, and translate it to any language with ChatGPT API

License: MIT License

PHP 100.00%

gpt-translate's Introduction

GPT-Translate for Laravel

gpt-translate is a package for Laravel that allows you to generate a translation file based on translation strings found throughout your application. You can call these strings using __(), @lang(), $t(), or trans(), and they can be located in php, js, ts, tsx, or vue files.

Furthermore, gpt-translate enables you to translate your base language file, whether you previously had it or generated it using the package, to other languages using the ChatGPT API. Supported languages for translation include English, Swedish, Danish, Norwegian, Finish, Dutch, Polish, Spanish, French, German, Italian, and Portuguese.

Getting Started

Installation
Add the following to your composer.json file:

{
    "repositories": [
        "gpt-translate": {
            "type": "git",
            "url": "https://github.com/techlove/gpt-translate.git"
        }
    ]
}

Then install the package using composer:

composer require techlove/gpt-translate

Add Service Provider Add the following to your config/app.php file:

'providers' => [
    ...
    Techlove\GptTranslate\TranslateProvider::class,
    ...
],

Publish the Configuration File
You need to publish the openai.php configuration file:

php artisan vendor:publish

Environment Configuration
Add the OPENAI_API_KEY and OPENAI_ORGANIZATION variables to your .env file with the details from your OpenAI account.

Fetch All Translatable and Translate As shown, this command extracts all translatable strings into a lang/en.json, then translate them using ChatGPT into a new file lang/sv.json. These values are used as default and can therefor be left out of the command:

php aritsan translate:extract --origin=en --lang=sv --model=gpt-3.5-turbo --path=resources/lang

Generate Base Translation File
If you don’t already have a base translation file, generate it using:

php artisan translate:make --lang=en --path=resources/lang

As shown, this command creates a lang/en.json in your root folder. If your application is in another language, pass the appropriate lang parameter, e.g., for Swedish:

php artisan translate:make --lang=sv --path=resources/lang

Translate with ChatGPT
After having your base translation file, whether generated by the package or otherwise, run the translation command for ChatGPT to do the translation, e.g.:

php artisan translate:lang --origin=en --lang=sv --path=resources/lang

This translates the original en.json to Swedish and creates a new sv.json file.

Provide Context (Optional)
For more accurate translations, briefly describe the context of your application’s purpose. This helps ChatGPT better understand and translate the text. Use the context parameter:

php artisan translate:lang --origin=en --lang=sv --context="a pet product sales application" --path=resources/lang

Specify the Model (Optional)
By default, the package uses GPT-3.5. If desired, specify any other OpenAI model compatible with the Chat API:

php artisan translate:lang --origin=en --lang=sv --model=gpt-4 --path=resources/lang

Conclusion

Leverage the power of ChatGPT and the flexibility of gpt-translate to localize your Laravel application effectively and efficiently.

gpt-translate's People

Contributors

namejepp avatar richxgc avatar mpanius avatar lagerroos avatar

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.