本文整理汇总了PHP中Symfony\Component\Intl\Intl::getLanguageBundle方法的典型用法代码示例。如果您正苦于以下问题:PHP Intl::getLanguageBundle方法的具体用法?PHP Intl::getLanguageBundle怎么用?PHP Intl::getLanguageBundle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Intl\Intl
的用法示例。
在下文中一共展示了Intl::getLanguageBundle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLanguageName
private function getLanguageName($locale = null)
{
if (!$locale) {
$locale = $this->getCurrentLocale();
}
return Intl::getLanguageBundle()->getLanguageName($locale, null, $this->getCurrentLocale());
}
示例2: guard
/**
* @param mixed $value
*
* @throws InvalidLanguageCodeException
*/
protected function guard($value)
{
$languageName = Intl::getLanguageBundle()->getLanguageName($value);
if (null === $languageName) {
throw new InvalidLanguageCodeException($value);
}
}
示例3: buildForm
/**
* {@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);
}]);
}
示例4: loadChoiceList
/**
* {@inheritdoc}
*/
public function loadChoiceList($value = null)
{
if (null !== $this->choiceList) {
return $this->choiceList;
}
return $this->choiceList = new ArrayChoiceList(array_flip(Intl::getLanguageBundle()->getLanguageNames()), $value);
}
示例5: indexAction
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));
}
}
示例6: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'choices' => Intl::getLanguageBundle()->getLanguageNames(),
'choice_translation_domain' => false,
));
}
示例7: getDisplayLanguages
/**
* 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];
}
示例8: execute
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>');
}
示例9: __construct
/**
* Constructor
*/
public function __construct(ProfileService $profileService, DocumentManager $documentManager, TranslatorInterface $translator)
{
$this->dm = $documentManager;
$this->languages = Intl::getLanguageBundle()->getLanguageNames();
$this->profileService = $profileService;
$this->translator = $translator;
}
示例10: validate
/**
* {@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();
}
}
}
示例11: __construct
/**
* @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();
}
示例12: validate
/**
* {@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));
}
}
示例13: retrieveLanguage
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;
}
示例14: getLanguageNames
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;
}
示例15: retrieveInterfaceLanguages
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;
}