Skip to content

Commit

Permalink
Merge pull request #39 from onysko/master
Browse files Browse the repository at this point in the history
	Fixed for new i18n functionality
  • Loading branch information
vitalyiegorov committed Apr 6, 2016
2 parents f4f594a + cb9f622 commit 0556d14
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/SamsonLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class SamsonLocale
*/
public static $locales = array();

/** @var bool Flag for leaving default locale as path placeholder */
public static $leaveDefaultLocale = true;

/**
* Проверить текущей значение установленной локали, и если выставлена
* не поддерживаемая локаль - установим локаль по умолчанию
Expand Down Expand Up @@ -155,19 +158,20 @@ public static function current($locale = null)
/**
* Parse URL arguments
* @param array $args Collection of URL arguments
* @param bool $leaveDefaultLocale Leave default locale placeholder
* @return boolean True if current locale has been changed
*/
public static function parseURL(array & $args)
public static function parseURL(array &$args, $leaveDefaultLocale = true)
{
// Iterate defined site locales
foreach (self::$locales as $locale) {
// Search locale string as URL argument
if (($key = array_search($locale, $args)) !== FALSE) {
if (($key = array_search($locale, $args)) === 0) {
// Change current locale
self::current($locale);

// If this is not default locale(empty string) - remove it from URL arguments
if ($locale != self::DEF) {
if ($leaveDefaultLocale || $locale != self::DEF) {
// Remove argument contained locale string
unset($args[$key]);

Expand Down
2 changes: 1 addition & 1 deletion src/shortcuts.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function url_build()
$args = func_get_args();

// If we have current locale set
if (\samson\core\SamsonLocale::current() != \samson\core\SamsonLocale::DEF) {
if (\samson\core\SamsonLocale::$leaveDefaultLocale && \samson\core\SamsonLocale::current() != \samson\core\SamsonLocale::DEF) {
// Add locale as first url parameter
array_unshift($args, \samson\core\SamsonLocale::current());
}
Expand Down

0 comments on commit 0556d14

Please sign in to comment.