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

Commit

Permalink
Added function hasTranslation(). #19
Browse files Browse the repository at this point in the history
  • Loading branch information
dimsav committed May 22, 2014
1 parent 937b0d4 commit 4df64eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Translatable/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,19 @@ protected function getNewTranslationInstance($locale)
return $translation;
}

public function hasTranslation($locale = null)
{
$locale = $locale ?: App::getLocale();

foreach ($this->translations as $translation)
{
if ($translation->getAttribute($this->getLocaleKey()) == $locale)
{
return true;
}
}

return false;
}

}
7 changes: 7 additions & 0 deletions tests/TranslatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,11 @@ public function testGettingTranslationFromSpecificLocale()
$this->assertEquals('Ελλάδα', $country->translate('el')->name);
}

public function testHasTranslation()
{
$country = Country::find(1);
$this->assertTrue($country->hasTranslation('en'));
$this->assertFalse($country->hasTranslation('abc'));
}

}

0 comments on commit 4df64eb

Please sign in to comment.