Skip to content
This repository was archived by the owner on Jun 18, 2019. It is now read-only.

Commit b1aa31a

Browse files
authored
Merge pull request #508 from ahmed-aliraqi/master
Allow to change default translation model namespace from config file
2 parents 11eabac + add50f9 commit b1aa31a

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/Translatable/Translatable.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,21 @@ public function getTranslationModelName()
111111
*/
112112
public function getTranslationModelNameDefault()
113113
{
114-
return get_class($this).config('translatable.translation_suffix', 'Translation');
114+
$modelName = get_class($this);
115+
116+
if ($namespace = $this->getTranslationModelNamespace()) {
117+
$modelName = $namespace.'\\'.class_basename(get_class($this));
118+
}
119+
120+
return $modelName.config('translatable.translation_suffix', 'Translation');
121+
}
122+
123+
/**
124+
* @return string|null
125+
*/
126+
public function getTranslationModelNamespace()
127+
{
128+
return config('translatable.translation_model_namespace');
115129
}
116130

117131
/**

src/config/translatable.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@
8282
*/
8383
'fallback_locale' => 'en',
8484

85+
/*
86+
|--------------------------------------------------------------------------
87+
| Translation Model Namespace
88+
|--------------------------------------------------------------------------
89+
|
90+
| Defines the default 'Translation' class namespace. For example, if
91+
| you want to use App\Translations\CountryTranslation instead of App\CountryTranslation
92+
| set this to 'App\Translations'.
93+
|
94+
*/
95+
'translation_model_namespace' => null,
96+
8597
/*
8698
|--------------------------------------------------------------------------
8799
| Translation Suffix

tests/TranslatableTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ public function test_it_finds_the_default_translation_class()
1616
$country->getTranslationModelNameDefault());
1717
}
1818

19+
public function test_it_finds_the_translation_class_with_namespace_set()
20+
{
21+
$this->app->make('config')->set('translatable.translation_model_namespace', 'App\Models\Translations');
22+
$country = new Country();
23+
$this->assertEquals(
24+
'App\Models\Translations\CountryTranslation',
25+
$country->getTranslationModelNameDefault());
26+
}
27+
1928
public function test_it_finds_the_translation_class_with_suffix_set()
2029
{
2130
App::make('config')->set('translatable.translation_suffix', 'Trans');

0 commit comments

Comments
 (0)