Skip to content

Commit 32a134b

Browse files
committed
fix trans
1 parent a534160 commit 32a134b

File tree

5 files changed

+101
-8
lines changed

5 files changed

+101
-8
lines changed

README.md

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,89 @@ This is the contents of the published config file:
4848

4949
```php
5050
return [
51-
'source_language' => env('TRANSLATIONS_SOURCE_LANGUAGE', 'en'), // Source Language
51+
/*
52+
|--------------------------------------------------------------------------
53+
| Source Language
54+
|--------------------------------------------------------------------------
55+
|
56+
| This is the language that will be used as the source language for
57+
| the translations. This language will be used to import the
58+
| translations from the files.
59+
|
60+
*/
61+
'source_language' => env('TRANSLATIONS_SOURCE_LANGUAGE', 'en'),
62+
63+
64+
65+
/*
66+
* Language lines will be fetched by these loaders. You can put any class here that implements
67+
* the Samehdoush\LaravelTranslationsApi\TranslationLoaders\TranslationLoader-interface.
68+
*/
69+
'translation_loaders' => [
70+
Samehdoush\LaravelTranslationsApi\TranslationLoaders\Db::class,
71+
],
72+
/*
73+
* This is the model used by the Db Translation loader. You can put any model here
74+
* that extends Samehdoush\LaravelTranslationsApi\Models\Phrase.
75+
*/
76+
'model' => Samehdoush\LaravelTranslationsApi\Models\Phrase::class,
77+
78+
/*
79+
* This is the translation manager which overrides the default Laravel `translation.loader`
80+
*/
81+
'translation_manager' => Samehdoush\LaravelTranslationsApi\TranslationLoaderManager::class,
82+
/*
83+
|--------------------------------------------------------------------------
84+
| Exclude Files
85+
|--------------------------------------------------------------------------
86+
|
87+
| The following files will be ignored during the import process.
88+
| and those files will be ignored in every language.
89+
|
90+
*/
5291
'exclude_files' => [
5392
//'validation.php', // Exclude default validation for example.
5493
],
94+
95+
/*
96+
|--------------------------------------------------------------------------
97+
| Laravel Translations Path
98+
|--------------------------------------------------------------------------
99+
|
100+
| The default is `translations` but you can change it to whatever works best and
101+
| doesn't conflict with the routing in your application.
102+
|
103+
*/
55104
'route_prefix' => env('TRANSLATIONS_PATH', 'translations'),
56-
'middleware' => ['api','auth:sanctum'],
105+
106+
107+
108+
/*
109+
|--------------------------------------------------------------------------
110+
| Laravel Translations route middleware
111+
|--------------------------------------------------------------------------
112+
|
113+
| These middleware will be assigned to every Laravel Translations route, giving you
114+
| the chance to add your own middleware to this list or change any of
115+
| the existing middleware. Or, you can simply stick with this list.
116+
|
117+
*/
118+
119+
'middleware' => ['api', 'auth:sanctum'],
120+
121+
/*
122+
|--------------------------------------------------------------------------
123+
| Database Connection
124+
|--------------------------------------------------------------------------
125+
|
126+
| The database connection that should be used to store the imported
127+
| translations You may specify the connection as a string
128+
| which is the name of the connection in the database.php file
129+
|
130+
*/
57131
'database_connection' => env('TRANSLATIONS_DB_CONNECTION', null),
58132
];
133+
59134
```
60135

61136
## Usage

config/translations-api.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
// config for Samehdoush/LaravelTranslationsApi
43
return [
54
/*
65
|--------------------------------------------------------------------------
@@ -14,6 +13,25 @@
1413
*/
1514
'source_language' => env('TRANSLATIONS_SOURCE_LANGUAGE', 'en'),
1615

16+
17+
18+
/*
19+
* Language lines will be fetched by these loaders. You can put any class here that implements
20+
* the Samehdoush\LaravelTranslationsApi\TranslationLoaders\TranslationLoader-interface.
21+
*/
22+
'translation_loaders' => [
23+
Samehdoush\LaravelTranslationsApi\TranslationLoaders\Db::class,
24+
],
25+
/*
26+
* This is the model used by the Db Translation loader. You can put any model here
27+
* that extends Samehdoush\LaravelTranslationsApi\Models\Phrase.
28+
*/
29+
'model' => Samehdoush\LaravelTranslationsApi\Models\Phrase::class,
30+
31+
/*
32+
* This is the translation manager which overrides the default Laravel `translation.loader`
33+
*/
34+
'translation_manager' => Samehdoush\LaravelTranslationsApi\TranslationLoaderManager::class,
1735
/*
1836
|--------------------------------------------------------------------------
1937
| Exclude Files

src/LaravelTranslationsApiServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function configurePackage(Package $package): void
4747
public function registeringPackage()
4848
{
4949
$this->app->singleton('translation.loader', function ($app) {
50-
$class = TranslationLoaderManager::class;
50+
$class = config('translations-api.translation_manager');
5151

5252
return new $class($app['files'], $app['path.lang']);
5353
});

src/TranslationLoaderManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function load($locale, $group, $namespace = null): array
3333

3434
return array_replace_recursive($fileTranslations, $loaderTranslations);
3535
} catch (QueryException $e) {
36-
$modelClass = Phrase::class;
36+
$modelClass = config('translations-api.model');
3737
$model = new $modelClass;
3838
if (is_a($model, Phrase::class)) {
3939
if (!Schema::hasTable($model->getTable())) {
@@ -50,7 +50,7 @@ protected function getTranslationsForTranslationLoaders(
5050
string $group,
5151
string $namespace = null
5252
): array {
53-
return collect(Db::class)
53+
return collect(config('translations-api.translation_loaders'))
5454
->map(function (string $className) {
5555
return app($className);
5656
})

src/TranslationLoaders/Db.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class Db implements TranslationLoader
1010
public function loadTranslations(string $locale, string $group): array
1111
{
1212

13-
14-
return Phrase::getTranslationsForGroup($locale, $group);
13+
$model = config('translations-api.model');
14+
return $model::getTranslationsForGroup($locale, $group);
1515
}
1616

1717

0 commit comments

Comments
 (0)