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

发布于 2024-10-21 05:28:40 字数 1619 浏览 1 评论 0原文

我使用的是 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 的第三个文件并将其添加到 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

I'm using CentOS 5.5 Linux (without X), PHP 5.3 and Drupal 7.0.

The core language of my site is Russian (not English)!

I've created a game.info and the following game.module which generates 3 blocks for the front page:

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') {
    ....
  }
}

It works ok, but I need all strings to be in Russian and do not want to hardcode them into my game.module file.

Do I need to create the 3rd file called game.po and add it to the game.info?

How can I create a .po file? I would prefer a simple editing of that file if possible, without obscure tools.

I've also tried a tool:

# 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇女薄笑 2024-10-28 05:28:40

步骤如下:

  1. 要生成 .pot 文件,请安装模块翻译模板提取器 < /p>

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

  3. 然后您可以使用 Poedit (http://www.poedit .net)。

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

    完成

请提供反馈并告诉您遇到了什么问题。谢谢

These should be the steps:

  1. To generate the .pot file, install the module Translation template extractor

  2. Go to the "Extract strings" tab on the Locale administration interface, select your module and submit the form. You will get one single template file generated.

  3. Then you can translate the strings with a tool like Poedit (http://www.poedit.net).

  4. When you are done, files should be copied to a "translations" sub-folder in the module folder, so they are automatically imported by Drupal when installing your game module.

Please, give feedback and tell what problems did you have. Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文