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

Not found localization

In order to customize the not found pages, this bundle offers an easy way to solve this problem. The only thing that we need to do is create a class that implements BenatEspina\I18nRoutingBundle\Resolver\NotFoundLocaleResolver interface with our custom project logic.

// src/AppBundle/Resolver/MyNotFoundLocaleResolver.php

namespace AppBundle\Resolver;

use BenatEspina\I18nRoutingBundle\Resolver\NotFoundLocaleResolver;
use Symfony\Component\HttpFoundation\Request;

class AwesomeNotFoundLocaleResolver implements NotFoundLocaleResolver
{
    public function generateUrl(Request $request, $locale, $newLocale)
    {
        if ($newLocale === 'en' && strstr($request->getPathInfo(), 'es')) {
            return strtr($request->getUri(), ['/es' => '']);
        } elseif ($newLocale === 'es' && !strstr($request->getPathInfo(), 'es')) {
            return '/es' . $request->getPathInfo();
        } elseif (($newLocale === 'es' && strstr($request->getPathInfo(), 'es'))
            || ($newLocale === 'en' && strstr($request->getPathInfo(), 'en'))
        ) {
            return $request->getPathInfo();
        }
    }

    public function getLocale(Request $request)
    {
        if (strstr($request->getPathInfo(), 'es')) {
            return 'es';
        }

        return 'en';
    }
}

After that, we need to register as a Symfony service tagging with benat_espina_i18n_routing.not_found_locale_resolver.

# app/config/services.yml

services:
    app.resolver.awesome_not_found_locale:
        class: AppBundle\Resolver\AwesomeNotFoundLocaleResolver
        tags:
            -
                name: benat_espina_i18n_routing.not_found_locale_resolver
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