PHPackages                             surda/language-switcher - 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. surda/language-switcher

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

surda/language-switcher
=======================

Language switcher control for Nette Framework

v1.3.1(6y ago)0371MITPHPPHP &gt;=7.1

Since Mar 18Pushed 6y ago1 watchersCompare

[ Source](https://github.com/surda/language-switcher)[ Packagist](https://packagist.org/packages/surda/language-switcher)[ Docs](http://surani.cz)[ RSS](/packages/surda-language-switcher/feed)WikiDiscussions master Synced 2mo ago

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

Language switcher
=================

[](#language-switcher)

---

[![Build Status](https://camo.githubusercontent.com/115792b8e98ef31c84afa04b54d165b0a7982c4433768d89bbf71b06d7351dc9/68747470733a2f2f7472617669732d63692e6f72672f73757264612f6c616e67756167652d73776974636865722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/surda/language-switcher)[![Licence](https://camo.githubusercontent.com/99e1907431ee0d88ee4bf593322a8d5491ac9b0f6cd048a7842be3badecfd1c7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f73757264612f6c616e67756167652d73776974636865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/surda/language-switcher)[![Latest stable](https://camo.githubusercontent.com/1757e877584767477a644100fb10df557b3ee8fd913a6d158668dccddab90c26/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73757264612f6c616e67756167652d73776974636865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/surda/language-switcher)[![PHPStan](https://camo.githubusercontent.com/441b5874ce4df0a2defc892979c96c46889b69cb32119d04f0b48626349f8bc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/phpstan/phpstan)

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

[](#installation)

The recommended way to is via Composer:

```
composer require surda/language-switcher

```

After that you have to register extension in config.neon:

```
extensions:
    languageSwitcher: Surda\LanguageSwitcher\DI\LanguageSwitcherExtension
```

Minimal configuration
---------------------

[](#minimal-configuration)

```
languageSwitcher:
    locales:
        cs: Čeština
        en: English
    default: cs
```

List of all configuration options:

```
languageSwitcher:
    locales:
        cs: Čeština
        en: English
    default: cs
    locale: cs
    useAjax: false
    locale2Country:
        en: us
        cs: cz
    template: path/to/your/latte/file.latte
    # or
    templates:
        default: path/to/your/latte/file.latte
        navbar: path/to/your/latte/navbar.latte
```

Usage
-----

[](#usage)

Inject language switcher + `$locale` persistent property

```
use Nette\Application\UI\Presenter;
use Surda\LanguageSwitcher\TLanguageSwitcher;

class BasePresenter extends Presenter
{
    use TLanguageSwitcher;
}
```

Inject language switcher without `$locale` persistent property

```
use Nette\Application\UI\Presenter;
use Surda\LanguageSwitcher\TLanguageSwitcherWithoutLocaleProperty;

class BasePresenter extends Presenter
{
    use TLanguageSwitcherWithoutLocaleProperty;

    /** @persistent */
    public $locale = 'cs';
}
```

Custom

```
use Nette\Application\UI\Presenter;
use Surda\LanguageSwitcher\LanguageSwitcherFactory;
use Surda\LanguageSwitcher\LanguageSwitcherControl;

class BasePresenter extends Presenter
{
    /** @var LanguageSwitcherFactory */
    private $languageSwitcherFactory;

    /** @persistent */
    public $locale = 'cs';

    public function injectLanguageSwitcherFactory(LanguageSwitcherFactory $LanguageSwitcherFactory)
    {
        $this->languageSwitcherFactory = $LanguageSwitcherFactory;
    }

    /**
    * @return LanguageSwitcherControl
    */
    protected function createComponentLanguageSwitcher(): LanguageSwitcherControl
    {
        $control = $this->languageSwitcherFactory->create();
        $control->setLocale($this->locale);

        $control->onChange[] = function (LanguageSwitcherControl $control, string $locale): void {
            $this->redirect('this', ['locale' => $locale]);
        };

        return $control;
    }
}
```

Template

```
{control languageSwitcher} or {control languageSwitcher default}
```

Set control template by type of template (see config.neon)

```
{control languageSwitcher navbar}
```

Custom component options
------------------------

[](#custom-component-options)

```
class ProductPresenter extends Presenter
{
    /**
    * @return LanguageSwitcherControl
    */
    protected function createComponentLanguageSwitcher(): LanguageSwitcherControl
    {
        // Init items per page component
        $control = $this->languageSwitcherFactory->create();

        // All allowed locales
        $control->setLocales(['cs' => 'Czech', 'en' => 'English']);

        // Default locale
        $control->setDefaultLocale('cs');

        // Current locale
        $control->setLocale('cs');

        // To use your own template (default type)
        $control->setTemplate('path/to/your/latte/file.latte');

        // To use your own template
        $control->setTemplates([
            'default' => 'path/to/your/latte/file.latte',
            'navbar' => 'path/to/your/latte/navbar.latte',
        ]);

        // Enable ajax (defult is disable)
        $control->enableAjax();

        // Disable ajax
        $control->disableAjax();

        return $control;
    }
}
```

Template file `bootstrap4.nav-item.flag.latte` using flags from

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~101 days

Total

3

Last Release

2413d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e8d497ef90ca9ed180419b5ab29857be10e88d0614cf01c94b0f2ab5094de45d?d=identicon)[surda](/maintainers/surda)

---

Top Contributors

[![surda](https://avatars.githubusercontent.com/u/588663?v=4)](https://github.com/surda "surda (10 commits)")

---

Tags

languagenettemultilanguagecontrol

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/surda-language-switcher/health.svg)

```
[![Health](https://phpackages.com/badges/surda-language-switcher/health.svg)](https://phpackages.com/packages/surda-language-switcher)
```

###  Alternatives

[lunetics/locale-bundle

A Bundle for switching Languages

1861.1M8](/packages/lunetics-locale-bundle)[contributte/translation

Symfony/Translation integration for Nette Framework.

771.8M37](/packages/contributte-translation)[kdyby/translation

Integration of Symfony/Translation into Nette Framework

921.2M24](/packages/kdyby-translation)[inpsyde/multilingual-press

Simply THE multisite-based free open source plugin for your multilingual websites.

2414.0k1](/packages/inpsyde-multilingual-press)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
