drmlxgmqn18198265 2015-06-01 09:53
浏览 103
已采纳

Gettext示例不适用于Windows 7 - XAMPP

I have the latest XAMPP (3.2.1) with PHP 5.6.8 and gettext enabled. I'm trying to get gettext() working there using a sample I've found on the internet: https://github.com/leftnode/gettext-example , but it is not working.

Other code I've tried (translation.php):

<?php
  session_start();

  $textdomain = "messages";
  $lang = "de_DE";

  echo(putenv("LC_ALL=".$lang)."<br>"); // outputs 1
  setlocale(LC_ALL, $lang);
  echo(bindtextdomain($textdomain, "locale")."<br>"); // successfully outputs the correct path to locale
  textdomain($textdomain);

  echo ((function_exists("_") && function_exists("gettext"))?"gettext loaded
<br>":""); // outputs gettext loaded

  $name = "Vic";
  printf(_("Hello, %s, it is nice to see you today.
"), $name); // outputs original english
?>

translation files - compiled with Poedit 1.8.1 (messages.po)

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR Codegroove.net
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: Codegroove.net Example Translations 0.0.1
"
"Report-Msgid-Bugs-To: vmc@codegroove.net
"
"POT-Creation-Date: 2015-06-01 11:34+0100
"
"PO-Revision-Date: 2015-06-01 11:38+0100
"
"Last-Translator: 
"
"Language-Team: 
"
"Language: de_DE
"
"MIME-Version: 1.0
"
"Content-Type: text/plain; charset=UTF-8
"
"Content-Transfer-Encoding: 8bit
"
"X-Generator: Poedit 1.8.1
"
"X-Poedit-SourceCharset: UTF-8
"
"X-Poedit-KeywordsList: _
"
"X-Poedit-Basepath: ..\\..\\..\\
"
"X-Poedit-SearchPath-0: .
"

#: translation.php:15
msgid "Hello, %s, it is nice to see you today.
"
msgstr "Hallo, %s, es ist schön dich zu sehen heute.
"

File locations

gettext\translation.php
gettext\locale\de_DE\LC_MESSAGES\messages.po
gettext\locale\de_DE\LC_MESSAGES\messages.mo

What else can I try to make the gettext working?

  • 写回答

2条回答 默认 最新

  • dqrnsg6439 2015-06-04 08:54
    关注

    I've found out that the locale is not set correctly although PHP reports it does. There is a bug in PHP that is causing this: https://bugs.php.net/bug.php?id=66265

    As a result gettext always uses system default locale for translations (after creating translations with my system locale it actually works). Related StackOverflow question: Gettext will always use system default locale

    Although the bug is closed and it should somewhat partially work I wasn't able to get it running. Instead I'm now using PHP solution that reads gettext .po files and that works: php-gettext (https://launchpad.net/php-gettext)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示