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.

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题