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

如何为定制Drupal 7模块生成翻译文件?,drupal,localization,internationalization,gettext,drupal-7,Drupal,Localization,Internationalization,Gettext,Drupal 7,我使用的是CentOS 5.5 Linux(不含X)、PHP5.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.'), 'cac

我使用的是CentOS 5.5 Linux(不含X)、PHP5.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') {
    ....
  }
}

这些应该是以下步骤:

  • 要生成.pot文件,请安装模块

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

  • 然后可以使用类似于Poedit()的工具翻译字符串

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


  • 请给出反馈,告诉我你有什么问题。感谢

    尽管这一切都是正确的,但对于贡献的模块,在发布新版本时会自动提取本地化字符串。然后,可以从那里获取翻译。但是自定义模块是另一回事,显然……如果您正在翻译自定义模块,则需要重新安装它才能应用翻译。当您不想这样做(例如,您不想在卸载时丢失所有权限和db表)时,可以运行drush命令强制加载翻译:
    drush php eval“locale\u system\u update(array('yourmodule\u name'));drush\u backend\u batch\u process()”
    @corbacho:我遵循您的步骤,但它对我不起作用
    # 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