t() 不打印翻译后的字符串
我目前尝试通过对所有硬代码字符串使用 t() 来使模块可翻译。由于我只是按照文档中的建议调用 t() ,所以我不知道我可能做错了什么。我调用模块的 block_theme 。
Hook_theme();
如果这很重要,请不要...
/* # Themes {{{*/
function catchy_overview_theme() {
return array(
'catchy_overview_block' => array(
'template' => 'catchy_overview_block',
'arguments' => array('nodes' => null, 'terms' => null, 'imagecache_preset' => imagecache_preset(variable_get("catchy_overview_imagecache_preset", null)))
)
);
}/*}}}*/
catchy_overview_block.tpl.php
<?php
/*
* Catchy Overview Block Template
*
* Defined Vars:
* $nodes All collected nodes grouped by tid
* $terms Taxonomy-Array-Map tid => Name
* $imagecache_preset The configured imagecache preset.
*/
?>
<ul class="catchy-overview">
<?php foreach ($nodes as $key => $value) { ?>
<li class="term term-<?php print $key?>">
<h2><?php print t( $terms[$key] ) ?></h2>
<ul>
<?php foreach ($value as $node) { ?>
<li class="node node-<?php print $node->nid ?>">
<?php
$image = theme_imagecache($imagecache_preset['presetname'], $node->field_photo[0]["filepath"], $node->title, $node->title);
print l($image . "<span>" . $node->title . "</span>", 'node/'.$node->nid, array('html' => true));
?>
</li>
<?php } ?>
</ul>
</li>
<?php } ?>
</ul>
要翻译和打印的术语位于
内,这是我通过 SQL 查询获取的分类术语:
$terms_result = db_query("
SELECT tid, name
FROM {term_data}
WHERE vid = '".variable_get('catchy_overview_vocabulary_id', false)."'
");
我真的希望你能帮助我。如果您需要更多信息,请随时发表评论……我现在很困惑。
I currenty try to make a module translateable by using t() for all Hard-Codes-Strings. Since I simply call t() as advised in the documentation I don't have a clue what I might be doing wrong. I call in the block_theme of my module.
Hook_theme();
Don't if this is important…
/* # Themes {{{*/
function catchy_overview_theme() {
return array(
'catchy_overview_block' => array(
'template' => 'catchy_overview_block',
'arguments' => array('nodes' => null, 'terms' => null, 'imagecache_preset' => imagecache_preset(variable_get("catchy_overview_imagecache_preset", null)))
)
);
}/*}}}*/
catchy_overview_block.tpl.php
<?php
/*
* Catchy Overview Block Template
*
* Defined Vars:
* $nodes All collected nodes grouped by tid
* $terms Taxonomy-Array-Map tid => Name
* $imagecache_preset The configured imagecache preset.
*/
?>
<ul class="catchy-overview">
<?php foreach ($nodes as $key => $value) { ?>
<li class="term term-<?php print $key?>">
<h2><?php print t( $terms[$key] ) ?></h2>
<ul>
<?php foreach ($value as $node) { ?>
<li class="node node-<?php print $node->nid ?>">
<?php
$image = theme_imagecache($imagecache_preset['presetname'], $node->field_photo[0]["filepath"], $node->title, $node->title);
print l($image . "<span>" . $node->title . "</span>", 'node/'.$node->nid, array('html' => true));
?>
</li>
<?php } ?>
</ul>
</li>
<?php } ?>
</ul>
The term to be translated and printed is within the <h2>
which is a Taxonomy-Term I grab with an SQL-Query:
$terms_result = db_query("
SELECT tid, name
FROM {term_data}
WHERE vid = '".variable_get('catchy_overview_vocabulary_id', false)."'
");
I really hope you can help me out. If you need any more information, don't hesitate to comment… I'm quite confused right now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我倾向于怀疑您没有启用区域设置模块,没有启用超过一种语言,或者没有输入该单词的实际翻译。
I'm inclined to suspect you don't have the Locale module enabled, don't have more than one language enabled, or don't have the actual translation entered for the word.
您可以将变量传递给 t() 但传递用户的输入(以避免安全问题)或大量代码生成的字符串(以避免填充数据库或其他内容)是不好的。
如果 t() 不起作用,请尝试注销并查看它是否会起作用?
如果您以管理员身份登录,并且语言设置为英语,并且语言检测优先考虑用户的设置,则即使页面使用其他语言,也可能会因为检测到用户语言英语而发生这种情况。
You can pass variable to t() but it's not good to pass user's input (to avoid security issue) or some great number of code-generated string (to avoid filling up database or something).
If t() is not working try logging out and see will it work then?
If you are logged in as admin which has i.e. English set for language and if language detection prioritizes user's setup it may happen that even if page is on some other language because of user language English is detected.
注意,必须先访问翻译后的页面,然后t('string')下的字符串才会出现在翻译界面中
note that the translated page must be visited before the string under t('string') appears in the translate interface
您不能将变量作为参数传递给 t() 函数,它必须是实际的基于代码的字符串。
你可以去这里:Drupal t() function API,阅读更多内容,但据我所知这是不可能的。您需要找到其他转换为密钥的方法。也许可以制作自己的关系表并自己翻译。
You cannot pass variables as parameters to the t() function, it has to be an actual code-based string.
you can go here: Drupal t() function API, to read more, but as far as I know it just isn't possible. You would need to find some other way of translating to keys. Maybe making your own relationship table and translate them yourself.