2017 © Pedro Peláez
 

cakephp-plugin cake-language-switcher

LanguageSwitcher plugin for CakePHP

image

scherersoftware/cake-language-switcher

LanguageSwitcher plugin for CakePHP

  • Monday, July 10, 2017
  • by cleptric
  • Repository
  • 6 Watchers
  • 0 Stars
  • 4,809 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 15 Versions
  • 11 % Grown

The README.md

CakePHP 3 Language Switcher Plugin, (*1)

Build Status License, (*2)

Installation

You can install this plugin into your CakePHP application using composer., (*3)

The recommended way to install composer packages is:, (*4)

composer require scherersoftware/cake-language-switcher

The next step is to load the plugin inside your bootstrap.php:, (*5)

bin/cake plugin load LanguageSwitcher

Add the Middleware to your Application.php:, (*6)

$middleware->push(new \LanguageSwitcher\Middleware\LanguageSwitcherMiddleware());

Optionally, you can pass an array of options to overwrite the default ones:, (*7)

$middleware->push(new \LanguageSwitcher\Middleware\LanguageSwitcherMiddleware([
    'model' => 'Users',
    'field' => 'language',
    'Cookie' => [
        'name' => 'ChoosenLanguage',
        'expires' => '+1 year',
        'domain' => 'foo.bar',
        'canonicalizeLocale' => false
    ],
    'availableLanguages' => [
        'en_US' => 'en_US'
    ]
]));

Add the Helper to your AppView:, (*8)

$this->loadHelper('LanguageSwitcher.LanguageSwitcher');

Optionally, you can pass an array of options:, (*9)

$this->loadHelper('LanguageSwitcher.LanguageSwitcher', [
    'availableLanguages' => [
        'en_US' => 'en_US',
        'de_DE' => 'de_DE'
    ],
    'displayNames' => [
        'en_US' => 'English',
        'de_DE' => 'Deutsch'
    ],
    'imageMapping' => [
        'en_US' => 'United-States',
        'de_DE' => 'Germany'
    ],
    'renderToggleButtonDisplayName' => true,
    'element' => 'LanguageSwitcher.language_switcher'
]);

To use the element:, (*10)

<?= $this->LanguageSwitcher->renderLanguageSwitcher(); ?>

Next, you should migrate your database., (*11)

bin/cake migrations migrate -p LanguageSwitcher

Add the css file located under webroot/css to your layout file!, (*12)

Configuration Usage

Inside your app.php add the following to change configs of the plugin:, (*13)

'LanguageSwitcher' => [
    'model' => 'Users',
    'field' => 'language',
    'Cookie' => [
        'name' => 'ChoosenLanguage',
        'expires' => '+1 year',
        'canonicalizeLocale' => false
    ],
    'availableLanguages' => [
        'en_US'
    ],
    'displayNames' => [
        'en_US' => 'English'
    ],
    'imageMapping' => [
        'en_US' => 'United-States'
    ],
    'renderToggleButtonDisplayName' => true,
    'beforeSaveCallback' => function ($user, $request, $response) {
        $language = 'en_EN';
        $user->language = $language;
    }
]
  • model: The model used in the migration
  • field: The field in the model
  • Cookie: Optionally you can change the cookie name, the expiration date of the cookie and define if the locale should be saved canonicalized.
  • availableLanguages: Add language keys
  • displayNames: Should contain the same keys as availableLanguages. Map language key with its Display Name
  • imageMapping: Should contain the same keys as availableLanguages. Map language key with its flag image name. (For all possible flag names open webroot/img/flags)
  • beforeSaveCallback: Optionally you can override the user entity to set e.g. the language field with a special value
  • renderToggleButtonDisplayName: Optionally you can hide the language name in the dropdown toggle button
  • element: Optionally you can override the element used for rendering the language switcher with your own.

The Versions

10/07 2017

dev-master

9999999-dev

LanguageSwitcher plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

10/07 2017

v1.0.12

1.0.12.0

LanguageSwitcher plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

10/07 2017

dev-feature/add-support-to-load-config-files

dev-feature/add-support-to-load-config-files

LanguageSwitcher plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

28/03 2017

v1.0.11

1.0.11.0

LanguageSwitcher plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

17/03 2017

v1.0.10

1.0.10.0

LanguageSwitcher plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

07/02 2017

v1.0.9

1.0.9.0

LanguageSwitcher plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

10/01 2017

v1.0.8

1.0.8.0

LanguageSwitcher plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

21/12 2016

v1.0.7

1.0.7.0

LanguageSwitcher plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

05/12 2016

v1.0.6

1.0.6.0

LanguageSwitcher plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

02/12 2016

v1.0.5

1.0.5.0

LanguageSwitcher plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

29/11 2016

v1.0.4

1.0.4.0

LanguageSwitcher plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

28/11 2016

v1.0.3

1.0.3.0

LanguageSwitcher plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

28/11 2016

v1.0.2

1.0.2.0

LanguageSwitcher plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

28/11 2016

v1.0.1

1.0.1.0

LanguageSwitcher plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

28/11 2016

v1.0.0

1.0.0.0

LanguageSwitcher plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires