Skip to content

Commit 2dd1ad3

Browse files
committed
Merge commit '54e2c8207f326a931f0ce266173db1b9ad8a879c'
# Conflicts: # README.md
2 parents b15d743 + 54e2c82 commit 2dd1ad3

File tree

1 file changed

+57
-24
lines changed

1 file changed

+57
-24
lines changed

README.md

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
# Laravel AI Translator
22

3-
Automatically translate your Laravel language files into multiple languages from English using AI with a single command!
3+
AI-powered translation tool for Laravel language files
44

55
## Overview
66

7-
Laravel AI Translator is a powerful tool designed to streamline the localization process in Laravel projects. Born out of the frustration of manual translation work, this package automates the tedious task of translating strings across multiple languages.
7+
Laravel AI Translator is a powerful tool designed to streamline the localization process in Laravel projects. It automates the tedious task of translating strings across multiple languages, leveraging advanced AI models to provide high-quality, context-aware translations.
88

99
Key benefits:
1010
- Time-saving: Translate all your language files with one simple command
11-
- AI-powered: Utilizes advanced AI to provide high-quality translations
12-
- Smart context understanding: Respects variables, tenses, and linguistic nuances
13-
- Seamless integration: Works within your existing Laravel project structure
11+
- AI-powered: Utilizes state-of-the-art language models (GPT-4, GPT-4o, GPT-3.5, Claude) for superior translation quality
12+
- Smart context understanding: Accurately captures nuances, technical terms, and Laravel-specific expressions
13+
- Seamless integration: Works within your existing Laravel project structure, preserving complex language file structures
1414

1515
Whether you're working on a personal project or a large-scale application, Laravel AI Translator simplifies the internationalization process, allowing you to focus on building great features instead of wrestling with translations.
1616

1717
## Key Features
1818

