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

Commit

Permalink
Merge pull request #508 from ahmed-aliraqi/master
Browse files Browse the repository at this point in the history
Allow to change default translation model namespace from config file
  • Loading branch information
Gummibeer committed Aug 7, 2018
2 parents 11eabac + add50f9 commit b1aa31a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Translatable/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,21 @@ public function getTranslationModelName()
*/
public function getTranslationModelNameDefault()
{
return get_class($this).config('translatable.translation_suffix', 'Translation');
$modelName = get_class($this);

if ($namespace = $this->getTranslationModelNamespace()) {
$modelName = $namespace.'\\'.class_basename(get_class($this));
}

return $modelName.config('translatable.translation_suffix', 'Translation');
}

/**
* @return string|null
*/
public function getTranslationModelNamespace()
{
return config('translatable.translation_model_namespace');
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/config/translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@
*/
'fallback_locale' => 'en',

/*
|--------------------------------------------------------------------------
| Translation Model Namespace
|--------------------------------------------------------------------------
|
| Defines the default 'Translation' class namespace. For example, if
| you want to use App\Translations\CountryTranslation instead of App\CountryTranslation
| set this to 'App\Translations'.
|
*/
'translation_model_namespace' => null,

/*
|--------------------------------------------------------------------------
| Translation Suffix
Expand Down
9 changes: 9 additions & 0 deletions tests/TranslatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ public function test_it_finds_the_default_translation_class()
$country->getTranslationModelNameDefault());
}

public function test_it_finds_the_translation_class_with_namespace_set()
{
$this->app->make('config')->set('translatable.translation_model_namespace', 'App\Models\Translations');
$country = new Country();
$this->assertEquals(
'App\Models\Translations\CountryTranslation',
$country->getTranslationModelNameDefault());
}

public function test_it_finds_the_translation_class_with_suffix_set()
{
App::make('config')->set('translatable.translation_suffix', 'Trans');
Expand Down

0 comments on commit b1aa31a

Please sign in to comment.