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