docker上的PHP:使用setLocale

我正试图将现有的Apache / PHP站点迁移到docker工人,并与网站本地化有问题。 挖掘代码,问题是setLocale在Docker安装上返回false(并且在现有站点上是true)。 这是一个在现有网站上运行良好并在Docker安装失败的phptesting。

<?php $locale = "fr_FR"; putenv("LC_ALL=$locale"); $ok = setlocale(LC_ALL, $locale); if ($ok) { echo "success"; } else { echo "failure"; } ?> 

这是我的Docker文件:

 FROM php:5-apache RUN apt-get update && apt-get install -y locales && apt-get clean RUN locale-gen fr_FR && locale-gen zh_TW && locale-gen tr_TR && locale-gen ru_R$ RUN docker-php-ext-install gettext RUN a2enmod rewrite && a2enmod headers 

我究竟做错了什么?

—编辑—

PatxiGortázar给了我正确的方向:-)这是固定的docker文件

 FROM php:5-apache RUN apt-get update && apt-get install -y locales && apt-get clean RUN sed -i -e 's/# fr_FR ISO-8859-1/fr_FR ISO-8859-1/' /etc/locale.gen && \ dpkg-reconfigure --frontend=noninteractive locales RUN docker-php-ext-install gettext RUN a2enmod rewrite && a2enmod headers 

如果您需要更多的语言环境,则必须查看容器中的/etc.locale.gen并添加一行

 sed -i -e 's/# locale/locale/' /etc/locale.gen && \ 

对于您需要的每个语言环境(假设#locale是/ ec tc / locale.gen中包含所需语言环境的行的内容)。

您需要重新configuration您的区域设置:

 RUN locale-gen fr_FR.UTF-8 && dpkg-reconfigure locales 

你可能需要(但我不清楚在什么情况下)将LC_ALLLANGUAGE环境variables添加到/etc/environment

 LC_ALL=... LANGUAGE=... 

在Docker的Ubuntu不附带语言环境..我不知道为什么。 您必须将其添加到您的Dockerfile中:

 RUN locale-gen fr_FR.UTF-8 ENV LANG fr_FR.UTF-8 ENV LANGUAGE fr_FR:en ENV LC_ALL fr_FR.UTF-8 

这应该做到这一点。

Interesting Posts