Comments (5)
Hello @rsereir ,
I don't understand what you mean , where do you want to force 2 chars exactly ?
from apiplatformtranslationbundle.
@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 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.
Is there any other way than to rewrite all the language recovery logic already written in the package ApiPlatformTranslationBundle ?
from apiplatformtranslationbundle.
@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)
- PUT requests not updating translations, they always INSERT and DELETE all of them HOT 5
- Uncaught Error: Return value of Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable::getTranslations() must implement interface Doctrine\Common\Collections\Collection, null returned HOT 1
- Can't force certain locale HOT 1
- Translations create not working as expected when GraphQl is used HOT 1
- best practice to prevent the user from translating the same word in the same language
- inconsistency of returning types HOT 2
- Error on loading AliceBundleFixtures HOT 1
- The Symfony validator don't with this bundle HOT 1
- validation of the fields of my entity with PUT REQUEST HOT 2
- Loader Load Exception HOT 1
- OrderFilter on translated fields and a certain locale HOT 2
- editing object after increment 'Translation' id
- Automatically add translation when it does not exist HOT 4
- Filter on current locale translations
- support api-platform/core^3.0@rc HOT 1
- unique constraint " name + locale " HOT 2
- Usage question about Api Platforms json-response HOT 1
- New release? HOT 2
- Doctrine/orm 3 support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apiplatformtranslationbundle.