KnpLabs / DoctrineBehaviors

Doctrine2 behavior traits that help handling Blameable, Loggable, Sluggable, SoftDeletable, Uuidable, Timestampable, Translatable, Tree behavior
http://knplabs.com
MIT License
914 stars 294 forks source link

[Translatable] Error when using locale + country code #622

Closed franckgre closed 3 years ago

franckgre commented 3 years ago

I'm writing a project in french (default) and english (India). When configured with the locales : fr(default) and en: My entity has no english translation : I can get it when visiting with _locale=fr or _locale=en but When configured with the locales : fr(default) and en_IN: My entity has no english translation : I can get it when visiting with _locale=fr but there's an error when _locale=en_IN (return null value).

I fix that changing code in knplabs\doctrine-behaviors\src\Provider\LocaleProvider.php > provideCurrentLocale

        $currentLocale = $currentRequest->getLocale();
        if ($currentLocale !== '') {
            return $currentLocale;
        }
to
        $currentLocale = $currentRequest->getLocale();
        if ($currentLocale !== '') {
            return substr($currentLocale,0,2);
        }

It forces only 2 digit for $currentLocale instead of 4

franckgre commented 3 years ago

It was a code error. Everything works well...