PHPackages                             hopefeda/cookielize - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. hopefeda/cookielize

AbandonedArchivedLibrary[Localization &amp; i18n](/categories/localization)

hopefeda/cookielize
===================

This package adds changing locale/language functionality to your laravel app using cookies

v1.3(7y ago)014MITPHPPHP &gt;=5.5.0

Since Nov 16Pushed 5y agoCompare

[ Source](https://github.com/curiousyigit/Cookielize)[ Packagist](https://packagist.org/packages/hopefeda/cookielize)[ Docs](https://github.com/hopefeda/Cookielize)[ RSS](/packages/hopefeda-cookielize/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

ABANDONED
=========

[](#abandoned)

This project is abondened and no longer maintained.

Cookielize
==========

[](#cookielize)

This package adds changing locale/language functionality to your laravel app using cookies.

How it works
------------

[](#how-it-works)

When a user visits a "trigger" url, the package sends back a cookie with the requested locale. Then, a middleware checks this cookie and changes the app locale accordingly.

Installation
------------

[](#installation)

Installation is straightforward, setup is similar to every other Laravel Package.

**1. Install via composer**

```
composer require hopefeda/cookielize

```

**2. Define the Service Provider and alias**
**Note:** You can skip this step if you are using laravel 5.5 and above as this package supports "**auto-discovery**".

If you are using Laravel 5.0 - 5.4 then you need to add a provider and alias. Inside of your `config/app.php` define a new service provider.

```
'providers' => [
	//  other providers

	hopefeda\Cookielize\CookielizeServiceProvider::class,
];

```

Then we want to define an alias in the same `config/app.php` file.

```
'aliases' => [
	// other aliases

	'Cookielize' => hopefeda\Cookielize\facades\CookielizeFacade::class,
];

```

**3. Publish Config File**
The config file allows you to override default settings of this package to meet your specific needs. It also allows you to change the supported languages list.

To generate a config file type this command into your terminal:

```
php artisan vendor:publish  --provider=hopefeda\Cookielize\CookielizeServiceProvider

```

This generates a config file at config/cookielize.php.

Usage
-----

[](#usage)

This package is very easy to use. Once installed, when a user visits the "trigger" url(which by default is [www.yourwebsite.com/languages/en](http://www.yourwebsite.com/languages/en), &lt;--where en is the language code.) the application locale for them is set if it is in the supported languages list.

**A few examples:**
 &lt;-- Sets the locale to arabic
 &lt;-- Sets the locale to french

Functions
---------

[](#functions)

**1. LocaleRoute() - Returns a trigger path**
This function is used to generate trigger(locale changer) urls in your views. It uses the "trigger\_path" to do so. Any changes to the "trigger\_path" in the config file will automatically reflect.

```
// Example 1
{{Cookielize::LocaleRoute('en')}} //gives /languages/en

// Example 2
Turkish //gives Turkish

```

**2. LocaleSupported() - Checks if locale is supported, returns a boolean**
This function is used to check if a locale is in the "supported\_languages" list. It returns **true** or **false**.

```
// Example
@if (Cookielize::LocaleSupported('en'))
// do somethinng
@endif

```

**3. SupportedLocales() - Gets an array of supported locales**
This function is used to get a list of supported locales from the "supported\_locales" in the `config/cookielize.php` file.

```
// Example
@foreach(Cookielize::SupportedLocales() as $locale)
	{{$locale}}
@endforeach

// Gives
en
ar

```

**4. CurrentLocale() - Gets the current set app locale**
This function is used to get the current app locale. It is the equivalent of `config('app.locale')`.

```
// Example
{{Cookielize::CurrentLocale()}} //Gives en

```

**Note:** If you want to use the Cookielize functions within your controllers, don't forget to add `use Cookielize;` at the beginning of your controller.

```
// Example
