laravel-localization icon indicating copy to clipboard operation
laravel-localization copied to clipboard

How to fallback to language code if country code is not in supported locales?

Open erdmenchen opened this issue 6 years ago • 6 comments

I have the following issue (maybe a configuration issue?): I have en defined in the supported locales and default language set to de. useAcceptLanguageHeader is set to true.

When browser requests en-US via Accept-Language-Header, the de locale is set. How to specify, that it should fall back to en if en-US is not available?

erdmenchen avatar Nov 06 '17 12:11 erdmenchen

Did you solve this? So simple thing and I cant figure out how to do it.

Daidalos117 avatar Jun 11 '18 09:06 Daidalos117

Nothing? Noone? So basic funcionality and noone solved this?

Daidalos117 avatar Jun 20 '18 09:06 Daidalos117

Same question here oO I agree, it's the base, should be native ? oO

Nuranto avatar Sep 24 '18 16:09 Nuranto

When browser requests en-US via Accept-Language-Header, the de locale is set. How to specify, that it should fall back to en if en-US is not available?

A browser usually has multiple languages set with different ranking values, so I am not sure if this is a realistic case, that a browser language has en-US as priority and not en at all.

However, adding this functionality to Accept-Language-Header method should't be a problem. Maybe we should make this general rule, whenever a language like xx-yy is requested, check at the end if xx is available. For example, if a browser has en-US(priority 1) and es(priority 0.7) then add en with lowest priority.

iwasherefirst2 avatar Oct 19 '19 10:10 iwasherefirst2

The laravel/framework 7.21.0 implements an App::setFallbackLocale method. This is easier now.

ruanpepe avatar Jul 21 '20 19:07 ruanpepe

@iwasherefirst2 Can you take a look at that pull request? Maybe this is the solution. #731

ruanpepe avatar Jul 23 '20 06:07 ruanpepe