<commit_before># Yii2 Cookie Language Selector

This is very simple component which adds language switch functionality to your site using cookies mechanism. It's not a widget, it doesn't offers any GUI like [lajax/yii2-language-picker](https://github.com/lajax/yii2-language-picker). This may be useful because every real web-site has your own design and HTML markup. Some of web-sites uses `<select>`, some uses `<ul>` dropdown list with `onclick` event handler which submits hidden POST form. With this component you're free to use any language selection method. You just need a something able to send POST when needed to switch language and add very simple handler of this POST request.

## Installation

Installation is very easy and contains following 5 steps.

### 1. Install component itself

Execute following command in directory of your Yii2 application:
```
composer require gugglegum/yii2-cookie-language-selector
```
(you may need to use `composer.phar` instead of `composer`). This will install the `gugglegum/yii2-cookie-language-selector` component into your application.

### 2. Add component to your config

Go to your frontend's config add component config into `components` section:

```
        'cookieLanguageSelector' => [
            'class' => 'gugglegum\Yii2\Extension\CookieLanguageSelector\Component',
            'defaultLanguage' => 'en-US',
            'validLanguages' => ['en-US', 'ru-RU', 'de-DE'],
        ],
```

The `defaultLanguage` is language used by default before language selection. The `validLanguages` is the list of languages which can be selected. Additionally you may define name of cookie to store language (`cookieName`) and it's expiration period (`cookieExpire`). By default cookie name is "lang" and it's expires after 7776000 seconds (90 days).

### 3. Add component in bootstrap

Your application stores current language in `Yii::$app->language`. So you need to add this component to `bootstrap` section of your frontend's config to init this component at every application start. You should get something like this:

```
    'bootstrap' => ['log', 'cookieLanguageSelector'],
```

The initialization of `cookieLanguageSelector` will just set `Yii::$app->language` to language retrieved from component. Please use long language format like "en-US", not just "en".

### 4. Create POST form on your web-site

You should create HTML form with POST method or ajax with POST to send new language to the server. Your form may contain only `language` parameter. Additionally you may add `redirectTo` parameter with URL your user should be redirected after switching language (usually the same URL where user was before). The names of these parameters (`language` and `redirectTo`) is not predefined, it's completely up to you and they are used only in you handler action described in step 5.<commit_msg>Typofix<commit_after># Yii2 Cookie Language Selector

This is very simple component which adds language switch functionality to your site using cookies mechanism. It's not a widget, it doesn't offers any GUI like [lajax/yii2-language-picker](https://github.com/lajax/yii2-language-picker). This may be useful because every real web-site has your own design and HTML markup. Some of web-sites uses `<select>`, some uses `<ul>` dropdown list with `onclick` event handler which submits hidden POST form. With this component you're free to use any language selection method. You just need a something able to send POST when needed to switch language and add very simple handler of this POST request.

## Installation

Installation is very easy and contains following 5 steps.

### 1. Install component itself

Execute following command in directory of your Yii2 application:
```
composer require gugglegum/yii2-cookie-language-selector
```
(you may need to use `composer.phar` instead of `composer`). This will install the `gugglegum/yii2-cookie-language-selector` component into your application.

### 2. Add component to your config

Go to your frontend's config and add component config into `components` section:

```
        'cookieLanguageSelector' => [
            'class' => 'gugglegum\Yii2\Extension\CookieLanguageSelector\Component',
            'defaultLanguage' => 'en-US',
            'validLanguages' => ['en-US', 'ru-RU', 'de-DE'],
        ],
```

The `defaultLanguage` is language used by default before language selection. The `validLanguages` is the list of languages which can be selected. Additionally you may define name of cookie to store language (`cookieName`) and it's expiration period (`cookieExpire`). By default cookie name is "lang" and it's expires after 7776000 seconds (90 days).

### 3. Add component in bootstrap

Your application stores current language in `Yii::$app->language`. So you need to add this component to `bootstrap` section of your frontend's config to init this component at every application start. You should get something like this:

```
    'bootstrap' => ['log', 'cookieLanguageSelector'],
```

The initialization of `cookieLanguageSelector` will just set `Yii::$app->language` to language retrieved from component. Please use long language format like "en-US", not just "en".

### 4. Create POST form on your web-site

You should create HTML form with POST method or ajax with POST to send new language to the server. Your form may contain only `language` parameter. Additionally you may add `redirectTo` parameter with URL your user should be redirected after switching language (usually the same URL where user was before). The names of these parameters (`language` and `redirectTo`) is not predefined, it's completely up to you and they are used only in you handler action described in step 5.
{'fraction_non_alphanumeric': 0.08073008073008073, 'fraction_numerical': 0.007722007722007722, 'mean_word_length': 4.479807692307692, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3120875', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1384, 'n_words': 746}