开发者

Strange gettext behaviour with value stored in a variable

开发者 https://www.devze.com 2023-02-08 01:21 出处:网络
I have some code like the following: <?php $subtitle = _(\'Products\'); ?> Later on I output the value of $subtitle

I have some code like the following:

<?php $subtitle = _('Products'); ?>

Later on I output the value of $subtitle

<h2><?php echo $subtitle; ?></h2>

I would have thought that it would output the translated value of Products, but instead it outputs the English value. If I change the section where I output the value to the followi开发者_JS百科ng, it works correctly.

<h2><?php echo _($subtitle); ?></h2>

Can anyone explain why this is happening? I had assumed that the value in $subtitle would be the translated value, but it does not appear to be the case.


I discovered what the problem was, and it was incredibly stupid. On many of the pages, the $subtitle assignment was taking place before the locale was set. I didn't notice because the code where the locale is set is in an included common header file.

0

精彩评论

暂无评论...
验证码 换一张
取 消