Is there a way to get the list of available locales in PHP?

前端 未结 7 1810
清酒与你
清酒与你 2020-12-18 20:20

In Java, you can call Locale.getAvailableLocales() to get the list of available locales.

I was expecting an equivalent from the PHP Locale class, but co

相关标签:
7条回答
  • 2020-12-18 21:00

    you normally need only locales that compatible with UTF-8 to use it in html

    thus, the ResourceBundle is useless, but you still can call it like this

    \ResourceBundle::getLocales('')
    

    to be sure how useless it is.

    So, you need to get a list of what supported by your Ubuntu (because Ubuntu is what you need)

        $string           = shell_exec("locale -a|grep .utf8");
        $array            = explode('.utf8' . "\n", $string);
    

    you will get things like en_US, ru_RU, zh_CN - whatever you installed on your ubuntu. Now take one and use it like so

    $locale  = $array[0].'.UTF-8';
    setlocale(LC_MONETARY, $locale);
    

    but you can install more locales on your Ubuntu

    0 讨论(0)
提交回复
热议问题