Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 7 additions & 27 deletions UrlManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,44 +548,24 @@ protected function matchCode($code)
$language = $code;
$country = null;
}

if (in_array($language . '-*', $this->languages)) {
if ($hasDash) {
// TODO: Make wildcards work with script codes
// like `sr-Latn`
return [$language, strtoupper($country)];
} else {
return [$language, null];
}
} elseif ($hasDash && in_array($language, $this->languages)) {
return [$language, null];
} else {
return [null, null];
}
} else {
$result = $this->languages[$key];
return $hasDash ? explode('-', $result, 2) : [$result, null];
if ($hasDash && in_array($language, $this->languages)) {
return [$language, null];
}
return [null, null];
}

$language = $code;
$country = null;
$parts = explode('-', $code);
if (count($parts) === 2) {
$language = $parts[0];
$country = strtoupper($parts[1]);
}
$result = $this->languages[$key];

if (in_array($code, $this->languages)) {
return [$language, $country];
} elseif (
$country && in_array("$language-$country", $this->languages) ||
in_array("$language-*", $this->languages)
) {
return [$language, $country];
} elseif (in_array($language, $this->languages)) {
return [$language, null];
} else {
return [null, null];
}
return $hasDash ? explode('-', $result, 2) : [$result, null];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, before I dig deeper into this: The code here has seen a couple of iterations so I think there was good reason why it was written that way. At a quick glance your change seems to oversimplify things.

I'd prefer not to touch it as the library has worked reliably for years ("If it ain't broken - don't fix it").

}

/**
Expand Down