0

I know how to get locale in Symfony e.g. $request->getLocale() but I want to get complete locale in the format "locale_region" e.g. "en_US" etc. I currently have the the locale say en, fr, es etc but I want to get complete locale. I need this because I want to translate the Facebook share button which contains code like this //connect.facebook.net/en_US/

Thank you.

rashidkhan
  • 462
  • 8
  • 24

1 Answers1

0

I found the answer here, tweaked it a little and it worked.

This is the function which returns the complete locale.

private function getLocale($lang = "en")
{
    $locs = array();
    exec('locale -a', $locs);
    $locale = 'en_US';

    foreach ($locs as $l)
    {
        $regex = "/$lang\_[A-Z]{2}$/";
        if(preg_match($regex, $l))
        {
            $locale = $l;
            break;
        }
    }

    return $locale;
}
rashidkhan
  • 462
  • 8
  • 24