Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Feb 7, 2018
2 parents 4be6dbf + 1f6fb05 commit feabc97
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

All notable changes to `laravel-translatable` will be documented in this file

## 2.1.3 - 2018-02-08
## 2.1.4 - 2018-02-08
- add support for L5.6

## 2.1.3 - 2018-01-24
- make locale handling more flexible

## 2.1.2 - 2017-12-24
- fix for using translations within translations

Expand Down
9 changes: 7 additions & 2 deletions src/HasTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function getAttributeValue($key)
return parent::getAttributeValue($key);
}

return $this->getTranslation($key, config('app.locale'));
return $this->getTranslation($key, $this->getLocale());
}

/**
Expand All @@ -38,7 +38,7 @@ public function setAttribute($key, $value)
}
// if the attribute is translatable and not already translated (=array),
// set a translation for the current app locale
return $this->setTranslation($key, config('app.locale'), $value);
return $this->setTranslation($key, $this->getLocale(), $value);
}

/**
Expand Down Expand Up @@ -196,6 +196,11 @@ protected function normalizeLocale(string $key, string $locale, bool $useFallbac
return $locale;
}

protected function getLocale() : string
{
return config('app.locale');
}

public function getTranslatableAttributes() : array
{
return is_array($this->translatable)
Expand Down
10 changes: 5 additions & 5 deletions tests/TranslatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function setNameAttribute($value)
$translations = [
'nl' => 'hallo',
'en' => 'hello',
'kh' => 'សួរស្តី'
'kh' => 'សួរស្តី',
];

$testModel->setTranslations('name', $translations);
Expand All @@ -317,7 +317,7 @@ public function setNameAttribute($value)
$expected = [
'nl' => 'I just mutated hallo',
'en' => 'I just mutated hello',
'kh' => 'I just mutated សួរស្តី'
'kh' => 'I just mutated សួរស្តី',
];

$this->assertEquals($expected, $testModel->getTranslations('name'));
Expand All @@ -335,19 +335,19 @@ public function setOtherFieldAttribute($value, $locale = 'en')

$testModel->setTranslations('name', [
'nl' => 'wereld',
'en' => 'world'
'en' => 'world',
]);

$testModel->setTranslations('other_field', [
'nl' => 'hallo',
'en' => 'hello'
'en' => 'hello',
]);

$testModel->save();

$expected = [
'nl' => 'hallo wereld',
'en' => 'hello world'
'en' => 'hello world',
];

$this->assertEquals($expected, $testModel->getTranslations('other_field'));
Expand Down

0 comments on commit feabc97

Please sign in to comment.