Skip to content

Commit

Permalink
Fixed major bug with direct attribute access
Browse files Browse the repository at this point in the history
  • Loading branch information
Flobbo authored and Flobbo committed Jul 13, 2017
1 parent 451a629 commit cfaed61
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/TranslatableDB/TranslatableDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public function getTranslationModelName(){
return $this->translationModel ?: $this->getTranslationModelNameDefault();
}

/**
* Retrieve the currently set languageModel or from config
* @return string
*/
public function getLanguageModelName(){
return isset($this->languageModel) ? $this->languageModel : $this->getConfigKey('language_model');
}

/**
* Main translation function to spit out translation based on locale
* @param bool $withFallback return untranslated attribute if no translation is found
Expand Down Expand Up @@ -155,7 +163,7 @@ private function getAttributeAndLocale($key){
if (str_contains($key, ':')) {
return explode(':', $key);
}
return [$key, $this->locale()];
return [$key, $this->getLocale()];
}

public function getRelationKey(){
Expand Down Expand Up @@ -237,7 +245,7 @@ protected function getFallbackKey(){
public function getLocale(){
//Database configuration
if($this->getConfigKey('use_db')){
$class = $this->languageModel ?: $this->getConfigKey('language_model');
$class = $this->getLanguageModelName();
$model = new $class;
$lang = $model->where($this->getConfigKey('locale_column'),$this->locale())->first();
if(!is_null($lang)){
Expand Down

0 comments on commit cfaed61

Please sign in to comment.