Skip to content

Latest commit

 

History

History
131 lines (86 loc) · 4.64 KB

README.md

File metadata and controls

131 lines (86 loc) · 4.64 KB

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 support@ekouk.com instead of using the issue tracker.

Credits

License

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