Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precedence in determiners #2

Closed
dionysiosarvanitis opened this issue May 7, 2016 · 7 comments
Closed

Precedence in determiners #2

dionysiosarvanitis opened this issue May 7, 2016 · 7 comments

Comments

@dionysiosarvanitis
Copy link

It would be nice if we could set a precedence in determiners. Eg. first check for a cookie and if not exists then check for a parameter, then for a session key and finally for a header attribute.

@BenConstable
Copy link
Owner

Thanks for the suggestion, it's something I've thought about actually and I'll try and get it built soon. I'll leave this issue open until then, and would welcome a PR if yourself or anyone else fancies a go.

@shadoWalker89
Copy link

+1

@BenConstable
Copy link
Owner

Hi @dionysiosarvanitis and @shadoWalker89 - I've added this functionality, so check out the updated README:

https://github.com/BenConstable/laravel-localize-middleware#using-multiple-determiners

Let me know what you think! I'll try to release a new version of the package tomorrow, but for now dev-master has the changes.

@BenConstable
Copy link
Owner

FYI, the relevant commit is 7925a09 if you want to have a look at the code.

@BenConstable
Copy link
Owner

BenConstable commented Jun 8, 2016

This functionality is now in place as of v1.2.0.

@dionysiosarvanitis
Copy link
Author

That's great news! Thanks a lot @BenConstable.

I also noticed that header's determineLocale should probably change a little. Since Accept-Language may include some language-range information we can end up with something like da, en-gb;q=0.8, en;q=0.7 for Accept-Language header.

What do you think about this:

public function determineLocale(Request $request)
{
    $header = $request->header($this->header, $this->fallback);

    $accepts = explode(',', $header);

    // Turn en-gb into en
    return  ! isset($accepts[0]) ?: substr($accepts[0], 0, 2);
}

@BenConstable
Copy link
Owner

No worries. Thanks for bringing that to my attention - I've created issue #3 to track this. The code looks like a good start, I'll look at getting an implementation sorted soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants