@@ -93,26 +93,29 @@ protected function resolveLocalizedRouteName($name, $locale, $currentLocale)
9393 return $ name ;
9494 }
9595
96+ // Normalize the route name by removing any locale prefix.
97+ // We will prepend the applicable locale manually.
98+ $ baseName = $ this ->stripLocaleFromRouteName ($ name );
99+
100+ if ($ baseName === '' ) {
101+ return '' ;
102+ }
103+
96104 // Use the specified or current locale
97105 // as a prefix for the route name.
98106 $ locale = $ locale ?: $ currentLocale ;
107+ $ newName = "{$ locale }. {$ baseName }" ;
108+ $ fallbackLocale = LocaleConfig::getFallbackLocale ();
99109
100- // If the locale is not supported, use a fallback
101- // locale if one is configured.
102- if ( ! LocaleConfig:: isSupportedLocale ( $ locale ) ) {
103- $ locale = LocaleConfig:: getFallbackLocale () ?: $ locale ;
110+ // If the localized route name doesn't exist,
111+ // use a fallback locale if one is configured.
112+ if ( ! Route:: has ( $ newName ) && $ fallbackLocale ) {
113+ $ newName = "{ $ fallbackLocale } . { $ baseName }" ;
104114 }
105115
106- // Normalize the route name by removing any locale prefix.
107- // We will prepend the applicable locale manually.
108- $ baseName = $ this ->stripLocaleFromRouteName ($ name );
109-
110- // If the route has a name (not just the locale prefix)
111- // add the requested locale prefix.
112- $ newName = $ baseName ? "{$ locale }. {$ baseName }" : '' ;
113-
114- // If the new localized route name does not exist, but the unprefixed route name does,
115- // someone is calling "route($name, [], true, $locale)" on a non localized route.
116+ // If the unprefixed route name exists, but the new localized route name doesn't,
117+ // someone may be trying to resolve a localized name in an unsupported locale,
118+ // e.g. "route('en.route', [], true, 'fr')" (where 'fr.route' doesn't exist and 'route' does)
116119 // In that case, resolve the unprefixed route name.
117120 if (Route::has ($ baseName ) && ! Route::has ($ newName )) {
118121 $ newName = $ baseName ;
0 commit comments