dongtangu6889 2015-08-03 13:12
浏览 114
已采纳

不推荐使用:setlocale():不推荐将语言环境类别名称作为字符串传递。 使用LC_

With the new update of PHP coming out it seems they have removed LC_MESSAGES and either LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, or LC_TIME must be used instead, I have changed my LC_MESSAGES to LC_ALL but am receiving this error:

Deprecated: setlocale(): Passing locale category name as string is deprecated. Use the LC_* -constants instead

Here is my code for reference:

public static function gettext()
{
    //include the libs
    include(Config::get('PATH_LIBS')."streams.php");
    include(Config::get('PATH_LIBS')."gettext.php");

    //define all the language settings
    define('LOCALE', 'en_GB');
    define('SESSION_LOCALE_KEY', 'locale');
    define('DEFAULT_LOCALE', 'en_GB');
    define('LOCALE_REQUEST_PARAM', 'lang');
    define('WEBSITE_DOMAIN', 'messages');

    //check if the language exists
    if(array_key_exists(LOCALE_REQUEST_PARAM, $_REQUEST)):
            $current_locale = $_REQUEST[LOCALE_REQUEST_PARAM];
            $_COOKIE[SESSION_LOCALE_KEY] = $current_locale;
    elseif(array_key_exists(SESSION_LOCALE_KEY, $_COOKIE)):
            $current_locale = $_COOKIE[SESSION_LOCALE_KEY];
    else:
            $current_locale = DEFAULT_LOCALE;
    endif;

    //will eventually stick this all in the model file
    putenv("LC_TIM=en_GB");
    putenv("LC_MESSAGES=$current_locale");
    setlocale('LC_ALL', $current_locale);

    //bind it all 
    bindtextdomain(WEBSITE_DOMAIN, Config::get('PATH_MAIN').'lang/');
    bind_textdomain_codeset(WEBSITE_DOMAIN, 'UTF-8');
    textdomain(WEBSITE_DOMAIN);
}
  • 写回答

1条回答 默认 最新

  • dsjbest2014 2015-08-03 13:51
    关注

    The error says "passing locale category name as string is deprecated". Look what you're doing:

    setlocale('LC_ALL', $current_locale);
    

    You're passing the locale category as string. Use the predefined constants instead:

    setlocale(LC_ALL, $current_locale);
    // Look ma, ^^ no quotes!
    

    And if LC_MESSAGES is missing, this snippet from the manual may be relevant:

    • LC_MESSAGES for system responses (available if PHP was compiled with libintl)

    libintl probably wasn't compiled with your PHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面