diff --git a/l10n_client.module b/l10n_client.module index 457aa83..1b96534 100644 --- a/l10n_client.module +++ b/l10n_client.module @@ -303,8 +303,30 @@ function _l10n_client_page_strings() { // 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, s.textgroup, s.context 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())); + + // Javascript aggregation and Drupal.t parsing is done in drupal_get_js(). + // Call it here to make sure the db and js translation files are up-to-date. + drupal_get_js(); + + $query = db_select('locales_source', 's'); + $query->leftJoin('locales_target', 't', 's.lid = t.lid AND t.language = :language', array( + ':language' => $language->language)); + $query->fields('s', array('source', 'textgroup', 'context')) + ->fields('t', array('translation')); + + // Prepare OR condition for query + $or = db_or()->condition('s.location', request_uri()); + foreach (array_keys(drupal_add_js()) as $script) { + $or->condition('s.location', '%' . $script . '%', 'LIKE'); + } + $query->condition($or); + + $result = $query->execute(); + foreach ($result as $data) { + if (!isset($strings[$data->textgroup])) { + $strings[$data->textgroup] = array(); + } if (!array_key_exists($data->source, $strings[$data->textgroup])) { $strings[$data->textgroup][$data->context][$data->source] = (empty($data->translation) ? TRUE : $data->translation); } @@ -315,6 +337,20 @@ function _l10n_client_page_strings() { } /** + * Implements hook_module_implements_alter(). + * + * Move l10n_client_page_alter() to the end of the hook queue to capture calls + * to drupal_add_js made from other page_alter hooks. + */ +function l10n_client_module_implements_alter(&$implementations, $hook) { + if ($hook == 'page_alter') { + $group = $implementations['l10n_client']; + unset($implementations['l10n_client']); + $implementations['l10n_client'] = $group; + } +} + +/** * Helper function for the string list DOM tree */ function _l10n_client_dom_strings($strings) { @@ -460,6 +496,20 @@ function l10n_client_save_string() { cache_clear_all('locale:', 'cache', TRUE); _locale_invalidate_js($language->language); + /* The following snippet is taken from the function + * _admin_menu_flush_cache() of the admin menu module. + * Invalidating the js translation files is not enough, so do a full + * clear cache and renew the dummy query string to force a reload. Also + * clear the css cache because it uses the same dummy query and clear + * page cache because js and css files changed. + * This also makes sure that all changes to js files are transferred + * into the db. + */ + _drupal_flush_css_js(); + drupal_clear_css_cache(); + drupal_clear_js_cache(); + cache_clear_all('*', 'cache_page', TRUE); + if (!empty($report['skips'])) { $message = theme('l10n_client_message', array('message' => t('Not saved locally due to invalid HTML content.'))); }