Skip to content

Commit

Permalink
Fix bug with fallback locales
Browse files Browse the repository at this point in the history
  • Loading branch information
Bozhidar Hristov committed Dec 21, 2016
1 parent 213e63e commit 93a6c64
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/TranslationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(Container $Container)
$this->typeGuesser = $Container->get('form.registry')->getTypeGuesser();
$this->managerRegistry = $Container->get('doctrine');
$this->annotationReader = $Container->get('annotation_reader');
$this->translator = $Container->get('translator');
$this->translator = $Container->get('translator.default');
$this->request = $Container->get('request');
$this->propertyAccess = PropertyAccess::createPropertyAccessor();
}
Expand All @@ -84,9 +84,9 @@ public function getTranslation($entity, $language)
$translationService = $this;
$PropertyAccess = $this->propertyAccess;
$Translation = $Translations->filter(function($item) use ($translationService, $language, $PropertyAccess) {
$TranslationLanguage = $PropertyAccess->getValue($item, $translationService->getLanguageField($item));
return $language instanceof Language ? ($TranslationLanguage == $language) : ($TranslationLanguage->getLocale() == $language);
})->first();
$TranslationLanguage = $PropertyAccess->getValue($item, $translationService->getLanguageField($item));
return $language instanceof Language ? ($TranslationLanguage == $language) : ($TranslationLanguage->getLocale() == $language);
})->first();

return $Translation;
}
Expand All @@ -112,8 +112,8 @@ public function getCurrentLanguage()
$CurrentLocale = $this->translator->getLocale();
}
return $this->getLanguages()->filter(function(Language $Lang) use ($CurrentLocale) {
return $Lang->getLocale() == $CurrentLocale;
})->first();
return $Lang->getLocale() == $CurrentLocale;
})->first();
}

public function getFallbackLocales()
Expand Down Expand Up @@ -225,8 +225,8 @@ public function getCurrentTranslationField($translatableClass)
public function getLanguageByLocale($locale)
{
return $this->getLanguages()->filter(function(Language $Lang) use ($locale) {
return $Lang->getLocale() == $locale;
})->first();
return $Lang->getLocale() == $locale;
})->first();
}

/**
Expand Down Expand Up @@ -337,5 +337,4 @@ public function guessMissingFieldOptions($guesser, $class, $property, $options)

return $options;
}

}

0 comments on commit 93a6c64

Please sign in to comment.