PHP gettext和vagrant运行ubuntu [英] PHP gettext and vagrant running ubuntu

查看:74
本文介绍了PHP gettext和vagrant运行ubuntu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行Ubuntu的Vagrant设置上获取gettext来翻译我的翻译文件时遇到问题.我的语言环境文件位于这样的目录中……

I'm having a problem getting gettext to translate one of my translation files on my Vagrant setup running Ubuntu. My locale files are in a directory like so...

locales\de_DE\LC_MESSAGES\default.po

我相信翻译文件是可以的,因为我有一个本地版本的xampp指向完全相同的文件,并且工作正常.

I am confident that the translation files are ok as I have a local version of xampp pointing to exactly the same file and it works fine.

我尝试了以下操作,几乎只是想弄清楚发生了什么,因为我花了很长时间研究它

I have tried the following and almost just want to figure out what is going on because I've spent so long looking into it

  • 权限-我可以在网页上输出default.mo文件的内容
  • 在"/etc/locale.gen"中启用了语言环境,运行了"locale-gen"并重新启动了Apache

有什么我可能想念的吗?

Is there anything that I may have missed?

<?php

define('LOCALES_DIR', "../locales");

if (! file_exists(LOCALES_DIR)) {
    exit("Locales not found from here");
}

$content = file_get_contents(LOCALES_DIR . "/de_DE/LC_MESSAGES/default.mo");
if (strlen($content) < 1) {
    exit("File could not be read");
}

$language = "de_DE.UTF-8";
putenv('LANG=' . $language);
setlocale(LC_ALL, $language);

$domain = "default";
bindtextdomain($domain, LOCALES_DIR);
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');

echo _("Sign In");

更新

  • 由于某种原因,它现在间歇性地半工作,在第三次刷新时,它将显示正确的文本.
  • 我的PHP版本略有不同
    • 游民:5.4.42
    • 本地:5.4.7
    • For some reason it is now semi-working intermittently, on the 3rd refresh it will display the correct text.
    • My PHP versions are slightly different
      • vagrant: 5.4.42
      • local: 5.4.7

      推荐答案

      因此,事实证明,按照这里的建议对我有用 https ://stackoverflow.com/a/20602983/682754

      So it turns out that following the suggestion here worked for me https://stackoverflow.com/a/20602983/682754

      sudo service php5-fpm restart
      

      我猜可能是由于以下原因之一造成的:

      I am guessing it may have stemmed from one of the following:

      • 我一直在将语言环境值de_DE.UTF-8切换为不使用连字符,并尝试使用小写字母,我在Ubuntu上注意到它是de_DE.utf8
      • 我还更改了.po和.mo文件的名称

      这篇关于PHP gettext和vagrant运行ubuntu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