Skip to content

Commit

Permalink
Rename package
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjoffroy committed Mar 3, 2018
1 parent 53ddf39 commit 72cdeb2
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 83 deletions.
36 changes: 18 additions & 18 deletions README.md
Expand Up @@ -2,11 +2,11 @@

# A Laravel package to handle localization from your routes

[![Latest Version on Packagist](https://img.shields.io/packagist/v/alexjoffroy/laravel-route-localization.svg?style=flat-square)](https://packagist.org/packages/alexjoffroy/laravel-route-localization)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/alexjoffroy/laravel-localization.svg?style=flat-square)](https://packagist.org/packages/alexjoffroy/laravel-localization)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/travis/alexjoffroy/laravel-route-localization/master.svg?style=flat-square)](https://travis-ci.org/alexjoffroy/laravel-route-localization)
[![Quality Score](https://img.shields.io/scrutinizer/g/alexjoffroy/laravel-route-localization.svg?style=flat-square)](https://scrutinizer-ci.com/g/alexjoffroy/laravel-route-localization)
[![Total Downloads](https://img.shields.io/packagist/dt/alexjoffroy/laravel-route-localization.svg?style=flat-square)](https://packagist.org/packages/alexjoffroy/laravel-route-localization)
[![Build Status](https://img.shields.io/travis/alexjoffroy/laravel-localization/master.svg?style=flat-square)](https://travis-ci.org/alexjoffroy/laravel-localization)
[![Quality Score](https://img.shields.io/scrutinizer/g/alexjoffroy/laravel-localization.svg?style=flat-square)](https://scrutinizer-ci.com/g/alexjoffroy/laravel-localization)
[![Total Downloads](https://img.shields.io/packagist/dt/alexjoffroy/laravel-localization.svg?style=flat-square)](https://packagist.org/packages/alexjoffroy/laravel-localization)

This Laravel package gives you the ability to simply handle localization in your application. It provides a set of helpers so you can basically do stuff like:

Expand All @@ -26,7 +26,7 @@ You can still continue to use Laravel core features such as testing, route cachi
- [Usage](#usage)
- [Register the middleware](#register-the-middleware)
- [Add your routes](#add-your-routes)
- [The RouteLocalization instance](#the-routelocalization-instance)
- [The Localization instance](#the-Localization-instance)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
Expand All @@ -40,20 +40,20 @@ You can still continue to use Laravel core features such as testing, route cachi
You can install the package via composer:

```bash
composer require alexjoffroy/laravel-route-localization
composer require alexjoffroy/laravel-localization
```

This package will automatically register itself.

Optionnaly, you can publish the config file `config/route-localization.php`:
Optionnaly, you can publish the config file `config/localization.php`:

```bash
php artisan vendor:publish --provider="AlexJoffroy\RouteLocalization\RouteLocalizationServiceProvider --tag="config"
php artisan vendor:publish --provider="AlexJoffroy\Localization\LocalizationServiceProvider --tag="config"
```
If you want to customize the [default switch view](#render-switch):
```bash
php artisan vendor:publish --provider="AlexJoffroy\RouteLocalization\RouteLocalizationServiceProvider --tag="views"
php artisan vendor:publish --provider="AlexJoffroy\Localization\LocalizationServiceProvider --tag="views"
```
## Configuration
Expand All @@ -73,7 +73,7 @@ You can list all locales you want to support here.
Each key should be a locale code (en, fr, ...).
The `native` field is the label which will be rendered in the switch view.
`regional_code`, `charset`, and `constants` fields are required to work with [PHP's setlocale](http://php.net/manual/en/function.setlocale.php), which is called in `RouteLocalization::setLocale`. This is useful for stuff like date formatting with Carbon.
`regional_code`, `charset`, and `constants` fields are required to work with [PHP's setlocale](http://php.net/manual/en/function.setlocale.php), which is called in `Localization::setLocale`. This is useful for stuff like date formatting with Carbon.
```php
'supported_locales' => [
Expand Down Expand Up @@ -121,7 +121,7 @@ The easiest way to do that is to register it globally:
protected $middleware = [
// ...
\AlexJoffroy\RouteLocalization\Http\Middlewares\SetLocale::class,
\AlexJoffroy\Localization\Http\Middlewares\SetLocale::class,
];
```
Expand All @@ -147,12 +147,12 @@ According you are supporting `en` and `fr` locales and you defined translations
| GET HEAD | en/about | en.about | App\Http\Controllers\AboutController@index |
| GET HEAD | fr/a-propos | fr.about | App\Http\Controllers\AboutController@index |
### The RouteLocalization instance
### The Localization instance
The `\AlexJoffroy\RouteLocalization\RouteLocalization` class provides a set of methods which could be helpful to use in your app. The object is registered as a singleton and can be accessed from the app container, the `L10n` facade or the `l10n()` helper.
The `\AlexJoffroy\Localization\Localization` class provides a set of methods which could be helpful to use in your app. The object is registered as a singleton and can be accessed from the app container, the `L10n` facade or the `l10n()` helper.
```php
$l10n = app('route-localization');
$l10n = app('localization');
// or
$l10n = L10n::getFacadeRoot();
// or
Expand All @@ -167,7 +167,7 @@ $l10n->getLocale(); // `en`
$l10n->setLocale('fr'); // Set the current locale to `fr`
```
_`RouteLocalization::getLocale` and `RouteLocalization::setLocale` are aliases for `App::getLocale` and `App::setLocale`_
_`Localization::getLocale` and `Localization::setLocale` are aliases for `App::getLocale` and `App::setLocale`_
#### Checks
```php
Expand Down Expand Up @@ -229,7 +229,7 @@ $l10n->currentRoute('fr', false); // `/fr/a-propos`
#### Render switch
This should be called in a Blade view like `{{ l10n()->renderSwitch() }}`. When using a custom view, you can directly access the RouteLocalization instance from `$l10n` variable.
This should be called in a Blade view like `{{ l10n()->renderSwitch() }}`. When using a custom view, you can directly access the Localization instance from `$l10n` variable.
```php
// Default view
Expand All @@ -255,7 +255,7 @@ Custom view example:
#### Facade
The RouteLocalization methods are also available from the `L10n` facade.
The Localization methods are also available from the `L10n` facade.
```php
L10n::getLocale();
Expand All @@ -268,7 +268,7 @@ L10n::currentRoute();
#### Helpers
```php
// Get the RouteLocalization instance
// Get the Localization instance
$l10n = l10n();
// Get the current locale
Expand Down
14 changes: 7 additions & 7 deletions composer.json
@@ -1,16 +1,16 @@
{
"name": "alexjoffroy/laravel-route-localization",
"name": "alexjoffroy/laravel-localization",
"description": "A Laravel package to handle localization with ease",
"keywords": [
"alexjoffroy",
"laravel-route-localization",
"laravel-localization",
"laravel",
"route",
"localization",
"lang",
"php"
],
"homepage": "https://github.com/alexjoffroy/laravel-route-localization",
"homepage": "https://github.com/alexjoffroy/laravel-localization",
"license": "MIT",
"authors": [
{
Expand All @@ -29,12 +29,12 @@
},
"autoload": {
"psr-4": {
"AlexJoffroy\\RouteLocalization\\": "src"
"AlexJoffroy\\Localization\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"AlexJoffroy\\RouteLocalization\\Tests\\": "tests"
"AlexJoffroy\\Localization\\Tests\\": "tests"
}
},
"scripts": {
Expand All @@ -48,10 +48,10 @@
"extra": {
"laravel": {
"providers": [
"AlexJoffroy\\RouteLocalization\\RouteLocalizationServiceProvider"
"AlexJoffroy\\Localization\\LocalizationServiceProvider"
],
"aliases": {
"RouteLocalization": "AlexJoffroy\\RouteLocalization\\Facades\\Localization"
"Localization": "AlexJoffroy\\Localization\\Facades\\Localization"
}
}
}
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/Facades/L10n.php
@@ -1,16 +1,16 @@
<?php

namespace AlexJoffroy\RouteLocalization\Facades;
namespace AlexJoffroy\Localization\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @see \AlexJoffroy\RouteLocalization\RouteLocalization
* @see \AlexJoffroy\Localization\Localization
*/
class L10n extends Facade
{
protected static function getFacadeAccessor(): string
{
return 'route-localization';
return 'localization';
}
}
4 changes: 2 additions & 2 deletions src/Helpers/l10n.php
Expand Up @@ -2,10 +2,10 @@

if (!function_exists('l10n')) {
/**
* @return \AlexJoffroy\RouteLocalization\RouteLocalization
* @return \AlexJoffroy\Localization\Localization
*/
function l10n()
{
return app('route-localization');
return app('localization');
}
}
2 changes: 1 addition & 1 deletion src/Helpers/locale.php
Expand Up @@ -6,7 +6,7 @@
*/
function locale($locale = null)
{
$l10n = app('route-localization');
$l10n = app('localization');
if ($locale) {
return $l10n->setLocale($locale);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/locales.php
Expand Up @@ -6,6 +6,6 @@
*/
function locales()
{
return app('route-localization')->getSupportedLocales();
return app('localization')->getSupportedLocales();
}
}
8 changes: 4 additions & 4 deletions src/Http/Middlewares/SetLocale.php
@@ -1,18 +1,18 @@
<?php

namespace AlexJoffroy\RouteLocalization\Http\Middlewares;
namespace AlexJoffroy\Localization\Http\Middlewares;

use Closure;
use Illuminate\Http\Request;
use AlexJoffroy\RouteLocalization\RouteLocalization;
use AlexJoffroy\Localization\Localization;
use Symfony\Component\HttpFoundation\Response;

class SetLocale
{
/** @var \AlexJoffroy\RouteLocalization\RouteLocalization */
/** @var \AlexJoffroy\Localization\Localization */
protected $localization;

public function __construct(RouteLocalization $localization)
public function __construct(Localization $localization)
{
$this->localization = $localization;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Listeners/AppLocaleUpdated.php
@@ -1,16 +1,16 @@
<?php

namespace AlexJoffroy\RouteLocalization\Listeners;
namespace AlexJoffroy\Localization\Listeners;

use Illuminate\Foundation\Events\LocaleUpdated;
use AlexJoffroy\RouteLocalization\RouteLocalization;
use AlexJoffroy\Localization\Localization;

class AppLocaleUpdated
{
/** @var \AlexJoffroy\RouteLocalization\RouteLocalization */
/** @var \AlexJoffroy\Localization\Localization */
protected $localization;

public function __construct(RouteLocalization $localization)
public function __construct(Localization $localization)
{
$this->localization = $localization;
}
Expand Down
8 changes: 4 additions & 4 deletions src/RouteLocalization.php → src/Localization.php
@@ -1,12 +1,12 @@
<?php

namespace AlexJoffroy\RouteLocalization;
namespace AlexJoffroy\Localization;

use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Illuminate\Contracts\Container\Container;

class RouteLocalization
class Localization
{
/** @var \Illuminate\Contracts\Container\Container */
protected $app;
Expand All @@ -18,7 +18,7 @@ public function __construct(Container $app)

protected function config(string $key)
{
return config("route-localization.$key");
return config("localization.$key");
}

public function getLocale(): string
Expand Down Expand Up @@ -101,7 +101,7 @@ public function currentRoute(string $locale, bool $absolute = true): string
return $url;
}

public function renderSwitch(string $view = 'route-localization::switch', array $data = []): HtmlString
public function renderSwitch(string $view = 'localization::switch', array $data = []): HtmlString
{
return new HtmlString(view($view, array_merge($data, [
'l10n' => $this,
Expand Down
@@ -1,36 +1,36 @@
<?php

namespace AlexJoffroy\RouteLocalization;
namespace AlexJoffroy\Localization;

use Closure;
use Illuminate\Support\ServiceProvider;
use AlexJoffroy\RouteLocalization\RouteLocalization;
use AlexJoffroy\Localization\Localization;
use Illuminate\Foundation\Events\LocaleUpdated;
use AlexJoffroy\RouteLocalization\Listeners\AppLocaleUpdated;
use AlexJoffroy\Localization\Listeners\AppLocaleUpdated;

class RouteLocalizationServiceProvider extends ServiceProvider
class LocalizationServiceProvider extends ServiceProvider
{
public function boot()
{
$this->publishes([
__DIR__ . '/../config/route-localization.php' => config_path('route-localization.php'),
__DIR__ . '/../config/localization.php' => config_path('localization.php'),
], 'config');

$this->publishes([
__DIR__ . '/../resources/views' => base_path('resources/views/vendor/route-localization'),
__DIR__ . '/../resources/views' => base_path('resources/views/vendor/localization'),
], 'views');

$this->loadViewsFrom(__DIR__ . '/../resources/views', 'route-localization');
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'localization');

$this->app->events->listen(LocaleUpdated::class, AppLocaleUpdated::class);
}

public function register()
{
$this->mergeConfigFrom(__DIR__ . '/../config/route-localization.php', 'route-localization');
$this->mergeConfigFrom(__DIR__ . '/../config/localization.php', 'localization');

$this->app->singleton('route-localization', function () {
return new RouteLocalization($this->app);
$this->app->singleton('localization', function () {
return new Localization($this->app);
});

$this->registerHelpers();
Expand Down
8 changes: 4 additions & 4 deletions tests/Facades/L10nTest.php
@@ -1,15 +1,15 @@
<?php

namespace AlexJoffroy\RouteLocalization\Tests\Facades;
namespace AlexJoffroy\Localization\Tests\Facades;

use AlexJoffroy\RouteLocalization\Facades\L10n;
use AlexJoffroy\RouteLocalization\Tests\TestCase;
use AlexJoffroy\Localization\Facades\L10n;
use AlexJoffroy\Localization\Tests\TestCase;

class L10nTest extends TestCase
{
/** @test */
public function it_resolves_to_the_localization_manager_instance()
{
$this->assertEquals(L10n::getFacadeRoot(), app('route-localization'));
$this->assertEquals(L10n::getFacadeRoot(), app('localization'));
}
}
6 changes: 3 additions & 3 deletions tests/Helpers/L10nTest.php
@@ -1,14 +1,14 @@
<?php

namespace AlexJoffroy\RouteLocalization\Tests\Helpers;
namespace AlexJoffroy\Localization\Tests\Helpers;

use AlexJoffroy\RouteLocalization\Tests\TestCase;
use AlexJoffroy\Localization\Tests\TestCase;

class L10nTest extends TestCase
{
/** @test */
public function it_resolves_to_the_localization_manager_instance()
{
$this->assertEquals(l10n(), app('route-localization'));
$this->assertEquals(l10n(), app('localization'));
}
}
4 changes: 2 additions & 2 deletions tests/Helpers/LocaleTest.php
@@ -1,8 +1,8 @@
<?php

namespace AlexJoffroy\RouteLocalization\Tests\Helpers;
namespace AlexJoffroy\Localization\Tests\Helpers;

use AlexJoffroy\RouteLocalization\Tests\TestCase;
use AlexJoffroy\Localization\Tests\TestCase;

class LocaleTest extends TestCase
{
Expand Down

0 comments on commit 72cdeb2

Please sign in to comment.