Git Product home page Git Product logo

Comments (5)

kevinG73 avatar kevinG73 commented on July 24, 2024

Hello @rsereir ,
I don't understand what you mean , where do you want to force 2 chars exactly ?

from apiplatformtranslationbundle.

rsereir avatar rsereir commented on July 24, 2024

@kevinG73 My Accept-Language header is provided by my browser when frontend ( react ) call an api request to my Api Platform API.

This accept language value can be 'fr_FR' but my $locale field have length of 2 chars in my database. So i want to force transformation of fr_FR to fr when ApiPlatformTranslationBundle try to get locale to use

from apiplatformtranslationbundle.

kevinG73 avatar kevinG73 commented on July 24, 2024

@kevinG73 My Accept-Language header is provided by my browser when frontend ( react ) call an api request to my Api Platform API.

This accept language value can be 'fr_FR' but my $locale field have length of 2 chars in my database. So i want to force transformation of fr_FR to fr when ApiPlatformTranslationBundle try to get locale to use

You can create an EventSubscriber like it :

<?php

namespace App\EventSubscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class LocaleSubscriber implements EventSubscriberInterface
{

    public static function getSubscribedEvents(): array
    {
        return [
            KernelEvents::REQUEST => [['onKernelRequest', 20]],
        ];
    }

    public function onKernelRequest(RequestEvent $event)
    {
        $request = $event->getRequest();
        $accept_language = $request->headers->get("Accept-Language");
          if (empty($accept_language)) {
            $lang = "fr";
        }else{
             $lang = substr($accept_language, 0, 2);
        }
        $request->setLocale($lang);
        $request->headers->set('Accept-Language', $lang);
         return;
    }
}

from apiplatformtranslationbundle.

rsereir avatar rsereir commented on July 24, 2024

Is there any other way than to rewrite all the language recovery logic already written in the package ApiPlatformTranslationBundle ?

from apiplatformtranslationbundle.

kevinG73 avatar kevinG73 commented on July 24, 2024

@rsereir
yes but in this case then it is not for me to do , I'm not contributor .
But add this class simply in any folder inside SRC and it's done

from apiplatformtranslationbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.