Skip to content

Commit

Permalink
Update on function negotiateLanguage (#389)
Browse files Browse the repository at this point in the history
* Update on function negotiateLanguage

When testing the negotiateLanguage i found out that the browser never found a match, that was because this function was only checking the supportedLocales array keys.
for example, my locale key is "pt" but my browser was negociating "pt-PT".

* Update LanguageNegotiator.php

* Update LanguageNegotiator.php

* Update LanguageNegotiator.php
  • Loading branch information
seltix5 authored and Marc Cámara committed Dec 31, 2016
1 parent b4b9976 commit a51fafa
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Mcamara/LaravelLocalization/LanguageNegotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public function negotiateLanguage()
if (!empty($this->supportedLanguages[$key])) {
return $key;
}

// Search for acceptable locale by 'regional' => 'af_ZA' or 'lang' => 'af-ZA' match.
foreach ( $this->supportedLanguages as $key_supported => $locale ) {
if ( (isset($locale['regional']) && $locale['regional'] == $key) || (isset($locale['lang']) && $locale['lang'] == $key) ) {
return $key_supported;
}
}
}
// If any (i.e. "*") is acceptable, return the first supported format
if (isset($matches['*'])) {
Expand Down

0 comments on commit a51fafa

Please sign in to comment.