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

前端 未结 7 1858
清酒与你
清酒与你 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 20:47

    On Windows you can try to call the setlocale() php function with all the items of the following list:
    http://msdn.microsoft.com/en-us/goglobal/bb895996.aspx

    Here is a code sniplet to list all available locales on a Windows based host:

    '."\n";
    echo ''."\n";
    echo '  Languange'."\n";
    echo '  Sub-Languange'."\n";
    echo '  Languange String'."\n";
    echo ''."\n";
    foreach ( $langs as $lang ) {
        echo ''."\n";
        echo '  '.$lang[0].''."\n";
        echo '  '.$lang[1].''."\n";
        $a = array();
        foreach ( $lang[2] as $lang_code ) {
            $loc = setlocale( LC_ALL, $lang_code );
            $a []= $lang_code.' '.( false === $loc ? '✖' : '✔ - '.$loc );
        }
        echo '  '.implode( '
    ', $a ).''."\n"; echo ''."\n"; } echo ''."\n"; // Note: Norvegian (Bokmal) is Norvegian (Bokmål), see: http://en.wikipedia.org/wiki/Bokmål ?>

提交回复
热议问题