Skip to content

Commit

Permalink
Merge pull request #1 from kiberzauras/v2
Browse files Browse the repository at this point in the history
Language list now is json file, to be for dynamic manipulations
  • Loading branch information
grinry committed Aug 25, 2015
2 parents 597161d + c3c04b8 commit 98154a4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 24 deletions.
4 changes: 2 additions & 2 deletions MultiLanguageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ protected function registerUrlGenerator()

$url = new UrlGenerator(
$routes, $app->rebinding(
'request', $this->requestRebinder()
)
'request', $this->requestRebinder()
)
);

$url->setSessionResolver(function () {
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ At first you need to install our package:

composer require "kiberzauras/laravel.multilanguage"

Then you need to create new file under /config/multiLanguage.php with this content:
Then you need to create new file under /config/multilanguage.json with this content:

<?php
return [
'default'=>'en', // Default language, if not found in request
'array'=>['en', 'ru', 'fr', 'lt', 'en_us'] // All available languages for your project goes here
];
{"default":"en","enabled":["en","ru","lt"]}


In /public/index.php file change these lines:

Expand Down
12 changes: 6 additions & 6 deletions Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ class Request extends LaravelRequest
*/
public static function capture()
{
$config_url = config_path() . DIRECTORY_SEPARATOR . 'multiLanguage.php';
$config_url = config_path() . DIRECTORY_SEPARATOR . 'multilanguage.json';
if (file_exists($config_url)) {
$params = require_once $config_url;
$params = json_decode(file_get_contents($config_url));

if (!empty($params['array'])) {
if (!empty($params->enabled)) {
$uri = trim($_SERVER['REQUEST_URI'], '/');
$lang = strstr($uri, '/', true);
if (in_array($lang, $params['array'])) {
if (in_array($lang, $params->enabled)) {
// for accessing /en/page/page
$_SERVER['REQUEST_URI'] = strstr($uri, '/');
define('Language', $lang);
} elseif (in_array($uri, $params['array'])) {
} elseif (in_array($uri, $params->enabled)) {
// for accessing /, /en, and /en/ pages
$_SERVER['REQUEST_URI'] = '/';
define('Language', $uri);
}
}
defined('Language') || define('Language', !empty($params['default']) ? $params['default'] : 'en');
defined('Language') || define('Language', !empty($params->default) ? $params->default : 'en');
}

static::enableHttpMethodParameterOverride();
Expand Down
10 changes: 0 additions & 10 deletions test/config/multiLanguage.php

This file was deleted.

1 change: 1 addition & 0 deletions test/config/multilanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"default":"en","enabled":["en","ru","lt"]}

0 comments on commit 98154a4

Please sign in to comment.