Esempio n. 1
0
 private function getLanguageName($locale = null)
 {
     if (!$locale) {
         $locale = $this->getCurrentLocale();
     }
     return Intl::getLanguageBundle()->getLanguageName($locale, null, $this->getCurrentLocale());
 }
Esempio n. 2
0
 /**
  * @param mixed $value
  *
  * @throws InvalidLanguageCodeException
  */
 protected function guard($value)
 {
     $languageName = Intl::getLanguageBundle()->getLanguageName($value);
     if (null === $languageName) {
         throw new InvalidLanguageCodeException($value);
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $intlBundle = Intl::getLanguageBundle();
     $builder->add('locale', ChoiceType::class, ['choices' => $options['lang_code'], 'choices_as_values' => true, 'choice_label' => function ($lang) use($intlBundle) {
         return $intlBundle->getLanguageName($lang);
     }]);
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function loadChoiceList($value = null)
 {
     if (null !== $this->choiceList) {
         return $this->choiceList;
     }
     return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getLanguageBundle()->getLanguageNames()), $value);
 }
 public function indexAction(Request $request)
 {
     $searchForm = $this->createForm(new MainSearch());
     $searchForm->handleRequest($request);
     if ($searchForm->isValid()) {
         $userAgent = $request->headers->get('User-Agent');
         $clientIp = $request->getClientIp();
         $preferredLanguage = $request->getPreferredLanguage();
         $acceptedLanguages = $request->getLanguages();
         $languageName = Intl::getLanguageBundle()->getLanguageName($preferredLanguage);
         $data = $searchForm->getData();
         $searchRecord = new Searches();
         $searchRecord->setSearchDate(new DateTime());
         $searchRecord->setClientIpAddress($clientIp);
         $searchRecord->setAcceptedLanguages($acceptedLanguages);
         $searchRecord->setPreferredLanguage($languageName);
         $searchRecord->setUserAgent($userAgent);
         $searchRecord->setSearchText($data['search_element_text']);
         $searchRecord->setSerializedData($data);
         $em = $this->get('doctrine')->getManager();
         $em->persist($searchRecord);
         $em->flush();
         //redirect off to google
         $queryParams = array('q' => $data['search_element_text']);
         return $this->redirect(sprintf("%s#%s&tbs=qdr:y", self::GOOGLE_URL, http_build_query($queryParams)));
     } else {
         //get last 10 searches
         $lastTenSearches = $this->getDoctrine()->getRepository('YeargleCoreBundle:Searches')->getLastTenSearches();
         if (!$lastTenSearches) {
             //
             $lastTenSearches = array();
         }
         return $this->render('YeargleCoreBundle:Default:index.html.twig', array('searchForm' => $searchForm->createView(), 'lastTenSearches' => $lastTenSearches));
     }
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(array(
         'choices' => Intl::getLanguageBundle()->getLanguageNames(),
         'choice_translation_domain' => false,
     ));
 }
Esempio n. 7
0
 /**
  * Returns the language names for a locale.
  *
  * @param string $locale The locale to use for the language names
  *
  * @return array The language names with their codes as keys
  *
  * @throws \RuntimeException When the resource bundles cannot be loaded
  */
 public static function getDisplayLanguages($locale)
 {
     if (!isset(self::$languages[$locale])) {
         self::$languages[$locale] = Intl::getLanguageBundle()->getLanguageNames($locale);
     }
     return self::$languages[$locale];
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $textWriter = new TextBundleWriter();
     $textWriter->write(CACHE_PATH . 'intl/text_bundle', 'en', ['data' => ['Ok']]);
     $textWriter->write(CACHE_PATH . 'intl/text_bundle', 'ru', ['data' => ['Хорошо']]);
     $phpWriter = new PhpBundleWriter();
     $phpWriter->write(CACHE_PATH . 'intl/php_bundle', 'en', ['data' => 'php bundle: Ok', 'nested' => ['message' => 'Hi!']]);
     $phpWriter = new PhpBundleWriter();
     $phpWriter->write(CACHE_PATH . 'intl/php_bundle', 'ru', ['data' => 'php bundle: Хорошо', 'nested' => ['message' => 'Привет!']]);
     $compiler = new GenrbCompiler();
     $compiler->compile(CACHE_PATH . 'intl/text_bundle', CACHE_PATH . 'intl/compiled');
     $phpReader = new PhpBundleReader();
     $data = $phpReader->read(CACHE_PATH . 'intl/php_bundle', 'en');
     $output->writeln($data['data']);
     $data = $phpReader->read(CACHE_PATH . 'intl/php_bundle', 'ru');
     $output->writeln($data['data']);
     $reader = new BundleEntryReader($phpReader);
     $data = $reader->readEntry(CACHE_PATH . 'intl/php_bundle', 'ru', ['nested', 'message']);
     $output->writeln($data);
     $language = Intl::getLanguageBundle()->getLanguageName('ru', 'RU', 'en');
     $output->writeln($language);
     $language = Intl::getLanguageBundle()->getLanguageName('ru', 'RU', 'de');
     $output->writeln($language);
     $language = Intl::getLanguageBundle()->getLanguageName('ru', 'RU', 'ru');
     $output->writeln($language);
     $currencyName = Intl::getCurrencyBundle()->getCurrencyName('RUB', 'en');
     $output->writeln($currencyName);
     $currencyName = Intl::getCurrencyBundle()->getCurrencySymbol('USD', 'en');
     $output->writeln($currencyName);
     $output->writeln('<comment>Ok</comment>');
 }
 /**
  * Constructor
  */
 public function __construct(ProfileService $profileService, DocumentManager $documentManager, TranslatorInterface $translator)
 {
     $this->dm = $documentManager;
     $this->languages = Intl::getLanguageBundle()->getLanguageNames();
     $this->profileService = $profileService;
     $this->translator = $translator;
 }
