'checkboxes', '#title' => t('Select text groups'), '#options' => $groups, ); $form['refresh'] = array('#type' => 'submit', '#value' => t('Refresh strings'), '#suffix' => '
'.t('This will create all the missing strings for the selected text groups.').'
', ); // Get all languages, except default language $languages = locale_language_list('name', TRUE); unset($languages[language_default('language')]); $form['languages'] = array( '#type' => 'checkboxes', '#title' => t('Select languages'), '#options' => $languages, ); $form['update'] = array('#type' => 'submit', '#value' => t('Update translations'), '#suffix' => ''.t('This will fetch all existing translations from the localization tables for the selected text groups and languages.').'
', ); return $form; } /** * Form submission */ function i18nstrings_admin_refresh_submit($form, &$form_state) { $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; $groups = array_filter($form_state['values']['groups']); $languages = array_filter($form_state['values']['languages']); if ($op == t('Refresh strings') && $groups) { foreach ($groups as $group) { module_invoke_all('locale', 'refresh', $group); } } else if($op == t('Update translations') && $groups && $languages) { $count = 0; foreach ($languages as $language) { $count += i18nstrings_admin_update($language, $groups); } drupal_set_message(format_plural($count, '1 string has been updated.', '@count strings have been updated.')); } } /** * Update strings for language */ function i18nstrings_admin_update($language, $groups) { $params = $groups; $params[] = $language; $sql = 'SELECT g.*, t.translation, t.lid as tlid FROM {locales_source} g INNER JOIN {locales_source} s ON g.source = s.source AND s.lid <> g.lid '; $sql .= 'INNER JOIN {locales_target} t ON s.lid = t.lid LEFT JOIN {locales_target} t2 ON g.lid = t2.lid '; $sql .= 'WHERE t2.lid IS NULL AND g.textgroup IN ('. db_placeholders($groups, 'varchar'). ") AND t.language = '%s'"; $result = db_query($sql , $params); $count = 0; while ($string = db_fetch_object($result)) { $count++; if (!empty($string->translation)) { db_query("INSERT INTO {locales_target} (translation, lid, language) VALUES('%s', %d, '%s')", $string->translation, $string->lid, $language); } } return $count; }