gpt4 book ai didi

php - docker php gettext无法翻译

转载 作者:行者123 更新时间:2023-12-02 19:14:35 28 4
gpt4 key购买 nike

我很想找到一个解决方案,为什么gettext不能翻译。我遵循了多个教程,却不知道为什么它不起作用。语言环境已安装,gettext也已激活,已激活,已加载到php.ini中,但仍无法正常工作。目前,我正在尝试将英语翻译成捷克语。
Docker文件

FROM php:7.4-apache
RUN apt-get update && apt-get install -y zlib1g-dev libicu-dev g++ locales gettext

RUN docker-php-ext-configure intl \
&& docker-php-ext-configure gettext \
&& docker-php-ext-install \
intl \
gettext
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
sed -i -e 's/# cs_CZ.UTF-8 UTF-8/cs_CZ.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV LANGUAGE cs_CZ:en_US:en
ENV LANG en_US.UTF-8
RUN docker-php-ext-install pdo
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-enable intl gettext
RUN a2enmod rewrite
RUN service apache2 restart
RUN apache2ctl restart
EXPOSE 80
语言应正确安装
$ locale -a
C
cs_CZ.utf8
C.UTF-8
en_US.utf8
POSIX
文件结构
index.php

locale

└───cs_CZ.utf8
│ │
│ └───LC_MESSAGES
│ │ messages.mo
│ │ messages.po

└───en_US.utf8
│ │
│ └───LC_MESSAGES
│ │ messages.mo
│ │ messages.po
CS翻译中的messages.po
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-10-05 10:15+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: cs_CZ.utf8\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"

#: index.php:42
msgid "HELLO_WORLD"
msgstr "Ahoj světe"

#: index.php:43
msgid "TEST_TRANSLATION"
msgstr "Testovací překlad"
messages.po是通过msgfmt生成的
index.php
$locale = 'cs_CZ.utf8';
$domain = 'messages';
setlocale(LC_TIME, "");
$results = putenv("LC_ALL=$locale");
if (!$results) {
exit('putenv failed');
}

$results = setlocale(LC_ALL, $locale);
if (!$results) {
exit('setlocale failed: locale function is not available on this platform, or the given local does not exist in this environment');
}

$results = bindtextdomain($domain, "locale/$locale");
echo 'new text domain is set: ' . $results . "\n";

$results = textdomain($domain);
echo 'current message domain is set: ' . $results . "<br>";

echo _("HELLO_WORLD");
echo "<br>";
echo _("TEST_TRANSLATION");
它返回
new text domain is set: /var/www/html/locale/cs_CZ.utf8 current message domain is set: messages
HELLO_WORLD
TEST_TRANSLATION
还有其他方法如何调试gettext吗?我想念什么吗?谢谢!

最佳答案

罪魁祸首是语言,因为debian甚至在LC_ALL之前都会先查找此变量!

putenv("LANGUAGE=$locale");

关于php - docker php gettext无法翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64205724/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com