2017 © Pedro Peláez
 

project pulsar-navtools

Navtools package

image

syscover/pulsar-navtools

Navtools package

  • Saturday, June 23, 2018
  • by carlospalacin
  • Repository
  • 2 Watchers
  • 0 Stars
  • 112 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 12 % Grown

The README.md

Navtools package to Laravel

Total Downloads Latest Stable Version License, (*1)

Installation

1 - From the command line run, (*2)

composer require syscover/pulsar-navtools

2 - To publish package, you must type on console, (*3)

php artisan vendor:publish --provider="Syscover\Navtools\NavtoolsServiceProvider"

3 - Register middlewares pulsar.navtools on file app/Http/Kernel.php add to routeMiddleware array, (*4)

'pulsar.navtools' => \Syscover\Navtools\Middleware\Navtools::class,

General configuration environment values

Set NAVTOOLS_URL_TYPE options on environment file .env

Set url type for you web, you have three types, lang, country or lang-country, for urls type lang:, (*5)

NAVTOOLS_URL_TYPE=lang

you can work with this urls, (*6)

hrrp://mydomain.com/en/any-page

for urls type country, (*7)

NAVTOOLS_URL_TYPE=country

you can work with this urls, (*8)

hrrp://mydomain.com/us/any-page

for urls type lang-country, (*9)

NAVTOOLS_URL_TYPE=lang-country

you can work with this urls, (*10)

hrrp://mydomain.com/en-us/any-page

Set NAVTOOLS_LANGS options on environment file .env

Set available languages in your web, (*11)

NAVTOOLS_LANGS=en|es

Set NAVTOOLS_COUNTRIES options on environment file .env

Set available countries in your web, (*12)

NAVTOOLS_COUNTRIES=us|gb|es

Set NAVTOOLS_DEFAULT_COUNTRY options on environment file .env

Set default country for your web, (*13)

NAVTOOLS_DEFAULT_COUNTRY=es

Routing with Navtools

On app\Http\routes.php file use this closure to implement routes with translation, (*14)

Route::group(['middleware' => ['pulsar.navtools']], function() {

    // write here your routes

});

Route configuration

You have several url configuration options depends on the chosen NAVTOOLS_URL_TYPE parameter:, (*15)

Write your routes with lang variable, (*16)

Route::group(['middleware' => ['pulsar.navtools']], function() {
    Route::get('/',                         function(){ return view('www.index'); });
    Route::get('{lang}',                  function(){ return view('www.index'); });
    Route::post('{lang}/contact',         ['as'=>'contact',  'uses'=>'FrontEndController@contact']);
});

Or set lang variable on your routes, (*17)

Route::group(['middleware' => ['pulsar.navtools']], function() {
    Route::get('/',                   function(){ return view('www.index'); });

    Route::get('en',                  function(){ return view('www.index'); });
    Route::get('es',                  function(){ return view('www.index'); });

    Route::post('en/contact',         ['as' => 'contact-en',          'uses'=>'FrontEndController@contact']);
    Route::post('es/contacto',        ['as' => 'contact-es',          'uses'=>'FrontEndController@contact']);
});

Or set constant lang but country variable, (*18)

Route::group(['middleware' => ['pulsar.navtools']], function() {
    Route::get('/',                   function(){ return view('www.index'); });

    Route::get('/en-{country}',                  function(){ return view('www.index'); });
    Route::get('/es-{country}',                  function(){ return view('www.index'); });

    Route::post('en-{country}'/contact',         ['as' => 'contact-en',          'uses'=>'FrontEndController@contact']);
    Route::post('es-{country}'/contacto',        ['as' => 'contact-es',          'uses'=>'FrontEndController@contact']);
});

Or use lang and country variables to get language value., (*19)

Route::group(['middleware' => ['pulsar.navtools']], function() {
    Route::get('/',                   function(){ return view('www.index'); });

    Route::get('/{lang}-{country}',                  function(){ return view('www.index'); });

    Route::post('/{lang}-{country}/contact',         ['as' => 'contact-en',          'uses'=>'FrontEndController@contact']);
});

Helper [user_country()]

Get country from user, a simple case, (*20)

user_country(); // get country user

Helper [user_lang()]

Get lang from user, a simple case, (*21)

user_lang(); // get language user

Helper [nt_route()]

To set routes you need to add lang or country parameters depending on NAVTOOLS_URL_TYPE., (*22)

route('routeName', ['lang' => 'en', 'country' => 'us']);

You can use a custom helper nt_route(), this helper inserts automatically variables lang and country, unless you specify these variables., (*23)

nt_route('routeName');

You can use redirect() helper without any trouble, we have extended Laravel core so that redirect()->route() does the same as nt_route()., (*24)

Helper [change_lang()]

You can change the language with change_lang helper, (*25)

change_lang('en');

Helper [change_country()]

You can change the country with change_country helper, (*26)

change_country('us');

Helper [active_route()]

Active route is a helper for to know when any route is active, has this properties: * route:string|array = Route name or array of route names to target * calls:string default:null = If isset this variable, helper will return the indicated string or a boolean * firstOccurrence:float = Check that the first section of the url matches the route, (*27)

A simple case, (*28)

<a class="{{ active_route('home', 'active') }}" href="{{ route('home') }}">HOME</a>

case with multiples routes, (*29)

<a class="{{ active_route(['home', 'home-en', 'home-es'], 'active') }}" href="{{ route('home') }}">HOME</a>

case with nested route, (*30)

<a class="{{ active_route('product', 'active', true) }}" href="{{ route('product-01') }}">PRODUCT</a>

Helper [get_lang_route_name()]

Get the route name of current route in other language, (*31)

<a href="{{ route(get_lang_route_name('en')) }}">Change Lang</a>

Helper [get_lang_route()]

Get the url of current route in other language, (*32)

<a href="{{ get_lang_route('en') }}">Change Lang</a>

License

The Navtools is open-sourced software licensed under the MIT license., (*33)

The Versions

23/06 2018

dev-master

9999999-dev

Navtools package

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

by SYSCOVER SL

laravel language locale set language set country