-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
44 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<?php | ||
/** | ||
* @author Rytis Grincevicius <[email protected]> | ||
* @link http://www.github.com/kiberzauras/laravel.multilanguage | ||
* @version 2.0.2 | ||
* @license MIT | ||
*/ | ||
namespace Kiberzauras\MultiLanguage; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<?php | ||
/** | ||
* @author Rytis Grincevicius <[email protected]> | ||
* @link http://www.github.com/kiberzauras/laravel.multilanguage | ||
* @version 2.0.2 | ||
* @license MIT | ||
*/ | ||
namespace Kiberzauras\MultiLanguage; | ||
|
@@ -24,22 +26,46 @@ public static function capture() | |
$params = json_decode(file_get_contents($config_url)); | ||
|
||
if (!empty($params->enabled)) { | ||
$uri = trim($_SERVER['REQUEST_URI'], '/'); | ||
$lang = strstr($uri, '/', true); | ||
if (in_array($lang, $params->enabled)) { | ||
// for accessing /en/page/page | ||
$_SERVER['REQUEST_URI'] = strstr($uri, '/'); | ||
define('Language', $lang); | ||
} elseif (in_array($uri, $params->enabled)) { | ||
// for accessing /, /en, and /en/ pages | ||
$_SERVER['REQUEST_URI'] = '/'; | ||
define('Language', $uri); | ||
} | ||
|
||
if (array_key_exists('HTTP_X_ORIGINAL_URL', $_SERVER)) | ||
self::parseServerVars('HTTP_X_ORIGINAL_URL', $params); | ||
|
||
elseif (array_key_exists('HTTP_X_REWRITE_URL', $_SERVER)) | ||
self::parseServerVars('HTTP_X_REWRITE_URL', $params); | ||
|
||
elseif ($_SERVER['UNENCODED_URL'] && $_SERVER['IIS_WasUrlRewritten'] == 1) | ||
self::parseServerVars('UNENCODED_URL', $params); | ||
|
||
elseif ($_SERVER['REQUEST_URI']) | ||
self::parseServerVars('REQUEST_URI', $params); | ||
|
||
elseif ($_SERVER['ORIG_PATH_INFO']) | ||
self::parseServerVars('ORIG_PATH_INFO', $params); | ||
|
||
} | ||
defined('Language') || define('Language', !empty($params->default) ? $params->default : 'en'); | ||
} | ||
|
||
static::enableHttpMethodParameterOverride(); | ||
return static::createFromBase(SymfonyRequest::createFromGlobals()); | ||
} | ||
|
||
/** | ||
* @param $var | ||
* @param $params | ||
*/ | ||
protected static function parseServerVars($var, $params) | ||
{ | ||
$uri = trim($_SERVER[$var], '/'); | ||
$lang = strstr($uri, '/', true); | ||
if (in_array($lang, $params->enabled)) { | ||
// for accessing /en/page/page | ||
$_SERVER[$var] = strstr($uri, '/'); | ||
define('Language', $lang); | ||
} elseif (in_array($uri, $params->enabled)) { | ||
// for accessing /, /en, and /en/ pages | ||
$_SERVER[$var] = '/'; | ||
define('Language', $uri); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<?php | ||
/** | ||
* @author Rytis Grincevicius <[email protected]> | ||
* @link http://www.github.com/kiberzauras/laravel.multilanguage | ||
* @version 2.0.2 | ||
* @license MIT | ||
*/ | ||
namespace Kiberzauras\MultiLanguage; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,12 @@ | |
"description": "Multilanguage support for Laravel 5.1 routes", | ||
"keywords": ["laravel", "multilanguage", "kiberzauras"], | ||
"license": "MIT", | ||
"time": "2015-11-30", | ||
"authors": [ | ||
{ | ||
"name": "Rytis Grincevicius", | ||
"email": "[email protected]" | ||
"email": "[email protected]", | ||
"homepage": "http://www.github.com/kiberzauras/laravel.multilanguage" | ||
} | ||
], | ||
"require": { | ||
|