mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix loading countries
This commit is contained in:
parent
770d64a2f8
commit
984c35f8bc
@ -19,6 +19,7 @@ use Symfony\Component\Console\Input\InputOption;
|
|||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Intl\Intl;
|
use Symfony\Component\Intl\Intl;
|
||||||
|
|
||||||
|
use Symfony\Component\Intl\Languages;
|
||||||
use function in_array;
|
use function in_array;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -84,15 +85,12 @@ class LoadAndUpdateLanguagesCommand extends Command
|
|||||||
{
|
{
|
||||||
$em = $this->entityManager;
|
$em = $this->entityManager;
|
||||||
$chillAvailableLanguages = $this->availableLanguages;
|
$chillAvailableLanguages = $this->availableLanguages;
|
||||||
$languages = [];
|
|
||||||
|
|
||||||
foreach ($chillAvailableLanguages as $avLang) {
|
foreach ($chillAvailableLanguages as $avLang) {
|
||||||
$languages[$avLang] = \Symfony\Component\Intl\Languages::getNames();
|
$languages[$avLang] = \Symfony\Component\Intl\Languages::getNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
$languageCodes = array_keys($languages[$chillAvailableLanguages[0]]);
|
foreach (Languages::getNames() as $code => $lang) {
|
||||||
|
|
||||||
foreach ($languageCodes as $code) {
|
|
||||||
$excludeCode = (
|
$excludeCode = (
|
||||||
(
|
(
|
||||||
!$input->getOption(self::INCLUDE_REGIONAL_VERSION)
|
!$input->getOption(self::INCLUDE_REGIONAL_VERSION)
|
||||||
@ -104,28 +102,25 @@ class LoadAndUpdateLanguagesCommand extends Command
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$langageDB = $em->getRepository(Language::class)->find($code);
|
if (true === $excludeCode) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$excludeCode) {
|
$languageDB = $em->getRepository(Language::class)->find($code);
|
||||||
if (!$langageDB) {
|
|
||||||
$langageDB = new \Chill\MainBundle\Entity\Language();
|
if (null === $languageDB) {
|
||||||
$langageDB->setId($code);
|
$languageDB = new \Chill\MainBundle\Entity\Language();
|
||||||
$em->persist($langageDB);
|
$languageDB->setId($code);
|
||||||
|
$em->persist($languageDB);
|
||||||
}
|
}
|
||||||
|
|
||||||
$avLangNames = [];
|
$avLangNames = [];
|
||||||
|
|
||||||
foreach ($chillAvailableLanguages as $avLang) {
|
foreach ($chillAvailableLanguages as $avLang) {
|
||||||
$avLangNames[$avLang] = $languages[$avLang][$code];
|
$avLangNames[$avLang] = Languages::getName($code, $avLang);
|
||||||
}
|
}
|
||||||
|
|
||||||
$langageDB->setName($avLangNames);
|
$languageDB->setName($avLangNames);
|
||||||
} else {
|
|
||||||
if ($langageDB) {
|
|
||||||
$em->remove($langageDB);
|
|
||||||
}
|
|
||||||
echo 'Code excluded : ' . $code . ' - ' . \Symfony\Component\Intl\Languages::getName('en_GB') . "\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
@ -16,6 +16,7 @@ use Doctrine\ORM\EntityManager;
|
|||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Intl\Countries;
|
||||||
use Symfony\Component\Intl\Intl;
|
use Symfony\Component\Intl\Intl;
|
||||||
|
|
||||||
class LoadCountriesCommand extends Command
|
class LoadCountriesCommand extends Command
|
||||||
@ -32,24 +33,18 @@ class LoadCountriesCommand extends Command
|
|||||||
|
|
||||||
public static function prepareCountryList($languages)
|
public static function prepareCountryList($languages)
|
||||||
{
|
{
|
||||||
$regionBundle = Intl::getRegionBundle();
|
$countryCodes = Countries::getCountryCodes();
|
||||||
$countries = [];
|
|
||||||
|
|
||||||
foreach ($languages as $language) {
|
|
||||||
$countries[$language] = \Symfony\Component\Intl\Currencies::getNames();
|
|
||||||
}
|
|
||||||
|
|
||||||
$countryEntities = [];
|
$countryEntities = [];
|
||||||
|
|
||||||
foreach ($countries[$languages[0]] as $countryCode => $name) {
|
foreach ($countryCodes as $code) {
|
||||||
$names = [];
|
$names = [];
|
||||||
|
|
||||||
foreach ($languages as $language) {
|
foreach ($languages as $language) {
|
||||||
$names[$language] = $countries[$language][$countryCode];
|
$names[$language] = Countries::getName($code, $language);
|
||||||
}
|
}
|
||||||
|
|
||||||
$country = new \Chill\MainBundle\Entity\Country();
|
$country = new \Chill\MainBundle\Entity\Country();
|
||||||
$country->setName($names)->setCountryCode($countryCode);
|
$country->setName($names)->setCountryCode($code);
|
||||||
$countryEntities[] = $country;
|
$countryEntities[] = $country;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ class LoadLanguages extends AbstractFixture implements ContainerAwareInterface,
|
|||||||
$names = [];
|
$names = [];
|
||||||
|
|
||||||
foreach ($this->container->getParameter('chill_main.available_languages') as $lang) {
|
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;
|
return $names;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user