Esempio n. 10
0
    /**
     * {@inheritdoc}
     */
    public function validate($value, Constraint $constraint)
    {
        if (!$constraint instanceof Language) {
            throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Language');
        }

        if (null === $value || '' === $value) {
            return;
        }

        if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
            throw new UnexpectedTypeException($value, 'string');
        }

        $value = (string) $value;
        $languages = Intl::getLanguageBundle()->getLanguageNames();

        if (!isset($languages[$value])) {
            if ($this->context instanceof ExecutionContextInterface) {
                $this->context->buildViolation($constraint->message)
                    ->setParameter('{{ value }}', $this->formatValue($value))
                    ->setCode(Language::NO_SUCH_LANGUAGE_ERROR)
                    ->addViolation();
            } else {
                $this->buildViolation($constraint->message)
                    ->setParameter('{{ value }}', $this->formatValue($value))
                    ->setCode(Language::NO_SUCH_LANGUAGE_ERROR)
                    ->addViolation();
            }
        }
    }
Esempio n. 11
0
 /**
  * @param GenderizeClient $genderizeClient
  */
 public function __construct(GenderizeClient $genderizeClient = null)
 {
     if ($genderizeClient) {
         $this->genderizeClient = $genderizeClient;
     } else {
         // create default client
         $this->genderizeClient = new GenderizeClient('https://api.genderize.io/');
     }
     $this->validCountries = Intl::getRegionBundle()->getCountryNames();
     $this->validLanguages = Intl::getLanguageBundle()->getLanguageNames();
 }
