Skip to content

Commit 60212a9

Browse files
committed
Change default locale to be fallback_locale
1 parent 5e794fa commit 60212a9

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/Traits/HasTranslation.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
43
namespace Despark\LaravelDbLocalization\Traits;
54

6-
75
use Despark\LaravelDbLocalization\Models\TranslationModel;
86
use Despark\LaravelDbLocalization\Observers\ModelObserver;
97

@@ -33,7 +31,7 @@ trait HasTranslation
3331
protected $activeLocale;
3432

3533
/**
36-
* Bootstrap the trait
34+
* Bootstrap the trait.
3735
*/
3836
public static function bootHasTranslation()
3937
{
@@ -51,8 +49,9 @@ public function translation()
5149
/**
5250
* Create a new instance of the given model.
5351
*
54-
* @param array $attributes
55-
* @param bool $exists
52+
* @param array $attributes
53+
* @param bool $exists
54+
*
5655
* @return static
5756
*/
5857
public function newInstance($attributes = [], $exists = false)
@@ -67,14 +66,14 @@ public function newInstance($attributes = [], $exists = false)
6766
* Create a new model instance for a related model.
6867
* We overwrite this so we can dynamically create the table on the related model.
6968
*
70-
* @param string $class
69+
* @param string $class
70+
*
7171
* @return mixed
7272
*/
7373
protected function newRelatedInstance($class)
7474
{
75-
7675
if (is_a($class, TranslationModel::class, true)) {
77-
return tap(new $class, function ($instance) {
76+
return tap(new $class(), function ($instance) {
7877
$instance->setTable($this->getTranslationTable());
7978

8079
if (! $instance->getConnectionName()) {
@@ -83,7 +82,7 @@ protected function newRelatedInstance($class)
8382
});
8483
}
8584

86-
return tap(new $class, function ($instance) {
85+
return tap(new $class(), function ($instance) {
8786
if (! $instance->getConnectionName()) {
8887
$instance->setConnection($this->connection);
8988
}
@@ -92,7 +91,6 @@ protected function newRelatedInstance($class)
9291

9392
/**
9493
* @param string $key
95-
* @return null
9694
*/
9795
public function getAttribute($key)
9896
{
@@ -118,10 +116,10 @@ public function setTranslation($key, $locale, $value)
118116
$this->translatedAttributes[$locale][$key] = $value;
119117
}
120118

121-
122119
/**
123120
* @param $key
124121
* @param $locale
122+
*
125123
* @return string|null
126124
*/
127125
public function getTranslation($key, $locale = null)
@@ -163,6 +161,7 @@ public function unsetTranslation($locale, $key = null)
163161
/**
164162
* @param $key
165163
* @param $value
164+
*
166165
* @return $this
167166
*/
168167
public function setAttribute($key, $value)
@@ -176,7 +175,6 @@ public function setAttribute($key, $value)
176175
return parent::setAttribute($key, $value);
177176
}
178177

179-
180178
/**
181179
* Load transaltions from database.
182180
*/
@@ -218,7 +216,7 @@ public function getAvailableLocales()
218216
*/
219217
public function getDefaultLocale()
220218
{
221-
return config('app.locale');
219+
return config('app.fallback_locale');
222220
}
223221

224222
/**
@@ -271,16 +269,14 @@ public function getTranslationModel()
271269

272270
/**
273271
* @param $key
272+
*
274273
* @return bool
275274
*/
276275
public function isTranslatable($key)
277276
{
278277
return in_array($key, $this->translatable);
279278
}
280279

281-
/**
282-
*
283-
*/
284280
public function refreshTranslations()
285281
{
286282
$this->translatedAttributes = [];
@@ -295,4 +291,4 @@ public function getTranslatable()
295291
{
296292
return $this->translatable;
297293
}
298-
}
294+
}

0 commit comments

Comments
 (0)