A
A
Anton Shamanov2018-02-23 14:29:37
PHP
Anton Shamanov, 2018-02-23 14:29:37

What is the best order to check locales in setlocale?

Right now I'm using the following code to set the locale:

$locale = 'en_US';
if (!setlocale(LC_ALL, $locale.'.UTF-8', $locale.'.utf-8', $locale.'.UTF8', $locale.'.utf8', $locale)) {
  $lang = preg_replace('!_.*!', '', $locale);
  if (!setlocale(LC_ALL, $lang.'.UTF-8', $lang.'.utf-8', $lang.'.UTF8', $lang.'.utf8', $locale)) {
    // Set current locale
    setlocale(LC_ALL, '');
  }
}

I would like to speed up the process and arrange the locales by popularity.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question