dougan6982 2014-10-01 14:56
浏览 91

Gettext无法正常工作

I'm trying to get gettext to work in a localserver, but it's just not working. It's not giving me any kind of error, it just returns my string in spanish instead of translating it to english.

This is index.php

<html>
<?php
$locale = "en_US";
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "./locale");
bind_textdomain_codeset("messages", 'UTF-8');
textdomain("messages");
?>
<?= _("Volver al Panel") ?>
</htlm>

This is messages.po, located in locale/en_US/LC_MESSAGES/

# 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.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION
"
"Report-Msgid-Bugs-To: 
"
"POT-Creation-Date: 2014-10-01 11:31-0300
"
"PO-Revision-Date: 2014-10-01 11:38-0300
"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>
"
"Language-Team: LANGUAGE <LL@li.org>
"
"MIME-Version: 1.0
"
"Content-Type: text/plain; charset=UTF-8
"
"Content-Transfer-Encoding: 8bit
"
"X-Generator: Poedit 1.5.4
"

#: index.php:10
msgid "Volver al Panel"
msgstr "Back to Panel"

Of course, i also create the messages.mo with "sudo msgfmt messages.po" without a problem.

The thing is it should return "Back to Panel" instead of "Volver al Panel", am i wrong?

  • 写回答

1条回答 默认 最新

  • duanchuang6978 2014-10-01 19:32
    关注

    I figured out what the problem was and could fix it.

    I used the command locale -a and realized I didn't have a locale named en_US installed, but I did have an en_US.utf8 locale, so i switched them both and it worked.

    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)