@@ -247,7 +244,10 @@ function l10n_client_footer() {
$l10n_dom
";
- return $output;
+ $page['page_bottom']['l10n_client'] = array(
+ '#type' => 'markup',
+ '#markup' => $output,
+ );
}
}
@@ -261,7 +261,7 @@ function l10n_client_footer() {
*/
function l10_client_add_string_to_page($source = NULL, $translation = NULL) {
static $strings = array();
-
+
if (isset($source)) {
$strings[$source] = $translation;
}
@@ -282,25 +282,25 @@ function _l10n_client_page_strings() {
// Get the page strins stored by this or other modules.
$strings = l10_client_add_string_to_page();
-
+
// If this is not the module's translation page, merge all strings used on the page.
if (arg(0) != 'locale' && is_array($locale = locale()) && isset($locale[$language->language])) {
// @todo: add actual context support.
$strings = array_merge($strings, $locale[$language->language]['']);
-
+
// Also select and add other strings for this path. Other users may have run
// into these strings for the same page. This might be useful in some cases
// but will not work reliably in all cases, since strings might have been
// found on completely different paths first, or on a slightly different
// path.
- $result = db_query("SELECT s.source, t.translation FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '%s' WHERE s.location = '%s'", $language->language, request_uri());
- while ($data = db_fetch_object($result)) {
+ $result = db_query("SELECT s.source, t.translation FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.location = :location", array(':language' => $language->language, ':location' => request_uri()));
+ foreach ($result as $data) {
if (!array_key_exists($data->source, $strings)) {
$strings[$data->source] = (empty($data->translation) ? TRUE : $data->translation);
}
}
}
-
+
return $strings;
}
@@ -334,10 +334,10 @@ function _l10n_client_string_list($strin
// TRUE means we don't have translation, so we use the original string,
// so we always have the string displayed on the page in the dropdown.
$original = $values[1] === TRUE ? $values[0] : $values[1];
-
+
// Remove HTML tags for display.
$string = strip_tags($original);
-
+
if (empty($string)) {
// Edge case where the whole string was HTML tags. For the
// user to be able to select anything, we need to show part
@@ -350,7 +350,7 @@ function _l10n_client_string_list($strin
// Truncate and add ellipsis if too long.
$string = truncate_utf8($string, 78, TRUE, TRUE);
}
-
+
$select_list[] = "
$string
";
}
$output = implode("\n", $select_list);
@@ -386,7 +386,7 @@ function l10n_client_form($form_id, $str
$form['clear'] = array(
'#markup' => "",
);
-
+
return $form;
}
@@ -411,7 +411,7 @@ function l10n_client_search_form() {
*/
function l10n_client_save_string() {
global $user, $language;
-
+
if (user_access('use on-page translation')) {
if (isset($_POST['source']) && isset($_POST['target']) && !empty($_POST['form_token']) && drupal_valid_token($_POST['form_token'], 'l10n_client_form')) {
include_once 'includes/locale.inc';
@@ -420,7 +420,7 @@ function l10n_client_save_string() {
_locale_import_one_string_db($report, $language->language, '', $_POST['source'], $_POST['target'], 'default', NULL, LOCALE_IMPORT_OVERWRITE);
cache_clear_all('locale:', 'cache', TRUE);
_locale_invalidate_js($language->language);
-
+
// Submit to remote server if enabled.
if (variable_get('l10n_client_use_server', FALSE) && user_access('submit translations to localization server') && !empty($user->l10n_client_key)) {
l10n_client_submit_translation($language->language, $_POST['source'], $_POST['target'], $user->l10n_client_key, l10n_client_user_token($user));
@@ -447,7 +447,7 @@ function l10n_client_import_package_form
drupal_set_message(t('No languages set up to reimport packages into.'), 'warning');
return array();
}
-
+
$form = array();
$form['reimport'] = array(
'#type' => 'fieldset',
@@ -484,7 +484,16 @@ function l10n_client_import_package_form
// Clean out all translations first if user asked to do that.
$langcodes = array_keys(array_filter($form_state['values']['langcodes']));
$textgroups = array_keys(array_filter($form_state['values']['textgroups']));
- db_query("DELETE FROM {locales_target} WHERE language IN (". db_placeholders($langcodes, 'varchar') .") AND lid IN (SELECT lid FROM {locales_source} WHERE textgroup IN (". db_placeholders($textgroups, 'varchar') ."))", array_merge($langcodes, $textgroups));
+
+ $query = db_select('locales_source', 's');
+ $query->condition('s.textgroup', $textgroups);
+ $lids = $query->fetchCol('lid');
+
+ db_delete('locales_target')
+ ->condition('language', $langcodes)
+ ->condition('lid', $lids)
+ ->execute();
+
// Also remove all source strings without translations.
db_query("DELETE FROM {locales_source} WHERE lid NOT IN (SELECT lid FROM {locales_target})");
}
@@ -528,11 +537,11 @@ function l10n_client_settings_form() {
* Make sure it supports the exact version of the API we will try to use.
*/
function l10n_client_settings_form_validate($form, &$form_state) {
- if ($form_state['values']['l10n_client_use_server'] && drupal_function_exists('xmlrpc')) {
-
+ if ($form_state['values']['l10n_client_use_server']) {
+
// Try to invoke the remote string submission with a test request.
$response = xmlrpc($form_state['values']['l10n_client_server'] .'/xmlrpc.php', 'l10n.server.test', '2.0');
-
+
if ($response && !empty($response['name']) && !empty($response['version'])) {
if (empty($response['supported']) || !$response['supported']) {
form_set_error('l10n_client_server', t('The given server could not handle the v2.0 remote submission API.'));
@@ -548,26 +557,29 @@ function l10n_client_settings_form_valid
}
/**
- * Implementation of hook_user().
- *
+ * Implement hook_user_form().
+ *
* Set up API key for localization server.
*/
-function l10n_client_user($type, $edit, &$account, $category = NULL) {
- if ($type == 'form' && $category == 'account' && variable_get('l10n_client_use_server', FALSE) && user_access('submit translations to localization server', $account)) {
- $form['l10n_client'] = array(
- '#type' => 'fieldset',
- '#title' => t('Localization client'),
- '#weight' => 1,
- );
- // Build link to retrieve user key.
- $server_link = variable_get('l10n_client_server', '') .'?q=translate/remote/userkey/'. l10n_client_user_token($account);
- $form['l10n_client']['l10n_client_key'] = array(
- '#type' => 'textfield',
- '#title' => t('Your Localization Server API key'),
- '#default_value' => !empty($account->l10n_client_key) ? $account->l10n_client_key : '',
- '#description' => t('This is a unique key that will allow you to send translations to the remote server. To get your API key go to !server-link.', array('!server-link' => l($server_link, $server_link))),
- );
- return $form;
+function l10n_client_form_user_profile_form_alter(&$form, &$form_state) {
+ if ($form['#user_category'] == 'account' && variable_get('l10n_client_use_server', FALSE)) {
+ $account = $form['#user'];
+ if (user_access('submit translations to localization server', $account)) {
+ $form['l10n_client'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Localization client'),
+ '#weight' => 1,
+ );
+ // Build link to retrieve user key.
+ $server_link = variable_get('l10n_client_server', '') .'?q=translate/remote/userkey/'. l10n_client_user_token($account);
+ $form['l10n_client']['l10n_client_key'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Your Localization Server API key'),
+ '#default_value' => !empty($account->l10n_client_key) ? $account->l10n_client_key : '',
+ '#description' => t('This is a unique key that will allow you to send translations to the remote server. To get your API key go to !server-link.', array('!server-link' => l($server_link, $server_link))),
+ );
+ return $form;
+ }
}
}
@@ -586,10 +598,10 @@ function l10n_client_user_token($account
function l10n_client_submit_translation($langcode, $source, $translation, $user_key, $user_token) {
$server_uid = current(split(':', $user_key));
$signature = md5($user_key . $langcode . $source . $translation . $user_token);
-
+
$response = xmlrpc(
variable_get('l10n_client_server', '') .'/xmlrpc.php',
- 'l10n.submit.translation',
+ 'l10n.submit.translation',
$langcode,
$source,
$translation,