如何在FreeBSD上设置PHP语言环境?

问题描述 投票:1回答:1

我正在FreeBSD Server 11.3-RELEASE-p7上使用Wordpress 5.2.4安装。在我的网站上,我需要从MySQL数据库中存储的某些日期输出工作日的德语名称。从数据库中检索值并将其转换为工作日名称的过程不会出现问题,对于英语而言。日期本身的格式可以正常使用(从YYYY-MM-DD到DD.MM.YYYY)。

问题

如前所述,我不能更改用于输出工作日姓名的语言。

我尝试过的事情

我已经尝试了从Google搜索中弹出的各种解决方案。包括在“常规”->“设置”中更改了Wordpress-installation的语言设置(无助于c)。这只是我期望使用的一些字符串:

foreach($result_dates as $date){

    setlocale(LC_TIME, 'de_DE.utf8'); //'de_DE@euro', 'de_DE', 'deu_deu', 
    setlocale(LC_ALL, 'de_DE.utf8'); //'de_DE@euro', 'de_DE', 'deu_deu', 

    $day = strftime("%A", strtotime($date->start_date));

    $date_formatted = date("d.m.Y", strtotime($date->start_date));

    echo '

        <div class="row">
            <div class="col-sm-12 col-12">
                <h3> <span id="day-long">' . $day . '</span>, <span id="day-short">' . strftime($date_formatted) . '</span></h3>
            </div>
        </div> ...';
}

使用建议的方法,我运行以下命令,输出混乱:

echo setlocale(LC_ALL, 0); // output: C

...和...

echo setlocale(LC_ALL, NULL); //output: C
$locale_info = localeconv();
print_r($locale_info); //output: Array ( [decimal_point] => . [thousands_sep] => [int_curr_symbol] => [currency_symbol] => [mon_decimal_point] => [mon_thousands_sep] => [positive_sign] => [negative_sign] => [int_frac_digits] => 127 [frac_digits] => 127 [p_cs_precedes] => 127 [p_sep_by_space] => 127 [n_cs_precedes] => 127 [n_sep_by_space] => 127 [p_sign_posn] => 127 [n_sign_posn] => 127 [grouping] => Array ( [0] => 127 ) [mon_grouping] => Array ( [0] => 127 ) ) 

我在寻找什么?

我想要一个简单的工作解决方案,将setlocale()strftime()结合使用。当然,可以使用数组比较和str_replace()进行手动翻译。但我敢肯定,没有这些替代方法也有可能。

php locale freebsd setlocale
1个回答
0
投票

@ nbari的提示将我指向了正确的方向。激活ssh-access并下载腻子后,我在CLI上运行了以下命令:

locale -a

该命令返回所有已安装语言包的列表。预先安装了德语,但不是de_DE.utf8,而是被称为de_DE.UTF8(请注意编码上的大写字母)。这为我解决了。谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.