Waavi / translation

Better translation management for Laravel
MIT License
360 stars 167 forks source link

Browser's Locale: add Region #169

Open rbayley opened 4 years ago

rbayley commented 4 years ago

Hi,

I noticed TranslationMiddleware detects browser locale with following code at line 86.

$browserLocale = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2);

is it possible to use config/translator variables to also support full HTTP_ACCEPT_LANGUAGE info?

Maybe something like this:

if( config('translator.browserLocale', true) ){

    $browserLocale = $request->server('HTTP_ACCEPT_LANGUAGE');

}else{

    $browserLocale = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2);

}

By setting config data default to true we are supporting backward compatibility, correct?

This way we could choose from getting 'en' or 'en_US'

I havent checked if languageRepository->isValidLocale() requires a two character data.

Anyway, hope this helps improve even better your package.

warm regards