gpt4 book ai didi

localization - Drupal 6,以编程方式添加字符串翻译

转载 作者:行者123 更新时间:2023-12-04 04:37:13 25 4
gpt4 key购买 nike

我需要以编程方式添加字符串翻译(例如翻译分类术语)。有没有像 add_translation($my_term_name, $language, $translation) 这样的函数?

最佳答案

不幸的是,核心中没有很好的功能。您可以通过直接写入数据库来检查区域设置菜单是如何执行的:

function locale_translate_edit_form_submit($form, &$form_state) {
$lid = $form_state['values']['lid'];
foreach ($form_state['values']['translations'] as $key => $value) {
$translation = db_result(db_query("SELECT translation FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $key));
if (!empty($value)) {
// Only update or insert if we have a value to use.
if (!empty($translation)) {
db_query("UPDATE {locales_target} SET translation = '%s' WHERE lid = %d AND language = '%s'", $value, $lid, $key);
}
else {
db_query("INSERT INTO {locales_target} (lid, translation, language) VALUES (%d, '%s', '%s')", $lid, $value, $key);
}
}
elseif (!empty($translation)) {
// Empty translation entered: remove existing entry from database.
db_query("DELETE FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $key);
}

// Force JavaScript translation file recreation for this language.
_locale_invalidate_js($key);
}

drupal_set_message(t('The string has been saved.'));

// Clear locale cache.
_locale_invalidate_js();
cache_clear_all('locale:', 'cache', TRUE);

$form_state['redirect'] = 'admin/build/translate/search';
return;
}

如果您的文本来自不受信任的来源(例如用户输入),请不要忘记验证。

关于localization - Drupal 6,以编程方式添加字符串翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9377381/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com