lib/composer/TranslationBundle/src/VisualMedia/TranslationBundle/Model/BaseLocaleModel.php line 27

Open in your IDE?
  1. <?php
  2. /**
  3. * Base Locale Model
  4. *
  5. * @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl>
  6. */
  7. namespace VisualMedia\TranslationBundle\Model;
  8. use Doctrine\Common\Collections\Collection;
  9. use Symfony\Component\Intl\Countries;
  10. use Symfony\Component\Intl\Languages;
  11. use Symfony\Component\Intl\Locales;
  12. use VisualMedia\TranslationBundle\Entity\BaseDomain;
  13. /**
  14. * Base Locale Model
  15. *
  16. * @property Collection|BaseDomain[] $domains
  17. */
  18. class BaseLocaleModel
  19. {
  20. /**
  21. * @param string $code
  22. */
  23. public function __construct(string $code = null)
  24. {
  25. $this->code = $code;
  26. if (!empty($this->code)) {
  27. @list($this->languageCode, $this->countryCode) = explode('_', $this->code);
  28. }
  29. }
  30. /**
  31. * @return string
  32. */
  33. public function getTitleByCode(): string
  34. {
  35. return Locales::getName($this->code);
  36. }
  37. /**
  38. * @return string
  39. */
  40. public function __toString(): string
  41. {
  42. return (string)$this->getTitleByCode();
  43. }
  44. }