Twi*_*ere 4 php laravel docker
你好,我的 Laravel 项目使用 docker 运行。但是当我用我的语言设置我的约会时。Laravel 以英文显示结果@php setlocale(LC_ALL, 'fr_FR'); echo strftime("%A %d %B %Y");@endphp
我很确定这个问题是由容器引起的,但我不知道如何解决它。
如果你locale -a在你的主机上输入,你一定会发现类似的东西fr_FR。但在容器中,默认情况下,大多数镜像不会提供法语。
接下来是一个安装法语的最小示例,仅供参考:
测试.php:
<?php setlocale(LC_ALL, 'fr_FR'); echo strftime("%A %d %B %Y");
Run Code Online (Sandbox Code Playgroud)
Dockerfile:
FROM php
COPY test.php /
RUN apt-get update; \
apt-get install -y locales; \
sed -i '/^#.* fr_FR.* /s/^#//' /etc/locale.gen; \
locale-gen
RUN locale -a
RUN php /test.php
Run Code Online (Sandbox Code Playgroud)
执行:
$ docker build -t abc:1 .
Sending build context to Docker daemon 3.072kB
Step 1/5 : FROM php
---> 7a9e4bdd6171
Step 2/5 : COPY test.php /
---> 705d4f7695e4
Step 3/5 : RUN apt-get update; apt-get install -y locales; sed -i '/^#.* fr_FR.* /s/^#//' /etc/locale.gen; locale-gen
---> Running in 1c9d6012e7b9
...
Generating locales (this might take a while)...
Generation complete.
Generating locales (this might take a while)...
fr_FR.ISO-8859-1... done
fr_FR.UTF-8... done
fr_FR.ISO-8859-15@euro... done
Generation complete.
Removing intermediate container 1c9d6012e7b9
---> ff1733e34ad0
Step 4/5 : RUN locale -a
---> Running in bd21cd6c14e8
C
C.UTF-8
POSIX
fr_FR
fr_FR.iso88591
fr_FR.iso885915@euro
fr_FR.utf8
fr_FR@euro
french
Removing intermediate container bd21cd6c14e8
---> 699d9918f95f
Step 5/5 : RUN php /test.php
---> Running in 49316730728c
mardi 22 juin 2021Removing intermediate container 49316730728c
---> c8cc561fd306
Successfully built c8cc561fd306
Successfully tagged abc:1
Run Code Online (Sandbox Code Playgroud)
解释:
fr_FR在 中被注释/etc/locale.gen,我们可以用来sed取消注释。locale-gen生成法语 lang。mardi 22 juin 2021运行 php 文件即可获取。| 归档时间: |
|
| 查看次数: |
692 次 |
| 最近记录: |