/** * {@inheritdoc} */ public function finishView(FormView $view, FormInterface $form, array $options) { if ($form->getConfig()->hasAttribute('prototype') && $view->vars['prototype']->vars['multipart']) { $view->vars['multipart'] = true; } $options = $form->getConfig()->getOptions(); $view->vars['null_locale_enabled'] = $options['null_locale_enabled']; $view->vars['null_locale_selected'] = $options['null_locale_selected']; $requestLocale = $this->getRequestLocale(); $view->vars['locale_titles'] = array(); foreach ($options['locales'] as $locale) { $view->vars['locale_titles'][$locale] = \Locale::getDisplayName($locale, $requestLocale); } $request = $this->getRequest(); if (null === $request) { $current_selected_lang = $options['locales'][0]; } else { $current_selected_lang = $request->cookies->get('current_selected_translation_lang', null); $selectedLanguageIsNotValid = $current_selected_lang !== '__all__' && !in_array($current_selected_lang, $options['locales']); if ($current_selected_lang === null || $selectedLanguageIsNotValid) { $current_selected_lang = $options['locales'][0]; } } $view->vars['current_selected_lang'] = $current_selected_lang; }
/** * Return the enabled locales suitable for local choosing. * * @return array Returns an array in the form `[locale => localeName]`. */ public static function enabledLocales() { $defaultLocale = Gdn_Locale::Canonicalize(C('Garden.Locale')); $localeModel = new LocaleModel(); if (class_exists('Locale')) { $localePacks = $localeModel->EnabledLocalePacks(false); $locales = array(); foreach ($localePacks as $locale) { if (isset(static::$overrides[$locale]['Name'])) { $locales[$locale] = static::$overrides[$locale]['Name']; } else { $locales[$locale] = ucwords(Locale::getDisplayName($locale, $locale)); } } $defaultName = Locale::getDisplayName($defaultLocale, $defaultLocale); } else { $locales = $localeModel->EnabledLocalePacks(true); $locales = array_column($locales, 'Name', 'Locale'); $defaultName = $defaultLocale === 'en' ? 'English' : $defaultLocale; } asort($locales); if (!array_key_exists($defaultLocale, $locales)) { $locales = array_merge(array($defaultLocale => $defaultName), $locales); } return $locales; }
public static function make_translations($project, $route, $params, $context, $default_db) { $tab_links = array(); $dm = $context->get('doctrine.odm.mongodb.document_manager'); $dm->getConfiguration()->setDefaultDB($default_db); $database = $dm->createQueryBuilder('PlantnetDataBundle:Database')->field('link')->equals($project)->getQuery()->getSingleResult(); if (!$database) { throw $context->createNotFoundException('Unable to find Database entity.'); } $current = $database->getlanguage(); $parent = $database->getParent(); if ($parent) { $database = $parent; } $children = $database->getChildren(); if (count($children)) { $params['project'] = $database->getLink(); $tab_links[$database->getLanguage()] = array('lang' => $database->getLanguage(), 'language' => \Locale::getDisplayName($database->getLanguage(), $database->getLanguage()), 'link' => $context->get('router')->generate($route, $params, true), 'active' => $database->getLanguage() == $current ? 1 : 0); $tab_sub_links = array(); foreach ($children as $child) { if ($child->getEnable() == true) { $params['project'] = $child->getLink(); $tab_sub_links[$child->getLanguage()] = array('lang' => $child->getLanguage(), 'language' => \Locale::getDisplayName($child->getLanguage(), $child->getLanguage()), 'link' => $context->get('router')->generate($route, $params, true), 'active' => $child->getLanguage() == $current ? 1 : 0); } } if (count($tab_sub_links)) { ksort($tab_sub_links); $tab_links = array_merge($tab_links, $tab_sub_links); } else { $tab_links = array(); } } return $tab_links; }
/** * A filter matching the same name to add additional information * about an attachment if it is a VTT or video. * * @param array $form_fields An array containing information about * the supplied attachment to display in the media library. * @param WP_Post $post Attachment post being viewed from the * media library. * @return array Updated $form_fields if the attachment is a VTT or * video. * @since 1.1.0 * @uses $webvtt * @see attachment_fields_to_edit() */ function attachment_fields_to_edit($form_fields, $post) { global $webvtt; $t = $post->post_mime_type; if ('text/vtt' === $t) { if ($t = $webvtt->get_video_by_vtt_name($post->post_name)) { $t = $this->get_post_link_html($t); } else { $t = '--'; } $form_fields['video'] = array('label' => __('Video'), 'input' => 'html', 'html' => $t); } elseif (0 === strpos($t, 'video/') && ($ts = $webvtt->get_tracks($post->post_name))) { $nl = strlen($post->post_name) + 1; static $labels, $locale; if (!$labels) { $labels = array('captions' => __('Video Captions', 'webvtt'), 'chapters' => __('Video Chapters', 'webvtt'), 'descriptions' => __('Video Descriptions', 'webvtt'), 'metadata' => __('Video Metadata', 'webvtt'), 'subtitles' => __('Video Subtitles', 'webvtt')); $locale = class_exists('Locale') ? get_locale() : false; } $vtts = array(); foreach ($ts as $i) { $t = substr($i->post_name, $nl, -3); $j = substr($i->post_name, -2); if ($locale) { $j = Locale::getDisplayName($j, $locale); } $vtts[$t][$j] = $i; } ksort($vtts); foreach ($vtts as $t => $js) { ksort($js); $h = ''; foreach ($js as $j => $i) { $h .= '<li>' . $this->get_post_link_html($i, $j) . '</li>'; } $form_fields['video_' . $t] = array('label' => $labels[$t], 'input' => 'html', 'html' => '<ol>' . $h . '</ol>'); } } return $form_fields; }
static function getLanguageDescription($lang) { global $thisstaff, $thisclient; $langs = self::availableLanguages(); $lang = strtolower($lang); if (isset($langs[$lang])) { $info =& $langs[$lang]; if (!isset($info['desc'])) { if (extension_loaded('intl')) { $lang = self::getCurrentLanguage(); list($simple_lang, ) = explode('_', $lang); $info['desc'] = sprintf("%s%s", Locale::getDisplayName($info['code'], $info['code']), strpos($simple_lang, $info['lang']) === false ? sprintf(' (%s)', Locale::getDisplayName($info['code'], $lang)) : ''); } else { $info['desc'] = sprintf("%s%s (%s)", $info['nativeName'], $info['locale'] ? sprintf(' - %s', $info['locale']) : '', $info['name']); } } return $info['desc']; } else { return $lang; } }
/** * Get the corresponding language name for a locale. * If the given locale contains a region code the name of that region will be appended in parentheses. * * @param string $locale Locale to be used with {@link http://php.net/manual/locale.getdisplayname.php}. * * @return string */ public function getLanguageName($locale) { if (empty($locale)) { return null; } $localeToUse = $this->showForeignLanguageNames ? $locale : $this->getLocale(); $languageName = \Locale::getDisplayName($locale, $localeToUse); if ($this->showFirstUppercase) { if (!extension_loaded('mbstring')) { throw new \RuntimeException('PHP extension "mbstring" is not loaded. Either load it or disable the "showFirstUppercase" option.'); } $encoding = mb_detect_encoding($languageName); $languageName = mb_strtoupper(mb_substr($languageName, 0, 1, $encoding), $encoding) . mb_substr($languageName, 1, mb_strlen($languageName, $encoding), $encoding); } return $languageName; }
/** * Returns the label of a locale in the specified language * * @param string $code the code of the locale to translate * @param string $translateIn the locale in which the label should be translated (if null, user locale will be used) * * @return string */ public function getLocaleLabel($code, $translateIn = null) { $translateIn = $translateIn ?: $this->getCurrentLocaleCode(); return \Locale::getDisplayName($code, $translateIn); }
/** * * * @param string $Path * @param Gdn_Controller $Controller */ public function init($Path, $Controller) { $Smarty = $this->smarty(); // Get a friendly name for the controller. $ControllerName = get_class($Controller); if (StringEndsWith($ControllerName, 'Controller', true)) { $ControllerName = substr($ControllerName, 0, -10); } // Get an ID for the body. $BodyIdentifier = strtolower($Controller->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::alphaNumeric(strtolower($Controller->RequestMethod))); $Smarty->assign('BodyID', htmlspecialchars($BodyIdentifier)); //$Smarty->assign('Config', Gdn::Config()); // Assign some information about the user. $Session = Gdn::session(); if ($Session->isValid()) { $User = array('Name' => htmlspecialchars($Session->User->Name), 'Photo' => '', 'CountNotifications' => (int) val('CountNotifications', $Session->User, 0), 'CountUnreadConversations' => (int) val('CountUnreadConversations', $Session->User, 0), 'SignedIn' => true); $Photo = $Session->User->Photo; if ($Photo) { if (!isUrl($Photo)) { $Photo = Gdn_Upload::url(changeBasename($Photo, 'n%s')); } } else { $Photo = UserModel::getDefaultAvatarUrl($Session->User); } $User['Photo'] = $Photo; } else { $User = false; /*array( 'Name' => '', 'CountNotifications' => 0, 'SignedIn' => FALSE);*/ } $Smarty->assign('User', $User); // Make sure that any datasets use arrays instead of objects. foreach ($Controller->Data as $Key => $Value) { if ($Value instanceof Gdn_DataSet) { $Controller->Data[$Key] = $Value->resultArray(); } elseif ($Value instanceof stdClass) { $Controller->Data[$Key] = (array) $Value; } } $BodyClass = val('CssClass', $Controller->Data, '', true); $Sections = Gdn_Theme::section(null, 'get'); if (is_array($Sections)) { foreach ($Sections as $Section) { $BodyClass .= ' Section-' . $Section; } } $Controller->Data['BodyClass'] = $BodyClass; // Set the current locale for themes to take advantage of. $Locale = Gdn::locale()->Locale; $CurrentLocale = array('Key' => $Locale, 'Lang' => str_replace('_', '-', Gdn::locale()->language(true))); if (class_exists('Locale')) { $CurrentLocale['Language'] = Locale::getPrimaryLanguage($Locale); $CurrentLocale['Region'] = Locale::getRegion($Locale); $CurrentLocale['DisplayName'] = Locale::getDisplayName($Locale, $Locale); $CurrentLocale['DisplayLanguage'] = Locale::getDisplayLanguage($Locale, $Locale); $CurrentLocale['DisplayRegion'] = Locale::getDisplayRegion($Locale, $Locale); } $Smarty->assign('CurrentLocale', $CurrentLocale); $Smarty->assign('Assets', (array) $Controller->Assets); // 2016-07-07 Linc: Request used to return blank for homepage. // Now it returns defaultcontroller. This restores BC behavior. $isHomepage = val('isHomepage', $Controller->Data); $Path = $isHomepage ? "" : Gdn::request()->path(); $Smarty->assign('Path', $Path); $Smarty->assign('Homepage', $isHomepage); // true/false // Assign the controller data last so the controllers override any default data. $Smarty->assign($Controller->Data); $security = new SmartySecurityVanilla($Smarty); $security->php_handling = Smarty::PHP_REMOVE; $security->allow_constants = false; $security->allow_super_globals = false; $security->streams = null; $security->setPhpFunctions(array_merge($security->php_functions, ['array', 'category', 'checkPermission', 'inSection', 'inCategory', 'ismobile', 'multiCheckPermission', 'getValue', 'setValue', 'url', 'useragenttype'])); $security->php_modifiers = array_merge($security->php_functions, array('sprintf')); $Smarty->enableSecurity($security); }
/** * Returns a name for the locale that is appropriate for display to the user. * * @param Locale|null $inLocale * * @return string */ public function getDisplayName(Locale $inLocale = null) { return \Locale::getDisplayName($this->locale, $inLocale ? $inLocale->locale : null); }
/** * @param Locale $locale * @param string $inLocale * * @return DisplayLocale */ public static function createFromLocale(Locale $locale, $inLocale = null) { $name = $inLocale ? \Locale::getDisplayName((string) $locale, $inLocale) : \Locale::getDisplayName((string) $locale); return new self($locale, $name); }
/** * Returns the name of a locale after localizing it in the default or some other locale. * * @param CULocale $inLocale **OPTIONAL. Default is** *the application's default locale*. The locale in which the * name is to be localized. * * @return CUStringObject The locale's localized name. */ public function dispName(CULocale $inLocale = null) { $strInLocale = isset($inLocale) ? $inLocale->m_name : self::defaultLocaleName(); return Locale::getDisplayName($this->m_name, $strInLocale); }
/** * Return the endonym for a given language - as per http://cldr.unicode.org/ * * @param $language * * @return string */ public static function languageName($language) { switch (str_replace(array('_', '@'), '-', $language)) { case 'af': return 'Afrikaans'; case 'ar': return 'العربية'; case 'bg': return 'български'; case 'bs': return 'bosanski'; case 'ca': return 'català'; case 'cs': return 'čeština'; case 'da': return 'dansk'; case 'de': return 'Deutsch'; case 'dv': return 'ދިވެހިބަސް'; case 'el': return 'Ελληνικά'; case 'en': return 'English'; case 'en-AU': return 'Australian English'; case 'en-GB': return 'British English'; case 'en-US': return 'U.S. English'; case 'es': return 'español'; case 'et': return 'eesti'; case 'fa': return 'فارسی'; case 'fi': return 'suomi'; case 'fo': return 'føroyskt'; case 'fr': return 'français'; case 'fr-CA': return 'français canadien'; case 'gl': return 'galego'; case 'haw': return 'ʻŌlelo Hawaiʻi'; case 'he': return 'עברית'; case 'hr': return 'hrvatski'; case 'hu': return 'magyar'; case 'id': return 'Bahasa Indonesia'; case 'is': return 'íslenska'; case 'it': return 'italiano'; case 'ja': return '日本語'; case 'ka': return 'ქართული'; case 'ko': return '한국어'; case 'lt': return 'lietuvių'; case 'lv': return 'latviešu'; case 'mi': return 'Māori'; case 'mr': return 'मराठी'; case 'ms': return 'Bahasa Melayu'; case 'nb': return 'norsk bokmål'; case 'ne': return 'नेपाली'; case 'nl': return 'Nederlands'; case 'nn': return 'nynorsk'; case 'oc': return 'occitan'; case 'pl': return 'polski'; case 'pt': return 'português'; case 'pt-BR': return 'português do Brasil'; case 'ro': return 'română'; case 'ru': return 'русский'; case 'sk': return 'slovenčina'; case 'sl': return 'slovenščina'; case 'sr': return 'Српски'; case 'sr-Latn': return 'srpski'; case 'sv': return 'svenska'; case 'ta': return 'தமிழ்'; case 'tr': return 'Türkçe'; case 'tt': return 'Татар'; case 'uk': return 'українська'; case 'vi': return 'Tiếng Việt'; case 'yi': return 'ייִדיש'; case 'zh': return '中文'; case 'zh-CN': return '简体中文'; // Simplified Chinese // Simplified Chinese case 'zh-TW': return '繁體中文'; // Traditional Chinese // Traditional Chinese default: // Use the PHP/intl library, if it exists if (class_exists('\\Locale')) { return Locale::getDisplayName($language, $language); } return $language; } }
/** * {@inheritdoc} */ public function getLocaleDisplayName($locale) { return \Locale::getDisplayName($locale); }
/** * Returns an appropriately localized display name for the locale * * @param string $inLocale Optional format locale * @return string Name of the locale in the format appropriate for $inLocale */ public function getDisplayName($inLocale = '') { if (!$inLocale) { $inLocale = $this->getLocale(); } return IntlLocale::getDisplayName($this->getLocale(), $inLocale); }
public function __toString() { return Language::getDisplayName($this->code); }
private function prepareDisplayProperties($lang) { $locale = $this->config->findLocaleByLanguage($lang); $nameOfLanguage = \Locale::getDisplayName($lang, $locale); $nameOfCountry = \Locale::getDisplayLanguage($lang, \Locale::getDefault()); $countryCode = \Locale::getRegion($locale); return [$nameOfLanguage, $nameOfCountry, $countryCode]; }
/** * Get $name * * @return string */ public function getName() { return \ucfirst(\Locale::getDisplayName($this->locale, $this->locale)); }
/** * @Route("/language_switch/{lang}", name="config_language_switch") * @Template() */ public function config_language_switchAction($lang) { $userManager = $this->get('fos_user.user_manager'); $user = $this->container->get('security.context')->getToken()->getUser(); $dm = $this->get('doctrine.odm.mongodb.document_manager'); $dm->getConfiguration()->setDefaultDB($this->getDataBase()); $database = $dm->getRepository('PlantnetDataBundle:Database')->findOneBy(array('name' => $user->getDbName())); if (!$database) { throw $this->createNotFoundException('Unable to find Database entity.'); } $parent = $database->getParent(); if ($parent) { $database = $parent; } $default = $database->getLanguage(); $availables = array(); $children = $database->getChildren(); if (count($children)) { foreach ($children as $child) { if ($child->getEnable() == true) { $availables[] = $child->getLanguage(); } } } $default_db = $database->getName(); $user->setDbName($default_db); if ($lang != $default) { if (in_array($lang, $availables)) { $user->setDbName($default_db . '_' . $lang); } } $userManager->updateUser($user); $this->get('session')->getFlashBag()->add('msg_success', 'Switched to ' . \Locale::getDisplayName($lang) . ' content'); return $this->redirect($this->generateUrl('admin_index')); }
<span class="input-group-btn"> <?php echo Html::submitButton('Find', ['class' => 'btn btn-primary']); ?> </span> </div> <?php echo Html::endForm(); ?> <?php if ($locale) { ?> <h1><?php echo Html::encode(\Locale::getDisplayName($locale, Yii::$app->language)); ?> <small><?php echo Html::encode($locale); ?> </small></h1> <small>Based on PHP intl data: ICU <?php echo INTL_ICU_VERSION; ?> . Data <?php echo INTL_ICU_DATA_VERSION; ?> .</small> <h2 id="plural-rules">Plural Rules <small><a href="#plural-rules">#</a></small></h2>
/** * @param InputInterface $input * @param OutputInterface $output */ protected function setupLocales(InputInterface $input, OutputInterface $output) { $localeRepository = $this->get('sylius.repository.locale'); $localeManager = $this->get('sylius.manager.locale'); do { if ($input->getOption('no-interaction')) { $locales = array('en_US'); } else { $output->writeln('Please enter list of locale codes, separated by commas or just hit ENTER to use "en_US". For example "en_US, de_DE".'); $codes = $this->ask($output, '<question>In which language your customers can browse the store?</question> ', array(), 'en_US'); $locales = explode(',', $codes); } $valid = true; foreach ($locales as $code) { if (0 !== count($errors = $this->validate(trim($code), array(new Locale())))) { $valid = false; } $this->writeErrors($output, $errors); } } while (!$valid); foreach ($locales as $key => $code) { $code = trim($code); try { $name = \Locale::getDisplayName($code); } catch (MethodNotImplementedException $e) { $name = $code; } $output->writeln(sprintf('Adding <info>%s</info>.', $name)); if (null !== $localeRepository->findOneByCode($code)) { continue; } $locale = $localeRepository->createNew(); $locale->setCode($code); $localeManager->persist($locale); } $localeManager->flush(); }
/** * * * @param $Path * @param $Controller */ public function init($Path, $Controller) { $Smarty = $this->smarty(); // Get a friendly name for the controller. $ControllerName = get_class($Controller); if (StringEndsWith($ControllerName, 'Controller', true)) { $ControllerName = substr($ControllerName, 0, -10); } // Get an ID for the body. $BodyIdentifier = strtolower($Controller->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::alphaNumeric(strtolower($Controller->RequestMethod))); $Smarty->assign('BodyID', $BodyIdentifier); //$Smarty->assign('Config', Gdn::Config()); // Assign some information about the user. $Session = Gdn::session(); if ($Session->isValid()) { $User = array('Name' => $Session->User->Name, 'Photo' => '', 'CountNotifications' => (int) val('CountNotifications', $Session->User, 0), 'CountUnreadConversations' => (int) val('CountUnreadConversations', $Session->User, 0), 'SignedIn' => true); $Photo = $Session->User->Photo; if ($Photo) { if (!IsUrl($Photo)) { $Photo = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s')); } } else { if (function_exists('UserPhotoDefaultUrl')) { $Photo = UserPhotoDefaultUrl($Session->User, 'ProfilePhoto'); } elseif ($ConfigPhoto = C('Garden.DefaultAvatar')) { $Photo = Gdn_Upload::url($ConfigPhoto); } else { $Photo = Asset('/applications/dashboard/design/images/defaulticon.png', true); } } $User['Photo'] = $Photo; } else { $User = false; /*array( 'Name' => '', 'CountNotifications' => 0, 'SignedIn' => FALSE);*/ } $Smarty->assign('User', $User); // Make sure that any datasets use arrays instead of objects. foreach ($Controller->Data as $Key => $Value) { if ($Value instanceof Gdn_DataSet) { $Controller->Data[$Key] = $Value->resultArray(); } elseif ($Value instanceof stdClass) { $Controller->Data[$Key] = (array) $Value; } } $BodyClass = val('CssClass', $Controller->Data, '', true); $Sections = Gdn_Theme::section(null, 'get'); if (is_array($Sections)) { foreach ($Sections as $Section) { $BodyClass .= ' Section-' . $Section; } } $Controller->Data['BodyClass'] = $BodyClass; // Set the current locale for themes to take advantage of. $Locale = Gdn::locale()->Locale; $CurrentLocale = array('Key' => $Locale, 'Lang' => str_replace('_', '-', $Locale)); if (class_exists('Locale')) { $CurrentLocale['Language'] = Locale::getPrimaryLanguage($Locale); $CurrentLocale['Region'] = Locale::getRegion($Locale); $CurrentLocale['DisplayName'] = Locale::getDisplayName($Locale, $Locale); $CurrentLocale['DisplayLanguage'] = Locale::getDisplayLanguage($Locale, $Locale); $CurrentLocale['DisplayRegion'] = Locale::getDisplayRegion($Locale, $Locale); } $Smarty->assign('CurrentLocale', $CurrentLocale); $Smarty->assign('Assets', (array) $Controller->Assets); $Smarty->assign('Path', Gdn::request()->path()); // Assign the controller data last so the controllers override any default data. $Smarty->assign($Controller->Data); $Smarty->Controller = $Controller; // for smarty plugins $Smarty->security = true; $Smarty->security_settings['IF_FUNCS'] = array_merge($Smarty->security_settings['IF_FUNCS'], array('Category', 'CheckPermission', 'InSection', 'InCategory', 'MultiCheckPermission', 'GetValue', 'SetValue', 'Url')); $Smarty->security_settings['MODIFIER_FUNCS'] = array_merge($Smarty->security_settings['MODIFIER_FUNCS'], array('sprintf')); $Smarty->secure_dir = array($Path); }
/** * Returns the language name * * @param string $locale Locale to get name for * @param string $in_locale Locale to display name in (when PHP intl is not installed, this is the indicator for native displaying) * * @return string */ public static function getLanguageName($locale, $in_locale) { if (class_exists('Locale')) { $languageName = Locale::getDisplayName($locale, $in_locale); } else { $native = false; if ($locale == $in_locale) { $native = true; } $languageName = i18n::get_language_name(substr($locale, 0, strpos($locale, '_')), $native); if (empty($languageName)) { $common_locales = i18n::get_common_locales($native); $all_locales = (array) Config::inst()->get('i18n', 'all_locales'); if (array_key_exists($locale, $common_locales)) { $languageName = $common_locales[$locale]; } elseif (array_key_exists($locale, $all_locales)) { $languageName = $all_locales[$locale]; } } } return $languageName; }
/** * Get locale name. * * If param $inLocale is not set the result will be in the local original language. * * @param Locale|string $inLocale [optional] Set the locale to display value in. * * @return string */ public function getLocaleName($inLocale = null) { $inLocale = Locale::sanitizeLocale($inLocale, $this->locale); return \Locale::getDisplayName($this->locale, $inLocale); }
protected function displayLocale(InputInterface $input, OutputInterface $output) { if ($input->getOption('locale')) { \Locale::setDefault($input->getOption('locale')); } $output->writeln('Available Faker locales'); $output->writeln(''); $locales = []; foreach ($this->getFakerConfig()->getLocales() as $locale) { $locales[] = [$locale, \Locale::getDisplayName($locale)]; } $table = $this->getHelperSet()->get('table'); $table->setCellRowFormat('<comment>%s</comment>'); $table->setHeaders(array('Locale', 'Language'))->setRows($locales); $table->render($output); $output->writeln(''); }
/** * @param InputInterface $input * @param OutputInterface $output */ protected function setupLocales(InputInterface $input, OutputInterface $output) { $localeRepository = $this->get('sylius.repository.locale'); $localeManager = $this->get('sylius.manager.locale'); $localeFactory = $this->get('sylius.factory.locale'); do { $locales = $this->getLocalesCodes($input, $output); $valid = true; foreach ($locales as $code) { if (0 !== count($errors = $this->validate(trim($code), array(new Locale())))) { $valid = false; } $this->writeErrors($output, $errors); } } while (!$valid); foreach ($locales as $key => $code) { $code = trim($code); try { $name = \Locale::getDisplayName($code); } catch (MethodNotImplementedException $e) { $name = $code; } $output->writeln(sprintf('Adding <info>%s</info>.', $name)); if (null !== ($existingLocale = $localeRepository->findOneByCode($code))) { $this->locales[] = $existingLocale; continue; } $locale = $localeFactory->createNew(); $locale->setCode($code); $this->locales[] = $locale; $localeManager->persist($locale); } $localeManager->flush(); }
public function language($var) { return \Locale::getDisplayName($var); }