Skip to content

Commit a983923

Browse files
author
mcamara
committed
More fixes to readability, getRouteNameFromAPath returns array
1 parent b2c0bb8 commit a983923

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

phpunit.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
<directory suffix=".php">./tests/</directory>
1616
</testsuite>
1717
</testsuites>
18-
</phpunit>
18+
</phpunit>

src/Mcamara/LaravelLocalization/Facades/LaravelLocalization.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ protected static function getFacadeAccessor()
1414
return 'laravellocalization';
1515
}
1616

17-
}
17+
}

src/Mcamara/LaravelLocalization/LaravelLocalization.php

+26-18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Session;
99
use Cookie;
1010
use App;
11-
use View;
1211
use Config;
1312

1413
class LaravelLocalization
@@ -65,7 +64,7 @@ class LaravelLocalization
6564
/**
6665
* Name of the translation key of the current route, it is used for url translations
6766
*
68-
* @var array|string
67+
* @var array
6968
*/
7069
protected $routesNames = array();
7170

@@ -170,7 +169,7 @@ public function setLocale($locale = null)
170169
* @param boolean $abbr Should languages be abbreviate to their locale codes?
171170
* @param string $customView Which template should the language bar have?
172171
*
173-
* @return string Returns an html view with a language bar
172+
* @return \Illuminate\View\View Returns an html view with a language bar
174173
*
175174
* @deprecated will be removed in v1.0 please see updated readme for details on making your own language bar template.
176175
*/
@@ -344,10 +343,10 @@ public function getLocalizedURL($locale = null, $url = null)
344343
* Returns an URL adapted to the route name and the locale given
345344
*
346345
* @param string $locale Locale to adapt
347-
* @param string $transKeyName Translation key name of the url to adapt
346+
* @param string $transKeysNames Translation key name of the url to adapt
348347
* @param array $attributes Attributes for the route (only needed if transKeyName needs them)
349348
*
350-
* @return string|boolean URL translated
349+
* @return string|false URL translated
351350
*/
352351
public function getURLFromRouteNameTranslated($locale, $transKeysNames = array(), $attributes = array())
353352
{
@@ -718,17 +717,32 @@ public function getTranslatedRoutes()
718717

719718
/**
720719
* Set current route name
721-
* @param string $name current route name
720+
* @param string|array $routeNames current route name
722721
*/
723-
public function setRouteName($name, $add = false)
722+
public function setRouteName($routeNames, $add = false)
724723
{
725724
if ($add)
726725
{
727-
$this->routesNames[] = $name;
726+
if(is_string($routeNames))
727+
{
728+
$this->routesNames[] = $routeNames;
729+
}
730+
else
731+
{
732+
$this->routesNames = array_merge($this->routesNames, $routeNames);
733+
}
728734
}
729735
else
730736
{
731-
$this->routesNames = $name;
737+
if(is_string($routeNames))
738+
{
739+
$this->routesNames = [];
740+
$this->routesNames[] = $routeNames;
741+
}
742+
else
743+
{
744+
$this->routesNames = $routeNames;
745+
}
732746
}
733747
}
734748

@@ -753,7 +767,7 @@ public function transRoute($routeName)
753767
*
754768
* @param string $path Path to get the key translated
755769
*
756-
* @return string|boolean Key for translation
770+
* @return arrays Keys for translation
757771
*/
758772
public function getRouteNameFromAPath($path)
759773
{
@@ -766,16 +780,15 @@ public function getRouteNameFromAPath($path)
766780
$path = trim($path,"/");
767781
$routesNames = [];
768782

769-
770783
foreach ($this->translatedRoutes as $route)
771784
{
772785
if ($this->translator->trans($route) == $path)
773786
{
774-
return $route;
787+
$routesNames[] = $route;
775788
}
776789
}
777790

778-
return False;
791+
return $routesNames;
779792
}
780793

781794

@@ -955,8 +968,3 @@ public function negotiateLanguage()
955968
}
956969

957970
}
958-
959-
class UnsupportedLocaleException extends Exception
960-
{
961-
962-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php namespace Mcamara\LaravelLocalization;
2+
3+
use Exception;
4+
5+
class UnsupportedLocaleException extends Exception
6+
{
7+
8+
}

0 commit comments

Comments
 (0)