Esempio n. 12
0
 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (null === $value || '' === $value) {
         return;
     }
     if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
         throw new UnexpectedTypeException($value, 'string');
     }
     $value = (string) $value;
     $languages = Intl::getLanguageBundle()->getLanguageNames();
     if (!isset($languages[$value])) {
         $this->context->addViolation($constraint->message, array('{{ value }}' => $value));
     }
 }
 private function retrieveLanguage($geantFeedObject)
 {
     if (!isset($geantFeedObject['expressions']['language'])) {
         throw new FeedSyncException(sprintf('There is no language (expressions.language) on feed with ID: %s', $geantFeedObject['identifier']));
     }
     $lang = $geantFeedObject['expressions']['language'];
     $lang = substr($lang, -2, 2);
     $lang = strtolower($lang);
     $languageNames = Intl::getLanguageBundle()->getLanguageNames();
     if (!array_key_exists($lang, $languageNames)) {
         throw new FeedSyncException(sprintf('The feed with ID: %s has a language format that is not recognized: %s', $geantFeedObject['identifier'], $geantFeedObject['expressions']['language']));
     }
     return $lang;
 }
 public static function getLanguageNames($customLanguages, $translator)
 {
     $languageNames = Intl::getLanguageBundle()->getLanguageNames();
     if ($customLanguages) {
         $choices = array();
         foreach ($customLanguages as $aux) {
             $code = strtolower($aux);
             $choices[$code] = isset($languageNames[$code]) ? $languageNames[$code] : (isset(self::$addonLanguages[$code]) ? $translator->trans(self::$addonLanguages[$code]) : $code);
         }
     } else {
         $choices = $languageNames;
     }
     return $choices;
 }
 private function retrieveInterfaceLanguages()
 {
     //Setting the default locale to english
     Locale::setDefault('en');
     $languages = [];
     //We want all the names of languages translated in all supported languages
     $source_languages = app('config')->get('app.supported_locales');
     if (!empty($source_languages)) {
         $target_languages = $source_languages;
         foreach ($source_languages as $language) {
             foreach ($target_languages as $targetLanguage) {
                 $languages[$language][$targetLanguage] = ucfirst(Intl::getLanguageBundle()->getLanguageName($targetLanguage, null, $language));
             }
         }
     }
     return $languages;
 }
 public function localesAction($route, $routeParams, $locale = null)
 {
     if (empty($locale)) {
         $locale = \Locale::getDefault();
     }
     if (is_string($routeParams)) {
         $routeParams = json_decode($routeParams, true);
     }
     $locales = $this->container->getParameter('bootstrapp.locales');
     $choices = [];
     switch ($this->container->getParameter('bootstrapp.locales_display')) {
         case 'dialect':
             $dialects = [];
             foreach ($locales as $locale) {
                 $lang = substr($locale, 0, 2);
                 if (!isset($dialects[$lang])) {
                     $dialects[$lang] = 1;
                 } else {
                     $dialects[$lang]++;
                 }
             }
             foreach ($locales as $l) {
                 $lang = substr($l, 0, 2);
                 $region = strlen($l) > 2 && $dialects[$lang] > 1 ? substr($l, -2) : null;
                 $choices[$l] = ucfirst(Intl::getLanguageBundle()->getLanguageName($lang, $region, $l));
             }
             break;
         case 'language':
             foreach ($locales as $l) {
                 $choices[$l] = ucfirst(Intl::getLanguageBundle()->getLanguageName(substr($l, 0, 2), null, $l));
             }
             break;
         default:
             foreach ($locales as $l) {
                 $choices[$l] = ucfirst(Intl::getLocaleBundle()->getLocaleName($l, $l));
             }
             break;
     }
     asort($choices);
     return $this->render('BootstrappBundle:Navbar:locales.html.twig', array('route' => $route, 'routeParams' => $routeParams, 'locale' => $locale, 'locales' => $choices));
 }
 private function populateTranslationLocaleMenu(Item $menu)
 {
     $requestParameters = $this->getRequestParameters();
     $route = $this->request->get('_route');
     $languageBundle = Intl::getLanguageBundle();
     if (isset($requestParameters['redirect_uri'])) {
         $redirectRequest = $this->createRedirectRequest($requestParameters['redirect_uri']);
     }
     foreach ($this->localeManager->getLocales() as $locale) {
         $requestParameters['locale'] = $locale;
         if (isset($redirectRequest)) {
             try {
                 $requestParameters['redirect_uri'] = $this->generateRequestUriForLocale($redirectRequest, $locale);
             } catch (ResourceNotFoundException $e) {
             }
         }
         $localeItem = new RoutableItem(sprintf('translation-locale.%s', $locale), $route, $requestParameters);
         $localeItem->setLabel($languageBundle->getLanguageName($locale, null, $this->request->getLocale()));
         $menu->addChild($localeItem);
     }
 }
 public function __construct()
 {
     $this->languageBundle = Intl::getLanguageBundle();
     $this->regionBundle = Intl::getRegionBundle();
 }
Esempio n. 19
0
 /**
  * Gets a language name in the given language.
  *
  * @param string $language
  * the language code of the desired language name
  *
  * @return string
  * the language name in the given language or null if not available
  */
 public function getLanguageName($language)
 {
     return Intl::getLanguageBundle()->getLanguageName($language, $language, $language);
 }
 /**
  * Builds a bunch of informations in order to build a switcher template
  * for custom needs
  *
  * Will return something like this (let's say current locale is fr :
  *
  * current_route: hello_route
  * current_locale: fr
  * locales:
  *   en:
  *     link: http://app_dev.php/en/... or http://app_dev.php?_locale=en
  *     locale: en
  *     locale_target_language: English
  *     locale_current_language: Anglais
  *
  * @param string|null $targetRoute The target route
  * @param array       $parameters  Parameters
  *
  * @return array           Informations for the switcher template
  */
 public function getTargetInformations($targetRoute = null, $parameters = array())
 {
     $request = $this->request;
     $router = $this->router;
     $route = $request->attributes->get('_route');
     if (method_exists($router, 'getGenerator')) {
         $generator = $router->getGenerator();
         if ($generator instanceof ConfigurableRequirementsInterface) {
             if (!$generator->isStrictRequirements()) {
                 $strict = false;
             }
         }
     }
     $infos['current_locale'] = $request->getLocale();
     $infos['current_route'] = $route;
     $infos['locales'] = array();
     $parameters = array_merge((array) $request->attributes->get('_route_params'), $request->query->all(), (array) $parameters);
     $targetLocales = $this->allowedLocales;
     foreach ($targetLocales as $locale) {
         $strpos = 0 === strpos($request->getLocale(), $locale);
         if ($this->showCurrentLocale && $strpos || !$strpos) {
             $targetLocaleTargetLang = Intl::getLanguageBundle()->getLanguageName($locale, $locale);
             $targetLocaleCurrentLang = Intl::getLanguageBundle()->getLanguageName($locale, $request->getLocale());
             $parameters['_locale'] = $locale;
             try {
                 if (null !== $targetRoute && "" !== $targetRoute) {
                     $switchRoute = $router->generate($targetRoute, $parameters);
                 } elseif ($this->useController) {
                     $switchRoute = $router->generate('lunetics_locale_switcher', array('_locale' => $locale));
                 } elseif ($route) {
                     $switchRoute = $router->generate($route, $parameters);
                 } else {
                     continue;
                 }
             } catch (RouteNotFoundException $e) {
                 // skip routes for which we cannot generate a url for the given locale
                 continue;
             } catch (InvalidParameterException $e) {
                 // skip routes for which we cannot generate a url for the given locale
                 continue;
             } catch (\Exception $e) {
                 if (isset($strict)) {
                     $generator->setStrictRequirements(false);
                 }
                 throw $e;
             }
             $infos['locales'][$locale] = array('locale_current_language' => $targetLocaleCurrentLang, 'locale_target_language' => $targetLocaleTargetLang, 'link' => $switchRoute, 'locale' => $locale);
         }
     }
     if (isset($strict)) {
         $generator->setStrictRequirements(false);
     }
     return $infos;
 }
