简体   繁体   English

PHP - bindtextdomain 在本地化网站的某些页面上停止工作

[英]PHP - bindtextdomain stops working on certain pages of localised Website

I am hoping someone can help me with this issue.我希望有人可以帮助我解决这个问题。 My website is localised into German, French, Spanish and English.我的网站已本地化为德语、法语、西班牙语和英语。 Everything seems to work correctly but during testing and often sporadic, the localised text does not appear and except the string codes appear.一切似乎都正常工作,但在测试期间并且通常是零星的,本地化文本不会出现,除了字符串代码出现。 The variable $language is been set correctly as the images are language specific and they are always displaying.变量 $language 已正确设置,因为图像是特定于语言的并且它们始终显示。

The code I am using is as follows:我使用的代码如下:

// I18N support information here
putenv("LANG=" . $language); 
setlocale(LC_ALL, $language);

// Set the text domain as "messages"
$domain = "messages";
bindtextdomain($domain, "./locale"); 
bind_textdomain_codeset($domain, 'UTF-8');

textdomain($domain);

The one thing I do seem to notices is this issue only occurs in pages of format: http://example.com/product/product_name.php It always works in pages of format http://example.com/page.php我似乎注意到的一件事是这个问题只发生在格式页面中: http://example.com/product/product_name.php它总是在格式页面中有效 http://example.com/page.php

Can anyone help or even give me details on how I could debug任何人都可以帮助我,甚至可以提供有关如何调试的详细信息

You will need to ensure that your path to bindtextdomain is correct. 您将需要确保您的bindtextdomain路径正确。 I would suggest this in your bootstrap file: 我建议在您的引导文件中:

define('ROOT_PATH', dirname(__FILE__));

and then in your script 然后在您的脚本中

bindtextdomain($domain, ROOT_PATH . '/locale');

This way if you get into a subfolder such as product/product_name.php bindtextdomain will not try to find the locale folder in the product folder. 这样,如果您进入诸如product/product_name.php的子文件夹, bindtextdomain将不会尝试在product文件夹中找到locale文件夹。

Thank you, Nikolaos, I had the same problem, and the solution is to use always absolute path inside 2nd parameter of bindtextdomain谢谢 Nikolaos,我遇到了同样的问题,解决方案是在 bindtextdomain 的第二个参数中始终使用绝对路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM