diff --git a/src/Bundle/ChillMainBundle/Command/LoadAndUpdateLanguagesCommand.php b/src/Bundle/ChillMainBundle/Command/LoadAndUpdateLanguagesCommand.php index 5b86b8c9b..ae32c8359 100644 --- a/src/Bundle/ChillMainBundle/Command/LoadAndUpdateLanguagesCommand.php +++ b/src/Bundle/ChillMainBundle/Command/LoadAndUpdateLanguagesCommand.php @@ -19,6 +19,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Intl\Intl; +use Symfony\Component\Intl\Languages; use function in_array; /* @@ -84,15 +85,12 @@ class LoadAndUpdateLanguagesCommand extends Command { $em = $this->entityManager; $chillAvailableLanguages = $this->availableLanguages; - $languages = []; foreach ($chillAvailableLanguages as $avLang) { $languages[$avLang] = \Symfony\Component\Intl\Languages::getNames(); } - $languageCodes = array_keys($languages[$chillAvailableLanguages[0]]); - - foreach ($languageCodes as $code) { + foreach (Languages::getNames() as $code => $lang) { $excludeCode = ( ( !$input->getOption(self::INCLUDE_REGIONAL_VERSION) @@ -104,28 +102,25 @@ class LoadAndUpdateLanguagesCommand extends Command ) ); - $langageDB = $em->getRepository(Language::class)->find($code); - - if (!$excludeCode) { - if (!$langageDB) { - $langageDB = new \Chill\MainBundle\Entity\Language(); - $langageDB->setId($code); - $em->persist($langageDB); - } - - $avLangNames = []; - - foreach ($chillAvailableLanguages as $avLang) { - $avLangNames[$avLang] = $languages[$avLang][$code]; - } - - $langageDB->setName($avLangNames); - } else { - if ($langageDB) { - $em->remove($langageDB); - } - echo 'Code excluded : ' . $code . ' - ' . \Symfony\Component\Intl\Languages::getName('en_GB') . "\n"; + if (true === $excludeCode) { + continue; } + + $languageDB = $em->getRepository(Language::class)->find($code); + + if (null === $languageDB) { + $languageDB = new \Chill\MainBundle\Entity\Language(); + $languageDB->setId($code); + $em->persist($languageDB); + } + + $avLangNames = []; + + foreach ($chillAvailableLanguages as $avLang) { + $avLangNames[$avLang] = Languages::getName($code, $avLang); + } + + $languageDB->setName($avLangNames); } $em->flush(); diff --git a/src/Bundle/ChillMainBundle/Command/LoadCountriesCommand.php b/src/Bundle/ChillMainBundle/Command/LoadCountriesCommand.php index 025188c36..69831d2a0 100644 --- a/src/Bundle/ChillMainBundle/Command/LoadCountriesCommand.php +++ b/src/Bundle/ChillMainBundle/Command/LoadCountriesCommand.php @@ -16,6 +16,7 @@ use Doctrine\ORM\EntityManager; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Intl\Countries; use Symfony\Component\Intl\Intl; class LoadCountriesCommand extends Command @@ -32,24 +33,18 @@ class LoadCountriesCommand extends Command public static function prepareCountryList($languages) { - $regionBundle = Intl::getRegionBundle(); - $countries = []; - - foreach ($languages as $language) { - $countries[$language] = \Symfony\Component\Intl\Currencies::getNames(); - } - + $countryCodes = Countries::getCountryCodes(); $countryEntities = []; - foreach ($countries[$languages[0]] as $countryCode => $name) { + foreach ($countryCodes as $code) { $names = []; foreach ($languages as $language) { - $names[$language] = $countries[$language][$countryCode]; + $names[$language] = Countries::getName($code, $language); } $country = new \Chill\MainBundle\Entity\Country(); - $country->setName($names)->setCountryCode($countryCode); + $country->setName($names)->setCountryCode($code); $countryEntities[] = $country; } diff --git a/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadLanguages.php b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadLanguages.php index 7b605a0ae..75472d3a7 100644 --- a/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadLanguages.php +++ b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadLanguages.php @@ -75,7 +75,7 @@ class LoadLanguages extends AbstractFixture implements ContainerAwareInterface, $names = []; foreach ($this->container->getParameter('chill_main.available_languages') as $lang) { - $names[$lang] = \Symfony\Component\Intl\Languages::getName('en_GB'); + $names[$lang] = \Symfony\Component\Intl\Languages::getName($languageCode, $lang); } return $names;