Closed ruudk closed 4 years ago
It turns out this is related to https://github.com/willdurand/Negotiation/issues/80. That issue is said to be related to https://github.com/willdurand/Negotiation/issues/76 which was opened by me in 2015 🙈
Ahh, it seems that the fix for those issue was merged to 2.x master but was never tagged.
See: https://github.com/willdurand/Negotiation/compare/v2.3.1...2.x
Can we please get a 2.3.2 tag?
$negotiator = new LanguageNegotiator();
$negotiator->getBest('es-es', ['en', 'es-es', 'es']); // es-es
$negotiator->getBest('es-es', ['en', 'es', 'es-es']); // es
How come when I specify a strict locale (es-es) it returns es
? Shouldn't it look for a exact match first, and if that's not the case, use a fallback based on priority?
<?php
declare(strict_types=1);
use Negotiation\LanguageNegotiator;
use Webmozart\Assert\Assert;
include (__DIR__ . '/vendor/autoload.php');
$negotiator = new LanguageNegotiator();
$one = $negotiator->getBest('es-es', ['en;q=0.1', 'es-es;q=0.9', 'es;q=0.5']);
Assert::same('es-es', $one->getNormalizedValue());
$two = $negotiator->getBest('es-es', ['en;q=0.1', 'es;q=0.5', 'es-es;q=0.9', ]);
Assert::same('es-es', $two->getNormalizedValue());
$three = $negotiator->getBest('es', ['en;q=0.1', 'es-es;q=0.9', 'es;q=0.5']);
Assert::same('es', $three->getNormalizedValue());
// Uncaught InvalidArgumentException: Expected a value identical to "es-es". Got: "es"
$four = $negotiator->getBest('es', ['en;q=0.1', 'es;q=0.5', 'es-es;q=0.9', ]);
Assert::same('es', $four->getNormalizedValue());
// Uncaught InvalidArgumentException: Expected a value identical to "es-es". Got: "es"
This project is dead sniff :cry:
Who does the LanguageNegotiator not return
fr-fr
when running the following code?In version 1.x it worked easier, because the
LanguageNegotiator
would always just return the best language based on the input. It gives me difficulty to upgrade to 2.x because I need to supply all possible combinations upfront.Any ideas how to solve this?