Giter VIP home page Giter VIP logo

localebundle's People

Contributors

artursvonda avatar buiduchoc1992 avatar dbu avatar electricmaxxx avatar emmanuelvella avatar erivello avatar gimler avatar gnat42 avatar goetas avatar hacfi avatar hason avatar ikwattro avatar ivoba avatar kevinarcher avatar kingcrunch avatar lsmith77 avatar lunetics avatar ma27 avatar michaelkaefer avatar mondane avatar morille avatar neilwhitworth avatar pborreli avatar rdohms avatar saidul avatar sbacelic avatar stephpy avatar wjzijderveld avatar wouterj avatar xelaris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

localebundle's Issues

Travis tests failing

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.

RFC: dynamically configure allowed_locales

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

Thanks!

This is not an usual Issue, but a big "Thank You" Issue, which goes out in no particular order to @Kwattro , @lsmith77, @gimler, @rdohms, @dbu for their work on the Bundle. Had some "code-off" time and it's just fantastic what you guys did to this Bundle.

Thank You!

Switcher not working....

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

optionally localize the links in the target language

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".

Configuration validation

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.

Priority of LocaleListener

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:

  • query
  • router

If query contains _locale = frand 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

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php#L41

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.

branch alias

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)

make ext/intl dependency optional

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 ..

cache clearing error after updating the bundle (dev-master)

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?

Config for JMSI18nRoutingBundle

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.

Tag 2.2.2

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?

_locale injected into hinclude calls

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.

LocaleListener not working

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.

Refactoring for other implementations

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.

  1. As previously said, it would be useful to have user configurable priorities for the bundle. So I think the bundle entry point has to be the class that manage the prioritization and handles the different detector classes (browser, url, ...)
  2. Make all the detector classes overwritable via the config so that if developers want to use their own detection logic they can
  3. I'm hesitating of the use of the $request->hasPreviousSession() to skip the locale detection behavior ? What do you think?
  4. Do not force users to enter the availableLanguage in the config, if it is empty we can always fallback on the default locale that will be used as only availableLanguage.

Ok it is for the begin, feel free to add requirements, remarks, tips.

Regards,

Christophe

make the 2.1 branch the MASTER branch

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 ?

/cc @dbu @lsmith77

Symfony 2.2 request scope error

With symfony 2.2 i get the following error.

You cannot create a service ("lunetics_locale.locale_update_listener") of an inactive scope ("request").

allowed locales and strict_match

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.

Language switcher not working

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 :)

Token is null when onLocaleChange is dispatched

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?

Problem to get it working with dev-master

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.

Add Flags?

What do you guys think, a Twig extension to display a flag? {{ flag(locale) }} (inspired from ServerGrove\LocaleBundle

RouterLocaleGuesser allows not allowed locales

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

Conditionally disable listener or change guessers

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:

  1. it tries to detect locale which potentially could lead to unexpected behaviour with locale dependent output
  2. sets client cookie with detected locale

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.

Error using dev env

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:

  • In Lunetics\LocaleBundle\EventListener\LocaleListener.php
    use Symfony\Component\EventDispatcher\EventDispatcherInterface;
    …
    public function setEventDispatcher(EventDispatcherInterface $dispatcher)
    …
  • In Lunetics\LocaleBundle\EventListener\LocaleUpdateListener.php
    use Symfony\Component\EventDispatcher\EventDispatcherInterface;
    …
    public function __construct(LocaleCookie $localeCookie,
                                LocaleSession $session,
                                EventDispatcherInterface $dispatcher,
                                $registeredGuessers = array(),
                                LoggerInterface $logger = null)
    …

Locale not intercepted

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

strict_mode parameter issue in the config.yml

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'.

Service not found in 2.2.3

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?

Symfony 2.5 compatibility

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)

allowed locales by country

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).

RouterLocaleGuesser missing validation

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

Empty language switcher on 404 page

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.

subrequest support

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

"lunetics_locale.cookie

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

[switcher] Add option for browser-lang order

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:

  • fr
  • en
  • de

defaultLocale not being set all the time

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.

Adding a DomainLocaleGuesser?

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?

how to configure the controller actor?

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,

Locale switch and forwards

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?

Locale not intercepted

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.