Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

Allow translateOrDefault to user app locale #500

Merged
merged 3 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
allow translateOrDefault with app locale
  • Loading branch information
Ralph Huwiler committed Jul 13, 2018
commit 6a41671e91f0d227f237efd982d5e5462e5d84fb
2 changes: 1 addition & 1 deletion src/Translatable/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function translate($locale = null, $withFallback = false)
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function translateOrDefault($locale)
public function translateOrDefault($locale = null)
{
return $this->getTranslation($locale, true);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/TranslatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ public function test_it_returns_default_translation()
$this->assertSame($country->getTranslation('ch', true)->name, 'Griechenland');
$this->assertSame($country->translateOrDefault('ch')->name, 'Griechenland');
$this->assertSame($country->getTranslation('ch', false), null);

$this->app->setLocale('ch');
$this->assertSame($country->translateOrDefault()->name, 'Griechenland');
}

public function test_fallback_option_in_config_overrides_models_fallback_option()
Expand Down