开发者

t() not printing a translated string

开发者 https://www.devze.com 2023-01-25 02:39 出处:网络
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

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.


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.


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.


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.


note that the translated page must be visited before the string under t('string') appears in the translate interface

0

精彩评论

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