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

Commit

Permalink
Merge pull request #121 from aydnbhdr/master
Browse files Browse the repository at this point in the history
getLocale function removed
  • Loading branch information
dimsav committed May 21, 2015
2 parents 1116d7d + 6fab689 commit c9d870f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Translatable/Translatable.php
Expand Up @@ -41,7 +41,7 @@ public function translateOrNew($locale)
*/
public function getTranslation($locale = null, $withFallback = null)
{
$locale = $locale ?: App::getLocale();
$locale = $locale ?: $this->locale();

$withFallback = $withFallback === null ? $this->useFallback() : $withFallback;

Expand All @@ -61,7 +61,7 @@ public function getTranslation($locale = null, $withFallback = null)

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

foreach ($this->translations as $translation) {
if ($translation->getAttribute($this->getLocaleKey()) == $locale) {
Expand Down Expand Up @@ -106,7 +106,7 @@ public function getAttribute($key)
if (str_contains($key, ':')) {
list($key, $locale) = explode(':', $key);
} else {
$locale = App::getLocale();
$locale = $this->locale();
}

if ($this->isTranslationAttribute($key)) {
Expand All @@ -125,7 +125,7 @@ public function setAttribute($key, $value)
if (str_contains($key, ':')) {
list($key, $locale) = explode(':', $key);
} else {
$locale = App::getLocale();
$locale = $this->locale();
}

if (in_array($key, $this->translatedAttributes)) {
Expand Down Expand Up @@ -239,7 +239,7 @@ protected function getLocales()

if (empty($locales)) {
throw new LocalesNotDefinedException('Please make sure you have run "php artisan config:publish dimsav/laravel-translatable" '.
' and that the locales configuration is defined.');
' and that the locales configuration is defined.');
}

return $locales;
Expand Down Expand Up @@ -313,15 +313,15 @@ public function scopeListsTranslations(Builder $query, $translationField)
$query
->select($this->getTable().'.'.$this->getKeyName(), $this->getTranslationsTable().'.'.$translationField)
->leftJoin($this->getTranslationsTable(), $this->getTranslationsTable().'.'.$this->getRelationKey(), '=', $this->getTable().'.'.$this->getKeyName())
->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), App::getLocale())
->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), $this->locale())
;
if ($withFallback) {
$query->orWhere(function (Builder $q) {
$q->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), $this->getFallbackLocale())
->whereNotIn($this->getTranslationsTable().'.'.$this->getRelationKey(), function (QueryBuilder $q) {
$q->select($this->getTranslationsTable().'.'.$this->getRelationKey())
->from($this->getTranslationsTable())
->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), App::getLocale());
->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), $this->locale());
});
});
}
Expand Down Expand Up @@ -349,4 +349,9 @@ private function getTranslationsTable()
{
return App::make($this->getTranslationModelName())->getTable();
}

protected function locale()
{
return App::make('translator')->getLocale();
}
}

0 comments on commit c9d870f

Please sign in to comment.