18

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
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416

1 Answers1

23

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

corbacho
  • 8,762
  • 1
  • 26
  • 23
  • 1
    Not that although this is all correct, for contributed modules, the extraction of localization strings happens automatically when a new version is released by http://localize.drupal.org. Then, http://drupal.org/project/l10n_update can be used to get the translations from there. But custom modules are a different story, obviously... – Berdir Mar 08 '11 at 20:40
  • 2
    If you are translating a *custom* module, you need to *reinstall* it in order to apply translation. When you don't want to do that (e.g. you don't want to lost all permissions and db tables on uninstall) you can run a drush command to force translations loading: ``drush php-eval "locale_system_update(array('yourmodule_name'));drush_backend_batch_process();"`` – gakhov Oct 15 '13 at 14:50
  • @corbacho: i follow your steps but it didn't work for me – Sumit Aggarwal Jan 16 '17 at 11:42