lunetics-org / localebundle Goto Github PK
View Code? Open in Web Editor NEWLocale Bundle for symfony
License: MIT License
Locale Bundle for symfony
License: MIT License
the tests are failing on the newer PRs. not sure what changed, because it looks like something in the test setup changed since the last commit on master.
I want to use the bundle with a multisite setup where each site uses different allowed locales. This is currently not possible with the bundle as the allowed locales are stored as a parameter in the container which can't be changed in a request.
I would propose to create a service that would replace the parameter but uses it internally so that I can create my own service with the allowed locales from my site setup.
I can do a PR for this if there is any interest.
Cheers
Uwe
Hi,
i'm quite new to SF 2.1 so i don't know if it's me or a mis-configuration but i can't make the switcher working...
i've added the bundle to my composer.json , updated it, and added it to the appkernel.php
Then i've added to my app/config/config.yml
lunetics_locale:
guessing_order:
- cookie
- router
- browser
allowed_locales: %locales%
cookie:
set_on_detection: true
with the locales defined in parameters.yml..
Then i've added to my layout.twig
{{ locale_switcher('home_lang') }}
and in my routing.yml
home_lang:
pattern: /lang/{_locale}
defaults:
_controller: lunetics_locale.switcher_controller:switchAction
_locale: %locale%
I clear my cookies then launch my homepage... LocalBundle correctly take the lang from my browser, but i'm unable to use the switcher ...
When i click on the " Switch to : French , Dutch.... " ... nothing happend ...
i got redirected to the same page with the same locale...
what did i miss?
Thanks for your help
I have the problem that if I call the route /changeLocale/**
the locale doesn't get changed.
right now in the link switcher the names of the target locales are in the current locale. it would make sense to have them shown in the target language.
f.e. when in en locale, the link to switch to german should be "Deutsch" and not "German".
Trying to set up the LocaleBundle, i got this error page:
The service "lunetics_locale.allowed_locales_provider" has a dependency on a non-existent parameter "lunetics_locale.allowed_locales"
I guess this is not an optional thing, so we should change the configuration to make the option required, right? Or is the allowed_locales_provider only needed if i enable something else and in that sense semi-optional? then we should improve the DI class to detect the problem and give a better explanation of what is wrong.
Hi,
I've an issue with priority of LocaleListener on KernelEvents::Request:
https://github.com/lunetics/LocaleBundle/blob/master/EventListener/LocaleListener.php#L144
ATM, Lunetics locale listener is executed before Symfony LocaleListener. If you use query parameter _locale for guesser query
it'll not work.
We have theses guessers:
If query contains _locale = fr
and route as default _locale = en
. Lunetics Locale Listener will set fr
locale and then, Symfony LocaleListener will set _locale = en
coz it takes _locales
from attributes
I fixed issue by edit priority of Lunetic listener to 12
(instead of 24).
Any thought ? I can make a PR if you think it's a valable issue.
the composer.json in master should have an alias so that people can depend on 2.2.*
instead of dev-master if they want the latest greatest version but not explode when this bundle does a BC breaking major version jump.
something like
"extra": {
"branch-alias": {
"dev-master": "2.2-dev"
}
}
(assuming the current master is the 2.2 version of this bundle)
i havent checked what it would take, but since i have added the LocaleBundle i often get users struggeling with the install just because of the ext/intl requirement. maybe it would be possible to make the Bundle still work but simple require additional configuration of sorts ..
after a composer update with:
"lunetics/locale-bundle": "dev-master",
"lunetics/timezone-bundle": "dev-master"
trying do:
php app/console cache:clear -vvv
i get this error:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
The service "lunetics_locale.topleveldomain_locale_map" has a dependency on a non-existent parameter "lunetics_locale.topleveldomain.topleveldom
ain_locale_map". Did you mean this: "lunetics_locale.topleveldomain.locale_map"?
previously this update i can run the command without errors, not sure is a bug or some new configuration pattern that i have follow about lunetics_locale.topleveldomain.topleveldom
ain_locale_map?
Hi @lunetics,
have you ever used this bundle in combination with https://github.com/schmittjoh/JMSI18nRoutingBundle?
I was wondering which configuration is recommended. I currently have:
lunetics_locale:
allowed_locales: [de, en]
guessing_order:
- query
- router
- cookie
- session
- browser
session:
variable: _locale
It works ok but visiting http://test.com/en/?_locale=de
will set the cookie to de but translate fields in English.
Symfony 2.4 uses a new EventDispatcher, so it requires the change in the listener that changed EventDispatcher
to EventdispatcherInterface
, this seems to only be in master right now, can we get a new release with it?
Any idea why this is happening? I only noticed because sometime it injects _locale= with the wrong locale causing the user to toggle over into another language on the subsequent request.
The only way I can make this bundle work with the latest version of symfony is by changing this line in LocaleListener#onkernelRequest:
$request->setLocale($locale)
to:
$request->attributes->set('_locale', $locale);
Explanation: This bundle's LocaleListener is defined to be triggered before the Symfony LocaleListener. The Symfony LocaleListener resets the request's locale to the value of the request's '_locale' attribute. If that attribute is not set, the default locale will override whatever locale was set by the Lunetics LocaleListener.
Hi @lunetics ,
As discussed in the symfony-cmf sandbox issues, I'll try to make a refactoring of your bundle in order to get the bundle usable for other implementations.
Before I start, I'll explain a little what are my intentions and if you and the cmf owners @dbu and @lsmith77 agree with it, then I'll dive in.
Ok it is for the begin, feel free to add requirements, remarks, tips.
Regards,
Christophe
Background:
The 2.1 branch contains now an upgraded version of the Bundle. The bundle is also working with Symfony-CMF, thanks to the PR of @lsmith77 .
I made a note in the documentation of master to move the master branch to 2.0 named branch and merge the 2.1 into master.
There are still improvements to do like doc, replace all old versions customizations and PSR's but the 2.1 gives already more features.
So, @lunetics @rdohms , as it is your bundle, are you happy to move the currently master branch to 2.0 on August 15 ?
$constraint parameter is missing here
https://github.com/lunetics/LocaleBundle/blob/master/Controller/LocaleController.php#L43
With symfony 2.2 i get the following error.
You cannot create a service ("lunetics_locale.locale_update_listener") of an inactive scope ("request").
i wonder if strict_match should not be true by default. when i configure the allowed locales to be [en, de] but my browser has de_CH as first locale, i end up with "Not allowed to switch to locale de_CH".
if i enable strict_match, things work as expected, even if my browser does not announce just "de" as option.
if i enable strict_mode, i end up with english if i only ask for de_CH but not de, which is not a good behaviour imho.
If {{ locale_switcher() }}
is invoked through a partial controller, it can not get available languages and nothing is displayed.
I think that using a RequestStack
object (in Symfony2.4) instead of a Request
object will prevent this bug.
Look at http://symfony.com/blog/new-in-symfony-2-4-the-request-stack
Hi,
I'm developing a multi-language site. I would like to be able to serve user's the content in their language, without changing the routes, as I don't want the locale parameter in the route.
If I understood correctly, this can be done with your bundle.
However, I haven't been able to get it to work.
These are my settings:
lunetics_locale:
guessing_order:
- cookie
- session
- browser
cookie:
set_on_change: true
allowed_locales:
- en
- sl
The cookie is set to SL (my browser's language). Even If I use the locale switcher, the cookie is still set to SL. It seems like the guessers ignore the order.
Thanks in advance for your help!
EDIT: Nevermind, I already solved it... Added "query" to guessers, and it works :)
Hi,
when onLocaleChange
is dispatched, there is no yet token
$securityContext->getToken(); // returns null
So it's impossible to subscribe to this event to update locale
column in users
table.
I see that this event was dispatched in LocaleController before.
What is the reason of removing it? How to update user entity each time locale is changed?
Hello,
I'm trying to have a localeswitch working.
This is my configuration:
lunetics_locale:
allowed_locales:
- en
- fr
- de
- es
guessing_order:
- query
- session
- cookie
- browser
- router
cookie:
set_on_change: true
Actually, calling /login?_locale=fr update my cookie to fr, and ?_locale=en update my cookie to en. But I think I don't have a setLocale() working as my translation files are here but I don't have any change. In my session, the locale don't change.
Maybe there's a problem with my setup but I don't see where.
Can you give me clues or help me to debug the problem please ?
Regards.
What do you guys think, a Twig extension to display a flag? {{ flag(locale) }} (inspired from ServerGrove\LocaleBundle
In the function guessLocale, RouterLocaleGuesser returns true and finishes search in a cases of not allowed locales:
/**
* Method that guess the locale based on the Router parameters
*
* @param Request $request
*
* @return boolean True if locale is detected, false otherwise
*/
public function guessLocale(Request $request)
{
$localeValidator = $this->metaValidator;
if ($locale = $request->attributes->get('_locale')) {
if ($localeValidator->isAllowed($locale)) {
$this->identifiedLocale = $locale;
}
return true;
}
return false;
}
So, as result, _locale of request is set to not allowed locale
note sure if this is possible, but would be nice to be able to just add the switcher into a menu.
I've noticed one limitation during developing REST API for the project.
Default configuration is:
lunetics_locale:
strict_mode: true
allowed_locales: %conf_locale_available%
guessing_order:
- router
- cookie
- browser
cookie:
set_on_change: true
For the website it completely fine, great job.
But for stateless API I see 2 issues:
Most preferable way would be to conditionally disable listener for specific routes or so, and use guesser manually, eg QueryLocaleGuesser
, to fetch locale regarding to API specs.
When I use this bundle in dev
env, I have the following error: Catchable fatal error: Argument 1 passed to Lunetics\\LocaleBundle\\EventListener\\LocaleListener::setEventDispatcher() must be an instance of Symfony\\Component\\EventDispatcher\\EventDispatcher, instance of Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher given
.
The error can be solved by changing some function definitions:
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
…
public function setEventDispatcher(EventDispatcherInterface $dispatcher)
…
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
…
public function __construct(LocaleCookie $localeCookie,
LocaleSession $session,
EventDispatcherInterface $dispatcher,
$registeredGuessers = array(),
LoggerInterface $logger = null)
…
Hello,
I have a problem like this:
I have the routes set this way:
index_not_localized:
path: /
defaults: { _controller: "AcmeSiteBundle:Default:index", _locale: %locale% }
acme_site:
resource: "@AcmeSiteBundle/Controller/"
type: annotation
prefix: /{_locale}/
defaults: { _locale: %locale% }
requirements:
_locale: en|it
if I go to www.example.com is set to the default local and not that of the user.
I have configured this way:
guessing_order:
- query
- router
- session
- cookie
- browser
But if imposed as this configuration:
guessing_order:
- session
- cookie
- browser
- query
- router
even if switch to another language does not change the value of the session and cookies.
Is there a problem, or I'm wrong configuration?
How can I get what I want?
thanks
I guess you changed the parameter 'strict_mode' to 'strict_match' in your recent update. It gives me an error in the Dependency Injection process.
I fixed it by changing 'strict_mode' to 'strict_match'.
Using version 2.2.3 throws upon CLI clear:cache
the following error:
[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
The service "lunetics_locale.locale_listener" has a dependency on a non-existent service "lunetics_locale.best_locale_matcher".
Anything I missed there?
MetaValidator should expect Symfony\Component\Validator\ValidatorInterface instead of Symfony\Component\Validator\Validator to be compatible with symfony 2.5. (as any other places where we expect a ValidatorInterface)
I'm trying to use this bundle to identify a country (Belgium), which has lots of locales (fr_BE
, wa_BE
, nl_BE
).
Instead of having to add all the allowed locales, isn't it possible to add only the country (BE
) to match all of these ?
If I'm not mistaking, with non-strict mode, it works only the other way (nl
to match nl_NL
and nl_BE
).
I think the RouterLocaleGuesser is missing a validation against the allowed locales. It's possible for switch to any language. e.g.
allowed_locales:
- en
- nl
- de
guessing_order:
- router
- browser
- cookie
allows to set ?_locale=fr
I have a custom 404 page which also shows the language switcher. On this page there are no entries in the switcher, is there a setting I'm missing? I would like to be able to translate this page too.
right now the LocaleListener skips subrequests. i think this does not make sense since otherwise there is no way to propagate the locale in a subrequest (f.e. via a query parameter).
the check was introduced in 54b46dd
I think there's some code missing to "force" overwrite the cookie set from the cookieguesser. I can't manually change the locale via the controller.
InvalidConfigurationException: Unrecognized options "set_on_detection" under "lunetics_locale.cookie"
in C:\wamp\www\map2uwebgis\vendor\symfony\symfony\src\Symfony\Component\Config\Definition\ArrayNode.php line 316
at ArrayNode->normalizeValue(array('set_on_detection' => true)) in C:\wamp\www\map2uwebgis\vendor\symfony\symfony\src\Symfony\Component\Config\Definition\BaseNode.php line 268
at BaseNode->normalize(array('set_on_detection' => true)) in C:\wamp\www\map2uwebgis\vendor\symfony\symfony\src\Symfony\Component\Config\Definition\ArrayNode.php line 308
at ArrayNode->normalizeValue(array('allowed_locales' => array('en', 'zh_CN'), 'guessing_order' => array('cookie', 'router', 'browser'), 'cookie' => array('set_on_detection' => true))) in C:\wamp\www\map2uwebgis\vendor\symfony\symfony\src\Symfony\Component\Config\Definition\BaseNode.php line 268
at BaseNode->normalize(array('allowed_locales' => array('en', 'zh_CN'), 'guessing_order' => array('cookie', 'router', 'browser'), 'cookie' => array('set_on_detection' => true))) in C:\wamp\www\map2uwebgis\vendor\symfony\symfony\src\Symfony\Component\Config\Definition\Processor.php line 33
at Processor->process(object(ArrayNode), array(array('allowed_locales' => array('en', 'zh_CN'), 'guessing_order' => array('cookie', 'router', 'browser'), 'cookie' => array('set_on_detection' => true)))) in C:\wamp\www\map2uwebgis\vendor\symfony\symfony\src\Symfony\Component\Config\Definition\Processor.php line 50
at Processor->processConfiguration(object(Configuration), array(array('allowed_locales' => array('en', 'zh_CN'), 'guessing_order' => array('cookie', 'router', 'browser'), 'cookie' => array('set_on_detection' => true)))) in C:\wamp\www\map2uwebgis\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Extension\Extension.php line 107
at Extension->processConfiguration(object(Configuration), array(array('allowed_locales' => array('en', 'zh_CN'), 'guessing_order' => array('cookie', 'router', 'browser'), 'cookie' => array('set_on_detection' => true)))) in C:\wamp\www\map2uwebgis\vendor\lunetics\locale-bundle\Lunetics\LocaleBundle\DependencyInjection\LuneticsLocaleExtension.php line 31
at LuneticsLocaleExtension->load(array(array('allowed_locales' => array('en', 'zh_CN'), 'guessing_order' => array('cookie', 'router', 'browser'), 'cookie' => array('set_on_detection' => true))), object(ContainerBuilder)) in C:\wamp\www\map2uwebgis\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass.php line 50
at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in C:\wamp\www\map2uwebgis\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass.php line 39
at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in C:\wamp\www\map2uwebgis\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\Compiler.php line 119
at Compiler->compile(object(ContainerBuilder)) in C:\wamp\www\map2uwebgis\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ContainerBuilder.php line 553
at ContainerBuilder->compile() in C:\wamp\www\map2uwebgis\app\bootstrap.php.cache line 657
at Kernel->buildContainer() in C:\wamp\www\map2uwebgis\app\bootstrap.php.cache line 593
at Kernel->initializeContainer() in C:\wamp\www\map2uwebgis\app\bootstrap.php.cache line 378
at Kernel->boot() in C:\wamp\www\map2uwebgis\app\bootstrap.php.cache line 409
at Kernel->handle(object(Request)) in C:\wamp\www\map2uwebgis\web\app_dev.php line 26
we could also render the locale list depending on the accept language specification
example:
Accept-language', 'fr-FR,fr;q=0.1,en-US;q=0.6,en;q=0.4
and allowed locales:
allowed_locales:
- en
- de
- fr
output of the switcher list:
is there a way to have the language chooser show the current locale and give that part a css class to have it highlight?
Here's my scenario: in an application, I'm loading templates asynchronously, in one case i'm rendering a FOSUserBundle login form in a view script.
In all cases but this, the locale is detected correctly, but for the login form, the onKernelRequest method in the LocaleListener is returned from before setting the default locale with the message 'Request is not a "MASTER_REQUEST" : SKIPPING...'
In my scenario it is not desirable to disallow setting the default locale on sub requests. So it would be helpful to make this a configurable option.
Hi,
A client wants to have multiple .be domains to differentiate between Dutch and French versions of the website. I see that only SubdomainLocaleGuesser
and TopleveldomainLocaleGuesser
are available.
Would you like me to write a DomainLocaleGuesser
and put it in a PR? Or should I just add it to the project as a custom guesser?
Hi,
This is not an issue in LocaleBundle. It's just a kind request for a simple example on how to configure the controller actor in the locale switcher (I am still fresh to symfony). Actually, I did all the basic configurations & my website is translated automatically. Nevertheless, i was not able to configure the controller actor.
Would please give me the simplest example?
Best regards,
If a forward happens in symfony (2.3 but i think 2.1 as well) the _route
request attribute becomes empty.
That means in some cases (when useController is off which is the default and on does not seem to work right now anyway) after a forward, TargetInformationBuilder will catch a RouteNotFoundException
and the locales array for the locale switcher will be empty.
I think the bundle should be able to at least generate a fallback url in this case. Maybe use the redirect_to_route
config option which in this case seems to be unused?
Or do you suggest anything else to try out?
Hello,
I have a problem like this:
I have the routes set this way:
index_not_localized:
path: /
defaults: { _controller: "AcmeSiteBundle:Default:index", _locale: %locale% }
acme_site:
resource: "@AcmeSiteBundle/Controller/"
type: annotation
prefix: /{_locale}/
defaults: { _locale: %locale% }
requirements:
_locale: en|it
if I go to www.example.com is set to the default local and not that of the user.
I have configured this way:
guessing_order:
- query
- router
- session
- cookie
- browser
But if imposed as this configuration:
guessing_order:
- session
- cookie
- browser
- query
- router
even if switch to another language does not change the value of the session and cookies.
Is there a problem, or I'm wrong configuration?
How can I get what I want?
thanks
Could you extend the documentation with the following.
Saying, we have urls like http://domain.com/{_locale}/dashboard,
what is the right way to impement redirect from
http://domain.com (root) to http://domain.com/{_locale}/someurl, where {_locale} is locale guessed by Lunetics guesseres.
I really lack this explanation in the docs. Guess this is done in routing.yml.
Many thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.