Skip to content

Commit

Permalink
Backwards compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
nurikabe committed Nov 25, 2014
1 parent 9a91f9e commit 7ed018f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ php:
- 5.6

env:
- SYMFONY_VERSION=2.3.*
- SYMFONY_VERSION=2.4.*
- SYMFONY_VERSION=2.5.*
- SYMFONY_VERSION=dev-master
Expand Down
8 changes: 4 additions & 4 deletions Tests/Validator/LocaleValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public function testLanguageIsValid($intlExtension)
$this->getLocaleValidator($intlExtension)->validate('eo', $constraint); // Esperanto
$this->getLocaleValidator($intlExtension)->validate('epo', $constraint);

// Filipino missing from ISO-639-2 support
//$this->getLocaleValidator($intlExtension)->validate('fil', $constraint); // Filipino
// Note that Filipino seems to be missing from ISO-639-2 support in the new Intl component
$this->getLocaleValidator($intlExtension)->validate('fil', $constraint); // Filipino
}

/**
Expand Down Expand Up @@ -117,8 +117,8 @@ public function testLocaleWithIso639_2Valid($intlExtension)

$this->getLocaleValidator($intlExtension)->validate('afr_af', $constraint); // Afrikaans

// Filipino missing from ISO-639-2 support
//$this->getLocaleValidator($intlExtension)->validate('fil_PH', $constraint);
// Note that Filipino seems to be missing from ISO-639-2 support in the new Intl component
$this->getLocaleValidator($intlExtension)->validate('fil_PH', $constraint);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion Twig/Extension/LocaleSwitcherExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ public function renderSwitcher($route = null, $parameters = array(), $template =
$showCurrentLocale = $this->container->getParameter('lunetics_locale.switcher.show_current_locale');
$useController = $this->container->getParameter('lunetics_locale.switcher.use_controller');
$allowedLocales = $this->container->get('lunetics_locale.allowed_locales_provider')->getAllowedLocales();
$request = $this->container->get('request_stack')->getMasterRequest();
// Use the request stack if it exists (Symfony 2.4+); otherwise use the request "service"
// @see http://symfony.com/blog/new-in-symfony-2-4-the-request-stack
$request = $this->container->has('request_stack')
? $this->container->get('request_stack')->getMasterRequest()
: $this->container->get('request')
;
$router = $this->container->get('router');

$infosBuilder = new TargetInformationBuilder($request, $router, $allowedLocales, $showCurrentLocale, $useController);
Expand Down
5 changes: 2 additions & 3 deletions Validator/LocaleValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
*/
namespace Lunetics\LocaleBundle\Validator;

use Symfony\Component\Intl\Locale as SymfonyLocale;
use Symfony\Component\Intl\Intl;
use Symfony\Component\Locale\Locale as SymfonyLocale;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
Expand Down Expand Up @@ -82,7 +81,7 @@ public function validate($locale, Constraint $constraint)
if ($this->intlExtension) {
$primary = SymfonyLocale::getPrimaryLanguage($locale);
$region = SymfonyLocale::getRegion($locale);
$locales = Intl::getLocaleBundle()->getLocales();
$locales = SymfonyLocale::getLocales();

if ((null !== $region && strtolower($primary) != strtolower($region)) && !in_array($locale, $locales) && !in_array($primary, $locales)) {
$this->context->addViolation($constraint->message, array('%string%' => $locale));
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
"minimum-stability": "dev",
"require": {
"php": ">=5.3.2",
"symfony/framework-bundle": ">=2.4",
"symfony/framework-bundle": ">=2.2.2",
"symfony/yaml": "~2.2",
"symfony/locale": "~2.2",
"symfony/validator": "~2.2",
"psr/log": "~1.0"
},
"require-dev": {
"twig/twig": "1.*",
"twig/twig": "1.*",
"ext-intl": "*",
"symfony/form": "~2.2"
},
"suggest": {
"ext-intl": "Needed for displaying the countryname in the locale language"
"ext-intl": "Needed for displaying the country name in the locale language"
},
"autoload": {
"psr-0": { "Lunetics\\LocaleBundle": "" }
Expand Down

0 comments on commit 7ed018f

Please sign in to comment.