- if (preg_match('/([a-z]{2})-?([a-z]{2})?/i', $headerLocale, $matches)) {
- $loc = $matches[1] . (!empty($matches[2]) ? '_' . strtoupper($matches[2]) : '');
- $attempts = array(
- $loc.'.UTF-8', $loc, str_replace('_', '-', $loc).'.UTF-8', str_replace('_', '-', $loc),
- $loc . '_' . strtoupper($loc).'.UTF-8', $loc . '_' . strtoupper($loc),
- $loc . '_' . $loc.'.UTF-8', $loc . '_' . $loc, $loc . '-' . strtoupper($loc).'.UTF-8',
- $loc . '-' . strtoupper($loc), $loc . '-' . $loc.'.UTF-8', $loc . '-' . $loc
- );
+ if (preg_match('/([a-z]{2,3})[-_]?([a-z]{2})?/i', $headerLocale, $matches)) {
+ $first = [strtolower($matches[1]), strtoupper($matches[1])];
+ $separators = ['_', '-'];
+ $encodings = ['utf8', 'UTF-8'];
+ if (!empty($matches[2])) {
+ $second = [strtoupper($matches[2]), strtolower($matches[2])];
+ $attempts = arrays_combination([$first, $separators, $second, ['.'], $encodings]);
+ } else {
+ $attempts = arrays_combination([$first, $separators, $first, ['.'], $encodings]);
+ }