Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

I18N Routing Bundle Laravel Package

benatespina/i18n-routing-bundle

View on GitHub
Deep Wiki
Context7

Prerequisites

Translations

If you wish to use this bundle, you have to make sure you have translator enabled in your config.

# app/config/config.yml

framework:
    translator: { fallbacks: ["%locale%"] }

For more information about translations, check Symfony documentation

Getting started

Once the bundle has been installed enable it in the AppKernel:

// app/config/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...

        new BenatEspina\I18nRoutingBundle\BenatEspinaI18nRoutingBundle(),
    ];
}

After that, you need to implement the BenatEspina\I18nRoutingBundle\Resolver\ParametersResolver interface with your desired strategy. Keep calm, in other chapters will try to explain this implementation purposes. ;) The following snippet is the minimum code that bundle needs to work.

// src/AppBundle/Resolver/AwesomeParametersResolver.php

namespace AppBundle\Resolver;

use BenatEspina\I18nRoutingBundle\Resolver\ParametersResolver;

class AwesomeParametersResolver implements ParametersResolver
{
    public function resolve($fromLocale, $toLocale, array &$parameters)
    {
        // Do something...*
    }
}

*You can check some information about this class in here or here.

Just created the resolver you need to register as service and tag it like this:

# app/config/services.yml

services:
    app.resolver.my_parameters_resolver:
        class: AppBundle\Resolver\AwesomeParametersResolver
        tags:
            -
                name: benat_espina_i18n_routing.parameters_resolver
                alias: awesome_resolver

With this basic configuration, now, you can use Twig's current_path_translation in an easy way:

{# app/Resources/views/your_favorite_template.html.twig #}

<ul class="language-selector">
    <li>
        <a href="{{ current_path_translation('en') }}">
            {{ 'languages.english'|trans }}
        </a>
    </li>
    <li>
        <a href="{{ current_path_translation('es') }}">
            {{ 'languages.spanish'|trans }}
        </a>
    </li>
</ul>
  • For more information about in memory parameters resolver strategy check this cookbook.
  • For more information about Doctrine ORM parameters resolver strategy check this cookbook.
  • Back to the index.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui