Fix loading countries

This commit is contained in:
Julien Fastré 2023-07-30 22:01:55 +02:00
parent 770d64a2f8
commit 984c35f8bc
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 26 additions and 36 deletions

View File

@ -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();

View File

@ -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;
}

View File

@ -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;