You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+57-24Lines changed: 57 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,29 @@
1
1
# Laravel AI Translator
2
2
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
4
4
5
5
## Overview
6
6
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.
8
8
9
9
Key benefits:
10
10
- 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
- Seamless integration: Works within your existing Laravel project structure, preserving complex language file structures
14
14
15
15
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.
16
16
17
17
## Key Features
18
18
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
20
20
- 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
24
27
25
28
Also, this tool is designed to translate your language files intelligently:
26
29
@@ -35,6 +38,7 @@ Do you want to know how this works? See the prompt in `src/AI`.
35
38
## Prerequisites
36
39
37
40
- PHP 8.0 or higher
41
+
- Laravel 8.0 or higher
38
42
39
43
## Installation
40
44
@@ -44,13 +48,15 @@ Do you want to know how this works? See the prompt in `src/AI`.
44
48
composer require kargnas/laravel-ai-translator
45
49
```
46
50
47
-
2. Add the Anthropic API key to your `.env` file:
51
+
2. Add the OpenAI API key to your `.env` file:
48
52
49
53
```
50
-
ANTHROPIC_API_KEY=your-api-key-here
54
+
OPENAI_API_KEY=your-openai-api-key-here
51
55
```
52
56
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.)
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.
62
68
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!
64
88
65
89
## Usage
66
90
@@ -132,7 +156,7 @@ This will create a `config/ai-translator.php` file where you can modify the foll
132
156
133
157
2.`source_directory`: If you use a different directory for language files instead of the default `lang` directory, you can specify it here.
134
158
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.
136
160
137
161
4.`locale_names`: This mapping of locale codes to language names enhances translation quality by providing context to the AI.
138
162
@@ -148,9 +172,9 @@ return [
148
172
'source_directory' => 'lang',
149
173
150
174
'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')
154
178
],
155
179
156
180
'locale_names' => [
@@ -171,11 +195,7 @@ return [
171
195
];
172
196
```
173
197
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.
179
199
180
200
## Supported File Types
181
201
@@ -199,7 +219,20 @@ If you're currently using JSON files for your translations, we recommend migrati
199
219
200
220
## AI Service
201
221
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.
203
236
204
237
## TODO List
205
238
@@ -211,7 +244,7 @@ We're constantly working to improve Laravel AI Translator. Here are some feature
211
244
- Check for consistency in pluralization rules across translations
212
245
-[ ] Write test code to ensure reliability and catch potential issues
213
246
-[ ] 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)
215
248
216
249
If you'd like to contribute to any of these tasks, please feel free to submit a pull request!
0 commit comments