如何为自定义Drupal 7模块生成翻译文件?

时间:2011-03-08 10:56:33

标签: drupal localization internationalization gettext drupal-7

我正在使用CentOS 5.5 Linux(不带X),PHP 5.3和Drupal 7.0。

我网站的核心语言是俄语(非英语)!

我创建了 game.info 和以下 game.module ,为首页生成了3个块:

function game_block_info() {
  return array(
  'game_main' => array(
    'info' => t('Set FlashVars and show the flash game.'),
    'cache' => DRUPAL_NO_CACHE,
  ),
  'game_winner' => array(
    'info' => t('Show the winner of the last week.'),
    'cache' => DRUPAL_NO_CACHE,
  ),
  'game_leader' => array(
    'info' => t('Show the leader of the current week.'),
    'cache' => DRUPAL_NO_CACHE,
  );
}


function game_block_view($block_name = '') {
  global $user;

  if ($block_name == 'game_main') {
    if (user_is_logged_in()) {
      $content = t('User is logged in.');
    } else {
      $content = t('User is an anonymous user.');
    }
    drupal_set_message("<pre>$output</pre>\n");
    return array(
      'subject' => t('Main Game'),
      'content' => $content,
    );
  } else if ($block_name == 'game_winner') {
    ....
  } else if ($block_name == 'game_leader') {
    ....
  }
}

它运行正常,但我需要所有字符串都是俄语,并且不想将它们硬编码到我的game.module文件中。

我是否需要创建名为 game.po 的第3个文件并将其添加到game.info?

如何创建.po文件?如果可能的话,我希望在没有模糊工具的情况下对该文件进行简单的编辑。

我也试过一个工具:

# xgettext -n game/game.module --keyword=t
xgettext: warning: file `game/game.module' extension `module' is unknown; will try C
game/game.module:87: warning: unterminated character constant
game/game.module:100: warning: unterminated character constant

1 个答案:

答案 0 :(得分:22)

这些应该是以下步骤:

  1. 要生成.pot文件,请安装模块Translation template extractor

  2. 转到“区域设置”管理界面上的“提取字符串”选项卡,选择您的模块并提交表单。您将获得一个生成的模板文件。

  3. 然后,您可以使用 Poedit http://www.poedit.net)等工具翻译字符串。

  4. 完成后,应将文件复制到模块文件夹中的“翻译”子文件夹,以便在安装游戏模块时由Drupal自动导入。

  5. 请提供反馈并告诉您有什么问题。谢谢