Skip to content

Commit

Permalink
Change default locale to be fallback_locale
Browse files Browse the repository at this point in the history
  • Loading branch information
ageshev committed Mar 21, 2017
1 parent 5e794fa commit 60212a9
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/Traits/HasTranslation.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace Despark\LaravelDbLocalization\Traits;


use Despark\LaravelDbLocalization\Models\TranslationModel;
use Despark\LaravelDbLocalization\Observers\ModelObserver;

Expand Down Expand Up @@ -33,7 +31,7 @@ trait HasTranslation
protected $activeLocale;

/**
* Bootstrap the trait
* Bootstrap the trait.
*/
public static function bootHasTranslation()
{
Expand All @@ -51,8 +49,9 @@ public function translation()
/**
* Create a new instance of the given model.
*
* @param array $attributes
* @param bool $exists
* @param array $attributes
* @param bool $exists
*
* @return static
*/
public function newInstance($attributes = [], $exists = false)
Expand All @@ -67,14 +66,14 @@ public function newInstance($attributes = [], $exists = false)
* Create a new model instance for a related model.
* We overwrite this so we can dynamically create the table on the related model.
*
* @param string $class
* @param string $class
*
* @return mixed
*/
protected function newRelatedInstance($class)
{

if (is_a($class, TranslationModel::class, true)) {
return tap(new $class, function ($instance) {
return tap(new $class(), function ($instance) {
$instance->setTable($this->getTranslationTable());

if (! $instance->getConnectionName()) {
Expand All @@ -83,7 +82,7 @@ protected function newRelatedInstance($class)
});
}

return tap(new $class, function ($instance) {
return tap(new $class(), function ($instance) {
if (! $instance->getConnectionName()) {
$instance->setConnection($this->connection);
}
Expand All @@ -92,7 +91,6 @@ protected function newRelatedInstance($class)

/**
* @param string $key
* @return null
*/
public function getAttribute($key)
{
Expand All @@ -118,10 +116,10 @@ public function setTranslation($key, $locale, $value)
$this->translatedAttributes[$locale][$key] = $value;
}


/**
* @param $key
* @param $locale
*
* @return string|null
*/
public function getTranslation($key, $locale = null)
Expand Down Expand Up @@ -163,6 +161,7 @@ public function unsetTranslation($locale, $key = null)
/**
* @param $key
* @param $value
*
* @return $this
*/
public function setAttribute($key, $value)
Expand All @@ -176,7 +175,6 @@ public function setAttribute($key, $value)
return parent::setAttribute($key, $value);
}


/**
* Load transaltions from database.
*/
Expand Down Expand Up @@ -218,7 +216,7 @@ public function getAvailableLocales()
*/
public function getDefaultLocale()
{
return config('app.locale');
return config('app.fallback_locale');
}

/**
Expand Down Expand Up @@ -271,16 +269,14 @@ public function getTranslationModel()

/**
* @param $key
*
* @return bool
*/
public function isTranslatable($key)
{
return in_array($key, $this->translatable);
}

/**
*
*/
public function refreshTranslations()
{
$this->translatedAttributes = [];
Expand All @@ -295,4 +291,4 @@ public function getTranslatable()
{
return $this->translatable;
}
}
}

0 comments on commit 60212a9

Please sign in to comment.