Git Product home page Git Product logo

ai-translate's Introduction

AI Translator for Laravel locales

Latest Version on Packagist Total Downloads run-tests Check & fix styling

Example

  • Just set a list of languages that you would like your site translating to and leave it to GPT.
  • Can use GPT-3.5-turbo or GPT-4
  • Estimates cost before running
  • More accurate than Google Translate
  • Handles variables in the translation string - they will not be translated.
  • Handles both PHP and JSON files
  • Model translations coming soon

Examples

Examples:- From English:

  • 'accepted' => 'The :attribute must be accepted.',
  • 'accepted_if' => 'The :attribute must be accepted when :other is :value.',

To Arabic:-

  • 'accepted' => 'يجب قبول الـ :attribute',
  • 'accepted_if' => 'يجب قبول الـ :attribute عندما يكون الـ :other هو :value',

To Ukrainian:-

  • 'accepted' => ':attribute має бути прийнятий.',
  • 'accepted_if' => ':attribute має бути прийнятий, коли :other є :value.',

To German:-

  • 'accepted' => 'Die :attribute müssen akzeptiert werden.',
  • 'accepted_if' => 'Die :attribute müssen akzeptiert werden, wenn :other :value ist.',

To Spanish:-

  • 'accepted' => 'El :attribute debe ser aceptado.',
  • 'accepted_if' => 'El :attribute debe ser aceptado cuando :other es :value.',

To Chinese Simplified:-

  • 'accepted' => ':attribute必须被接受。',
  • 'accepted_if' => '当:attribute是:other时,:value必须被接受。',

To Swedish:-

  • 'accepted' => ':attribute måste accepteras.',
  • 'accepted_if' => ':attribute måste accepteras när :other är :value.',

Requirements

PHP 8.1 Is the minimum for the OpenAI Wrapper.

Tested with Laravel ^9.45 and 10.x

Filament is not required (but can add to their already awesome set of translations.)

Installation

Download the package via composer:

composer require visualbuilder/ai-translate

Run the install to copy the config files:-

php artisan vb:ai:install

This will create config/ai-translate.php and config/openai.php if it isn't already installed.

If you don't have GPT keys already visit: https://platform.openai.com/account/api-keys

Add these keys to your .env

OPENAI_API_KEY=sk-xxxxxxx
OPENAI_ORGANIZATION=org-xxxxxx

Usage

Check the config file to make sure you have included the required source locale directories. Copy from the list of known_locales the languages you wish to translate into the target_locales array.

Currently handles .json and .php translation files. Attribute tokens should remain unchanged. This was a challenge as GPT-3.5 refused to ignore :attribute and always translated it even when told explicity to ignore it. To solve this all tokens are replaced with *** before translation and added back in after translation ensuring continuity.

php artisan vb:ai:translate --help

To run the script:-

php artisan vb:ai:translate

The script will scan all the source_directories for translation files and then provide an estimate of the cost to translate into the required languages for each GPT Model.

If you're happy to continue, select the model you wish to use and each source file will be translated.

php artisan vb:ai:translate

If the target file exists, only new keys not in the target will be translated. Unless you use the --force option which will overwrite any existing translations.

I will be adding additional capabilities for model translations and for Spatie Language lines. I have these in a couple of projects so want to extend features.

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The GNU GPLv3. Please see License File for more information.

ai-translate's People

Contributors

cannycookie avatar

Stargazers

Samuel avatar  avatar Zaher Ghaibeh avatar Devin Norgarb avatar  avatar Emmanuel Ketcha avatar Nic avatar JFOC avatar Abdullah Karam avatar Fabio Capucci avatar

Watchers

 avatar Kostas Georgiou avatar

ai-translate's Issues

Error message: Mismatch in source keys and translation. Keys: 40 Translated Strings: 46

When translating a Dutch language file to Germany, I got the following error (using gpt-4):

An error occurred while processing the file: resources/lang/de/cp.php
Error message: Mismatch in source keys and translation. Keys: 40 Translated Strings: 46

Not sure what to do with this. Seems like something is not working correctly in the project.

My language file has multidimensional arrays. I think this is possibly causing the error.

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.