t()不打印翻译的字符串

时间:2010-11-16 10:18:01

标签: drupal drupal-6 translation

我当前尝试通过对所有Hard-Codes-Strings使用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>

要翻译和打印的术语在<h2>范围内,这是一个使用SQL查询抓取的分类法术语:

  $terms_result = db_query("
    SELECT tid, name
    FROM {term_data}
    WHERE vid = '".variable_get('catchy_overview_vocabulary_id', false)."'
  ");

我真的希望你能帮助我。如果您需要更多信息,请随时评论......我现在很困惑。

4 个答案:

答案 0 :(得分:2)

您不能将变量作为参数传递给t()函数,它必须是基于代码的实际字符串。

你可以到这里: Drupal t() function API ,阅读更多内容,但据我所知,这是不可能的。您需要找到一些其他方式来翻译密钥。也许制作自己的关系表并自己翻译。

答案 1 :(得分:0)

我倾向于怀疑您没有启用Locale模块,没有启用多种语言,或者没有为该单词输入实际的翻译。

答案 2 :(得分:0)

你可以将变量传递给t(),但是传递用户的输入(以避免安全问题)或者大量代码生成的字符串(以避免填满数据库或其他东西)并不好。

如果t()不起作用,请尝试退出并查看是否可以正常工作?

如果您以管理员身份登录,即英语设置为语言,并且如果语言检测优先考虑用户的设置,则可能会发生由于检测到用户语言而导致页面处于某种其他语言的情况。

答案 3 :(得分:0)

请注意,在翻译界面中出现t('string')下的字符串之前,必须访问已翻译的页面