19-
- Automatically detects all language folders in your `lang` directory (It's okay even if the directory is empty)
19+
- Automatically detects all language folders in your `lang` directory
2020
- Translates PHP language files from a source language (default: English) to all other languages
21-
- Uses Anthropic's Claude AI for intelligent translations
22-
- Respects variables, tenses, and word lengths in translations
23-
- Supports multiple locales out of the box
21+
- Supports multiple AI providers for intelligent, context-aware translations
22+
- Preserves variables, HTML tags, pluralization codes, and nested structures
23+
- Maintains consistent tone and style across translations
24+
- Supports custom translation rules for enhanced quality and project-specific requirements
25+
- Efficiently processes large language files, saving time and effort
26+
- Respects Laravel's localization system, ensuring compatibility with your existing setup
2427

2528
Also, this tool is designed to translate your language files intelligently:
2629

@@ -35,6 +38,7 @@ Do you want to know how this works? See the prompt in `src/AI`.
3538
## Prerequisites
3639

3740
- PHP 8.0 or higher
41+
- Laravel 8.0 or higher
3842

3943
## Installation
4044

@@ -44,13 +48,15 @@ Do you want to know how this works? See the prompt in `src/AI`.
4448
composer require kargnas/laravel-ai-translator
4549
```
4650

47-
2. Add the Anthropic API key to your `.env` file:
51+
2. Add the OpenAI API key to your `.env` file:
4852

4953
```
50-
ANTHROPIC_API_KEY=your-api-key-here
54+
OPENAI_API_KEY=your-openai-api-key-here
5155
```
5256

53-
You can obtain an API key from the [Anthropic website](https://www.anthropic.com) or your Anthropic account dashboard.
57+
You can obtain an API key from the [OpenAI website](https://platform.openai.com/account/api-keys).
58+
59+
(If you want to use Anthropic's Claude instead, see step 4 below for configuration instructions.)
5460

5561
3. (Optional) Publish the configuration file:
5662

@@ -60,7 +66,25 @@ php artisan vendor:publish --provider="Kargnas\LaravelAiTranslator\LaravelAiTran
6066

6167
This step is optional but recommended if you want to customize the package's behavior. It will create a `config/ai-translator.php` file where you can modify various settings.
6268

63-
4. You're now ready to use the Laravel AI Translator!
69+
4. (Optional) If you want to use Anthropic's Claude instead of OpenAI's GPT, update the `config/ai-translator.php` file:
70+
71+
```php
72+
'ai' => [
73+
'provider' => 'anthropic',
74+
'model' => 'claude-3-5-sonnet-20240620',
75+
'api_key' => env('ANTHROPIC_API_KEY'),
76+
],
77+
```
78+
79+
Then, add the Anthropic API key to your `.env` file:
80+
81+
```
82+
ANTHROPIC_API_KEY=your-anthropic-api-key-here
83+
```
84+
85+
You can obtain an Anthropic API key from the [Anthropic website](https://www.anthropic.com).
86+
87+
5. You're now ready to use the Laravel AI Translator!
6488

6589
## Usage
6690

@@ -132,7 +156,7 @@ This will create a `config/ai-translator.php` file where you can modify the foll
132156

133157
2. `source_directory`: If you use a different directory for language files instead of the default `lang` directory, you can specify it here.
134158

135-
3. `ai`: Currently only supports Anthropic's Claude. You can configure the API key and model version here.
159+
3. `ai`: Configure the AI provider, model, and API key here.
136160

137161
4. `locale_names`: This mapping of locale codes to language names enhances translation quality by providing context to the AI.
138162

@@ -148,9 +172,9 @@ return [
148172
'source_directory' => 'lang',
149173

150174
'ai' => [
151-
'provider' => 'anthropic',
152-
'model' => 'claude-3-5-sonnet-20240620',
153-
'api_key' => env('ANTHROPIC_API_KEY'),
175+
'provider' => 'openai', // or 'anthropic'
176+
'model' => 'gpt-4o', // or 'gpt-4', 'gpt-3.5-turbo', 'claude-3-5-sonnet-20240620'
177+
'api_key' => env('OPENAI_API_KEY'), // or env('ANTHROPIC_API_KEY')
154178
],
155179

156180
'locale_names' => [
@@ -171,11 +195,7 @@ return [
171195
];
172196
```
173197

174-
Make sure to set your Anthropic API key in your `.env` file:
175-
176-
```
177-
ANTHROPIC_API_KEY=your-api-key-here
178-
```
198+
Make sure to set your chosen AI provider's API key in your `.env` file.
179199

180200
## Supported File Types
181201

@@ -199,7 +219,20 @@ If you're currently using JSON files for your translations, we recommend migrati
199219

200220
## AI Service
201221

202-
Currently, this package uses Claude from Anthropic for translations. Support for GPT-3.5, GPT-4, and GPT-4o is planned for future releases.
222+
This package supports both OpenAI's GPT models and Anthropic's Claude for translations, each with its own strengths:
223+
224+
- OpenAI:
225+
- GPT-4o: Optimized for speed and efficiency. Ideal for short-form translations and high-volume tasks. It offers a great balance of speed and quality.
226+
- GPT-4: Provides high-quality translations with good understanding of context.
227+
- GPT-3.5: Faster and more cost-effective, suitable for simpler translation tasks.
228+
229+
- Anthropic:
230+
- Claude: Excels at translating longer texts and producing more natural-sounding translations. It's slower compared to GPT models but can handle complex, nuanced content better.
231+
232+
Choose your model based on your specific needs:
233+
- For quick translations of short texts or UI elements, GPT-4o or GPT-3.5 might be your best bet.
234+
- For longer content where nuance and natural flow are crucial, Claude could be the better choice.
235+
- If you need a balance of speed and quality for mixed content, GPT-4 is a solid all-rounder.
203236

204237
## TODO List
205238

@@ -211,7 +244,7 @@ We're constantly working to improve Laravel AI Translator. Here are some feature
211244
- Check for consistency in pluralization rules across translations
212245
- [ ] Write test code to ensure reliability and catch potential issues
213246
- [ ] Implement functionality to maintain the array structure of strings during translation
214-
- [ ] Expand support for other LLMs (such as OpenAI GPT)
247+
- [ ] Expand support for other LLMs (such as Gemini)
215248

216249
If you'd like to contribute to any of these tasks, please feel free to submit a pull request!
217250

0 commit comments

Comments
 (0)