Skip to content

qbbr/LocaleConfiguratorBundle

Repository files navigation

LocaleConfiguratorBundle

Simple configuration on locale.

Tests Latest Stable Version Total Downloads License PHP Version Require

Installation

Step 1: Download the Bundle

composer require qbbr/locale-configurator-bundle

Step 2: Enable the Bundle

// config/bundles.php

return [
    // ...
    Qbbr\LocaleConfiguratorBundle\LocaleConfiguratorBundle::class => ['all' => true],
];

Configuration

Config structure

config/locale_configurator/
├── _default.yaml
├── en.yaml
├── ru.yaml
└── ...

logic: config = merge(_default.yaml, locale.yaml)

Parameters by default

u can override it.

parameters:
    qbbr.locale_configurator.config_dir: '%kernel.project_dir%/config/locale_configurator'
    qbbr.locale_configurator.raise_not_found_param_exception: false

Usage

PHP

use Qbbr\LocaleConfiguratorBundle\Configurator\LocaleConfigurator;

class SomeService
{
    private LocaleConfigurator $lc;

    public function __construct(
        LocaleConfigurator $lc
    ) {
        $this->lc = $lc;
    }

    public function something()
    {
        // $this->lc->setLocale('ru');
        $param1 = $this->lc->get('param1');
    }
}

Twig

has lc_has/lc_get fn.

{% if lc_has('param1') %}
    ...
{% endif %}

{% set param1 = lc_get('param1') %}

Tests

./vendor/bin/phpunit Tests/ -v --testdox