@@ -65,7 +65,7 @@ class LaravelLocalization
65
65
/**
66
66
* Name of the translation key of the current route, it is used for url translations
67
67
*
68
- * @var array
68
+ * @var array|string
69
69
*/
70
70
protected $ routesNames = array ();
71
71
@@ -254,20 +254,24 @@ public function localizeURL($url = null, $locale = null)
254
254
public function getLocalizedURL ($ locale = null , $ url = null )
255
255
{
256
256
if ($ locale !== false )
257
- {
258
- if (is_null ($ locale ))
259
- {
260
- $ locale = $ this ->getCurrentLocale ();
261
- }
262
- else
263
- {
264
- $ locales = $ this ->getSupportedLocales ();
265
- if (empty ($ locales [$ locale ]))
266
- {
267
- throw new UnsupportedLocaleException ('Locale \'' . $ locale . '\' is not in the list of supported locales. ' );
268
- }
269
- }
270
- }
257
+ {
258
+ if (is_null ($ locale ))
259
+ {
260
+ $ locale = $ this ->getCurrentLocale ();
261
+ }
262
+ else
263
+ {
264
+ $ locales = $ this ->getSupportedLocales ();
265
+ if (empty ($ locales [$ locale ]))
266
+ {
267
+ throw new UnsupportedLocaleException ('Locale \'' . $ locale . '\' is not in the list of supported locales. ' );
268
+ }
269
+ }
270
+ }
271
+ else
272
+ {
273
+ $ locale = $ this ->defaultLocale ;
274
+ }
271
275
272
276
if (is_null ($ url ) || !is_string ($ url ))
273
277
{
@@ -280,20 +284,21 @@ public function getLocalizedURL($locale = null, $url = null)
280
284
$ urlTranslated = $ this ->getURLFromRouteNameTranslated ($ locale );
281
285
if (!$ urlTranslated )
282
286
{
283
- return false ;
287
+ return False ;
284
288
}
285
289
286
290
$ url = parse_url ($ url );
287
291
$ urlTranslated = parse_url ($ urlTranslated );
288
- $ urlTranslated = array_merge ($ url ,$ urlTranslated );
292
+ $ urlTranslated = array_merge ($ url , $ urlTranslated );
289
293
290
294
return $ this ->unparse_url ($ urlTranslated );
291
295
}
292
296
}
293
297
294
298
$ base_path = Request::getBaseUrl ();
295
299
$ parsed_url = parse_url ($ url );
296
- if (empty ($ parsed_url ['path ' ]))
300
+
301
+ if ( !$ parsed_url || empty ($ parsed_url ['path ' ]) )
297
302
{
298
303
$ path = $ parsed_url ['path ' ] = "" ;
299
304
}
@@ -385,7 +390,7 @@ public function getURLFromRouteNameTranslated($locale, $transKeysNames = array()
385
390
{
386
391
if ($ this ->translator ->has ($ transKeyName ,$ locale ))
387
392
{
388
- $ translation = $ this ->translator ->trans ($ transKeyName ,array (), array (), $ locale );
393
+ $ translation = $ this ->translator ->trans ($ transKeyName , [], "" , $ locale );
389
394
$ route = $ route ."/ " .$ translation ;
390
395
391
396
if (is_array ($ attributes ))
@@ -746,9 +751,9 @@ public function transRoute($routeName)
746
751
/**
747
752
* Returns the translation key for a given path
748
753
*
749
- * @param string $path [description]
754
+ * @param string $path Path to get the key translated
750
755
*
751
- * @return string [description]
756
+ * @return string|boolean Key for translation
752
757
*/
753
758
public function getRouteNameFromAPath ($ path )
754
759
{
@@ -759,18 +764,18 @@ public function getRouteNameFromAPath($path)
759
764
}
760
765
$ path = str_replace ('/ ' . $ this ->currentLocale . '/ ' , '' , $ path );
761
766
$ path = trim ($ path ,"/ " );
762
- $ routesNames = array () ;
767
+ $ routesNames = [] ;
763
768
764
769
765
770
foreach ($ this ->translatedRoutes as $ route )
766
771
{
767
772
if ($ this ->translator ->trans ($ route ) == $ path )
768
773
{
769
- $ routesNames [] = $ route ;
774
+ return $ route ;
770
775
}
771
776
}
772
777
773
- return $ routesNames ;
778
+ return False ;
774
779
}
775
780
776
781
0 commit comments