umpirsky/i18n-routing-bundle

Internationalized routing with minimal performance cost.

Installs: 4 719

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 4

Forks: 1

Open Issues: 0

Type:symfony-bundle

1.0.0 2023-11-02 13:43 UTC

This package is auto-updated.

Last update: 2024-10-31 00:16:41 UTC


README

i18n routing bundlesymfony upgrade fixertwig gettext extractorwisdomcentipedepermissions handler

UmpirskyI18nRoutingBundle

Internationalized routing with minimal performance cost.

CI

Idea

The idea is to create i18n route for each regular route in the project instead of creating separate route for each locale. On large projects with high number of routes and many locales supported this can lead to explosion of routes and performance issues. With more then 1000 routes and 30+ languages it can be a real problem. With this bundle and prefix strategy there is no performance cost. For prefix_except_default number of routes is doubled, but again, does not depend on number of languages.

Installation

composer require umpirsky/i18n-routing-bundle
<?php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        return [
            // ...
            new Umpirsky\I18nRoutingBundle\UmpirskyI18nRoutingBundle(),
        ];
    }
}

Configuration

umpirsky_i18n_routing:
    default_locale: en
    locales: [en, sr, ru]

Usage

Disabling i18n routing on route level

If you want route not to be localized, you can disable it using i18n option:

foo:
    path: /foo
    options:
        i18n: false

Strategies

There are multiple routing strategies supported.

prefix

This will prefix all urls with given locales:

/en/foo
/sr/foo
/ru/foo

Configuration:

umpirsky_i18n_routing:
    default_locale: en
    locales: [en, sr, ru]
    strategy: prefix

prefix_except_default

This will prefix all urls with given locales except default:

/foo
/sr/foo
/ru/foo

Configuration:

umpirsky_i18n_routing:
    default_locale: en
    locales: [en, sr, ru]
    strategy: prefix_except_default

Example

There is example integration with Symfony Standard Edition.

Inspiration

This bundle is inspired by JMSI18nRoutingBundle and BeSimpleI18nRoutingBundle, but sacrifices the url translation feature for the sake of performance.