This repository was archived by the owner on Jun 18, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,21 @@ public function getTranslationModelName()
111
111
*/
112
112
public function getTranslationModelNameDefault ()
113
113
{
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 ' );
115
129
}
116
130
117
131
/**
Original file line number Diff line number Diff line change 82
82
*/
83
83
'fallback_locale ' => 'en ' ,
84
84
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
+
85
97
/*
86
98
|--------------------------------------------------------------------------
87
99
| Translation Suffix
Original file line number Diff line number Diff line change @@ -16,6 +16,15 @@ public function test_it_finds_the_default_translation_class()
16
16
$ country ->getTranslationModelNameDefault ());
17
17
}
18
18
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
+
19
28
public function test_it_finds_the_translation_class_with_suffix_set ()
20
29
{
21
30
App::make ('config ' )->set ('translatable.translation_suffix ' , 'Trans ' );
You can’t perform that action at this time.
0 commit comments