Skip to content

Commit 2942b95

Browse files
authored
Merge pull request #15 from tectonic/feature/configuration-based-transformer-registration
Configuration based transformer registration
2 parents 26b7d6b + 5f8a9ee commit 2942b95

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ Install via composer:
1010

1111
composer require tectonic/laravel-localisation
1212

13+
Publish the configuration
14+
15+
```shell
16+
php artisan vendor:publish --provider="Tectonic\LaravelLocalisation\ServiceProvider"
17+
```
1318
## Documentation
1419

1520
You can view the rest of the documentation here: (https://github.com/tectonic/laravel-localisation/wiki)

config/localisation.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,12 @@
44
/**
55
* Define the model you wish to use for any translation features.
66
*/
7-
'model' => \Tectonic\LaravelLocalisation\Database\Translation::class
7+
'model' => \Tectonic\LaravelLocalisation\Database\Translation::class,
8+
9+
/**
10+
* Define your custom transformers that will be used to transform the data.
11+
*/
12+
'transformers' => [
13+
//
14+
]
815
];

src/ServiceProvider.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,15 @@ private function registerTranslator()
7676
{
7777
$this->app->scoped('localisation.translator', function($app) {
7878
$translatorEngine = new Engine;
79-
79+
8080
$translatorEngine->registerTransformer(
8181
$app->make(ModelTransformer::class),
8282
$app->make(CollectionTransformer::class),
83-
$app->make(PaginationTransformer::class)
83+
$app->make(PaginationTransformer::class),
84+
...array_map(
85+
fn ($transformer) => $app->make($transformer),
86+
$app['config']->get('localisation.transformers', [])
87+
)
8488
);
8589

8690
return $translatorEngine;

0 commit comments

Comments
 (0)