17
我使用CentOS 5.5 Linux(不含X),PHP 5.3和Drupal 7.0。如何为自定义Drupal 7模块生成翻译文件?
我的网站的核心语言是俄语(不是英语)!
我创建了一个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
不是说,虽然这是完全正确的,但对于提供的模块,当http://localize.drupal.org发布新版本时,会自动提取本地化字符串。然后,可以使用http://drupal.org/project/l10n_update从那里获取翻译。但自定义模块是一个不同的故事,显然... – Berdir 2011-03-08 20:40:36
如果您正在翻译* custom *模块,则需要*重新安装*以便应用翻译。当你不想这样做时(例如,你不想在卸载时丢失所有权限和数据库表),你可以运行一个drush命令来强制翻译加载:''drush php-eval“locale_system_update(array('yourmodule_name ')); drush_backend_batch_process();“''' – gakhov 2013-10-15 14:50:56
@corbacho:我按照你的步骤,但它不适合我 – 2017-01-16 11:42:44