Esempio n. 21
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(array('choices' => Intl::getLanguageBundle()->getLanguageNames()));
 }
Esempio n. 22
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefaults(array('choices' => array_flip(Intl::getLanguageBundle()->getLanguageNames()), 'choices_as_values' => true, 'choice_translation_domain' => false));
 }
Esempio n. 23
0
 public function languageFilter($locale)
 {
     return Intl::getLanguageBundle()->getLanguageName($locale);
 }
Esempio n. 24
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function setupLocale(InputInterface $input, OutputInterface $output)
 {
     $localeRepository = $this->get('sylius.repository.locale');
     $localeManager = $this->get('sylius.manager.locale');
     $localeFactory = $this->get('sylius.factory.locale');
     $code = trim($this->getContainer()->getParameter('locale'));
     $name = Intl::getLanguageBundle()->getLanguageName($code);
     $output->writeln(sprintf('Adding <info>%s</info> locale.', $name));
     if (null !== ($existingLocale = $localeRepository->findOneBy(['code' => $code]))) {
         $this->locale = $existingLocale;
         return;
     }
     $locale = $localeFactory->createNew();
     $locale->setCode($code);
     $localeManager->persist($locale);
     $localeManager->flush();
     $this->locale = $locale;
 }
 /**
  * {@inheritdoc}
  */
 public function beforeCreateStub(StubbingContextInterface $context)
 {
     return array('Languages' => Intl::getLanguageBundle()->getLanguageNames('en'), 'Scripts' => Intl::getLanguageBundle()->getScriptNames('en'));
 }
Esempio n. 26
0
 protected function getLanguageCode($languageString)
 {
     // Temporarily save current locale
     $default = \Locale::getDefault();
     // Set locale according to store, retrieve language code
     \Locale::setDefault($this->getStoreLanguage());
     $languages = Intl::getLanguageBundle()->getLanguageNames();
     // Set locale back to default
     \Locale::setDefault($default);
     return array_search($languageString, $languages);
 }
Esempio n. 27
0
 /**
  * @param string $code
  *
  * @return string|null
  */
 private function getLanguageName($code)
 {
     return Intl::getLanguageBundle()->getLanguageName($code);
 }
Esempio n. 28
0
File: sf_intl.php Progetto: yfix/yf
#!/usr/bin/php
<?php 
$config = ['git_urls' => ['https://github.com/symfony/Intl.git' => 'sf_intl/'], 'autoload_config' => ['sf_intl/' => 'Symfony\\Component\\Intl'], 'example' => function () {
    $languages = \Symfony\Component\Intl\Intl::getLanguageBundle()->getLanguageNames();
    var_dump($languages);
}];
if ($return_config) {
    return $config;
}
require_once __DIR__ . '/_yf_autoloader.php';
new yf_autoloader($config);
Esempio n. 29
0
 /**
  * @param string      $code
  * @param string|null $locale
  *
  * @return string
  */
 public function language($code, $locale = null)
 {
     $codes = explode('_', $code);
     $name = Intl::getLanguageBundle()->getLanguageName($codes[0], isset($codes[1]) ? $code[1] : null, $locale ?: $this->localeDetector->getLocale());
     return $name ? $this->fixCharset($name) : '';
 }
Esempio n. 30
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $resolver->setDefaults(array('choices' => Intl::getLanguageBundle()->getLanguageNames()));
 }