Skip to content

Commit f556d95

Browse files
authored
Merge pull request #9 from wazzac/develop/v2.3.0
Develop/v2.3.0 to `main`: Next feature release v2.3.0
2 parents 56d9532 + 3f84dd7 commit f556d95

File tree

12 files changed

+2760
-2218
lines changed

12 files changed

+2760
-2218
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
# Release Notes
2+
3+
## v2.3.0 `2025-06-17`
4+
5+
### Changed
6+
- Refactored `TranslateController` to use instance (non-static) methods and registered it as a singleton in the service provider.
7+
- Updated all Blade directives in `DomTranslateServiceProvider` to use the singleton instance via `app(TranslateController::class)`.
8+
- Improved Blade directive registration for proper PHP syntax and singleton usage.
9+
10+
211
## v2.2.1 `2024-07-21`
312
### Updated
413
- Renamed the `PhraseHelper.php` class to conform to PSR-1.

README.md

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,22 @@ php artisan vendor:publish --tag="dom-translate-migrations"
3737
php artisan migrate
3838
```
3939

40+
Register the Service Provider (if not auto-discovered):
41+
Add to `bootstrap/providers.php`:
42+
43+
```php
44+
return [
45+
App\Providers\AppServiceProvider::class,
46+
Wazza\DomTranslate\Providers\DomTranslateServiceProvider::class,
47+
];
48+
```
49+
50+
> _If your package supports Laravel auto-discovery, this step may be optional._
51+
4052
Add `DOM_TRANSLATE_GOOGLE_KEY={your_google_api_key}` to your `.env` file and run:
4153

4254
```bash
55+
php artisan config:clear
4356
php artisan config:cache
4457
```
4558

@@ -105,27 +118,39 @@ Here are a few examples of how to use the translate Blade directive in your HTML
105118
Four directives are available by default (`@transl8()` is the main one). You can add more in your Laravel _AppServiceProvider_ file (under the `register()` method).
106119

107120
```php
108-
// Register the default Blade directive - @transl8()
109-
// Only the phrase argument is required. Default source and destination languages are sourced from the config file.
110-
// - Format: transl8('Phrase','target','source')
111-
// - Example: transl8('This must be translated to French.','fr')
112-
Blade::directive('transl8', function ($string) {
113-
return \Wazza\DomTranslate\Controllers\TranslateController::phrase($string);
114-
});
115-
116-
// Register language-specific Blade directives
117-
// French - @transl8fr('phrase')
118-
Blade::directive('transl8fr', function ($string) {
119-
return \Wazza\DomTranslate\Controllers\TranslateController::translate($string, "fr", "en");
120-
});
121-
// German - @transl8de('phrase')
122-
Blade::directive('transl8de', function ($string) {
123-
return \Wazza\DomTranslate\Controllers\TranslateController::translate($string, "de", "en");
124-
});
125-
// Japanese - @transl8je('phrase')
126-
Blade::directive('transl8je', function ($string) {
127-
return \Wazza\DomTranslate\Controllers\TranslateController::translate($string, "je", "en");
128-
});
121+
// Register the default Blade directive - @transl8()
122+
// Only the phrase argument is required. Default source and destination languages are sourced from the config file.
123+
// - Format: transl8('Phrase','target','source')
124+
// - Example: transl8('This must be translated to French.','fr')
125+
// Register the @transl8 directive separately
126+
Blade::directive('transl8', function ($string) {
127+
return "<?= app(" . TranslateController::class . "::class)->phrase({$string}); ?>";
128+
});
129+
130+
// Register the @transl8 directive for specific languages you use often
131+
$languages = [
132+
'fr', // French
133+
'de', // German
134+
'nl', // Dutch
135+
'es', // Spanish
136+
'it', // Italian
137+
'pt', // Portuguese
138+
'ru', // Russian
139+
'zhcn' => 'zh-CN', // Chinese Simplified
140+
'zhtw' => 'zh-TW', // Chinese Traditional
141+
'af', // Afrikaans
142+
'ar' => 'ar-SA', // Arabic
143+
// ... Add more languages as needed
144+
];
145+
146+
// Register directives for each language by iterating over the languages array
147+
foreach ($languages as $alias => $langCode) {
148+
// Handle array values like 'zhcn' => 'zh-CN'
149+
$directive = is_string($alias) ? $alias : $langCode;
150+
Blade::directive("transl8{$directive}", function ($string) use ($langCode) {
151+
return "<?= app(" . TranslateController::class . "::class)->translate({$string}, '{$langCode}', 'en'); ?>";
152+
});
153+
}
129154
```
130155

131156
## Future Development (Backlog)

composer.json

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,30 @@
22
"name": "wazza/dom-translate",
33
"description": "A Laravel Package that will use the build-in Blade Directive to define specific phrases for auto-translation before being rendered to the screen.",
44
"type": "library",
5+
"keywords": [
6+
"laravel",
7+
"translation",
8+
"blade-translate",
9+
"blade",
10+
"package"
11+
],
12+
"homepage": "https://www.wazzac.dev",
13+
"repository": "https://github.com/wazzac/laravel-translate",
14+
"readme": "README.md",
515
"require": {
6-
"php": "^8.1",
716
"ext-json": "*",
8-
"illuminate/support": "~10",
9-
"guzzlehttp/guzzle": "^7.4"
17+
"guzzlehttp/guzzle": "^7.8",
18+
"illuminate/support": "^12.0",
19+
"php": "^8.2 || ^8.3"
1020
},
1121
"require-dev": {
1222
"fakerphp/faker": "^1.20.0",
13-
"phpunit/phpunit": "~10",
14-
"orchestra/testbench": "~8",
23+
"laravel/legacy-factories": "~1",
1524
"mockery/mockery": "^1.2",
16-
"laravel/legacy-factories": "~1"
25+
"orchestra/testbench": "^10.0",
26+
"pestphp/pest": "^3.8",
27+
"pestphp/pest-plugin-laravel": "^3.2",
28+
"phpunit/phpunit": "^11.0"
1729
},
1830
"license": "MIT",
1931
"autoload": {
@@ -26,8 +38,8 @@
2638
"psr-4": {
2739
"Wazza\\DomTranslate\\": "src/",
2840
"Wazza\\DomTranslate\\Tests\\": "tests/",
29-
"Database\\Factories\\": "database/factories/",
30-
"Database\\Seeders\\": "database/seeders/"
41+
"Wazza\\DomTranslate\\Database\\Factories\\": "database/factories/",
42+
"Wazza\\DomTranslate\\Database\\Seeders\\": "database/seeders/"
3143
}
3244
},
3345
"extra": {
@@ -40,15 +52,27 @@
4052
}
4153
}
4254
},
43-
"authors": [{
44-
"name": "Warren Coetzee",
45-
"email": "warren.coetzee@gmail.com",
46-
"homepage": "https://www.wazzac.dev"
47-
}],
55+
"authors": [
56+
{
57+
"name": "Warren Coetzee",
58+
"email": "warren.coetzee@gmail.com",
59+
"homepage": "https://www.wazzac.dev"
60+
}
61+
],
62+
"support": {
63+
"issues": "https://github.com/wazzacdev/laravel-translate/issues",
64+
"source": "https://github.com/wazzacdev/laravel-translate"
65+
},
4866
"scripts": {
4967
"post-autoload-dump": [
5068
"@php ./vendor/bin/testbench package:discover --ansi"
5169
]
5270
},
53-
"minimum-stability": "stable"
71+
"minimum-stability": "stable",
72+
"prefer-stable": true,
73+
"config": {
74+
"allow-plugins": {
75+
"pestphp/pest-plugin": true
76+
}
77+
}
5478
}

0 commit comments

Comments
 (0)