You are here

function _l10n_client_page_strings in Localization client 7

Same name and namespace in other branches
  1. 5 l10n_client.module \_l10n_client_page_strings()
  2. 6.2 l10n_client.module \_l10n_client_page_strings()
  3. 6 l10n_client.module \_l10n_client_page_strings()

Get the strings to translate for this page.

These will be:

  • The ones added through l10n_client_add_string_to_page() by this or other modules.
  • The strings stored by the locale function (not for for this module's own pages).
1 call to _l10n_client_page_strings()
l10n_client_page_alter in ./l10n_client.module
Implement hook_page_alter().

File

./l10n_client.module, line 289
Localization client. Provides on-page translation editing.

Code

function _l10n_client_page_strings() {
  global $language;

  // Get the page strings 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])) {

    // Get the page strings stored by this or other modules.
    $strings += array(
      'default' => array(),
    );
    foreach ($locale[$language->language] as $context => $context_strings) {
      $strings['default'] += array(
        $context => array(),
      );
      $strings['default'][$context] = array_merge($strings['default'][$context], $context_strings);
    }

    // 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, 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(),
    ));
    foreach ($result as $data) {
      if (!array_key_exists($data->source, $strings[$data->textgroup])) {
        $strings[$data->textgroup][$data->context][$data->source] = empty($data->translation) ? TRUE : $data->translation;
      }
    }
  }
  return $strings;
}