Skip to content

Commit

Permalink
Adding localesNavbar() method
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Sep 20, 2015
1 parent 74f9d4a commit 4daf1a0
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 12 deletions.
9 changes: 9 additions & 0 deletions resources/views/navbar.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ul class="navbar-locales">
@foreach($supportedLocales as $key => $locale)
<li class="{{ localization()->getCurrentLocale() == $key ? 'active' : '' }}">
<a href="{{ localization()->getLocalizedURL($key) }}" rel="alternate" hreflang="{{ $key }}">
{{ $locale->native() }}
</a>
</li>
@endforeach
</ul>
12 changes: 12 additions & 0 deletions src/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,16 @@ private function useAcceptLanguageHeader()
{
return (bool) $this->config()->get('localization.accept-language-header', true);
}

/**
* Get locales navigation bar.
*
* @return string
*/
public function localesNavbar()
{
$supportedLocales = $this->supportedLocales->all();

return view('localization::navbar', compact('supportedLocales'))->render();
}
}
50 changes: 38 additions & 12 deletions src/LocalizationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@ public function getBasePath()
| Main Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Boot the package.
*/
public function boot()
{
parent::boot();

$this->publishes([
$this->getConfigFile() => config_path("{$this->package}.php"),
], 'config');
}

/**
* Register the service provider.
*/
Expand All @@ -70,6 +58,17 @@ public function register()
$this->registerLocalization();
}

/**
* Boot the package.
*/
public function boot()
{
parent::boot();

$this->publishConfig();
$this->registerViews();
}

/**
* Get the services provided by the provider.
*
Expand Down Expand Up @@ -100,4 +99,31 @@ private function registerLocalization()
Facades\Localization::class
);
}

/* ------------------------------------------------------------------------------------------------
| Resources
| ------------------------------------------------------------------------------------------------
*/
/**
* Publishes configs.
*/
private function publishConfig()
{
$this->publishes([
$this->getConfigFile() => config_path("{$this->package}.php"),
], 'config');
}

/**
* Register and published Views.
*/
private function registerViews()
{
$viewsPath = $this->getBasePath() . '/resources/views';

$this->loadViewsFrom($viewsPath, $this->package);
$this->publishes([
$viewsPath => base_path('resources/views/vendor/' . $this->package),
], 'views');
}
}
12 changes: 12 additions & 0 deletions tests/LocalizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,18 @@ public function it_can_create_url_from_uri()
);
}

/** @test */
public function it_can_render_locales_navigation_bar()
{
$navbar = localization()->localesNavbar();

$this->assertContains('<ul class="navbar-locales">', $navbar);
$this->assertContains('<li class="active">', $navbar);
$this->assertContains(e('English'), $navbar);
$this->assertContains(e('Español'), $navbar);
$this->assertContains(e('Français'), $navbar);
}

/* ------------------------------------------------------------------------------------------------
| Other Functions
| ------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 4daf1a0

Please sign in to comment.