1 gettext.inc _locale_export_get_strings($language = NULL)

Generates a structured array of all translated strings for the language.

Parameters

stdClass $language: Language object to generate the output for, or NULL if generating translation template.

Return value

array: An array of translated strings that can be used to generate an export.

Related topics

File

core/includes/gettext.inc, line 903
Gettext parsing and generating API.

Code

function _locale_export_get_strings($language = NULL) {
  if (isset($language)) {
    $result = db_query("SELECT s.lid, s.source, s.context, s.location, t.translation, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language ORDER BY t.plid, t.plural", array(':language' => $language->langcode));
  }
  else {
    $result = db_query("SELECT s.lid, s.source, s.context, s.location, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid ORDER BY t.plid, t.plural");
  }
  $strings = array();
  foreach ($result as $child) {
    $string = array(
      'comment' => $child->location,
      'source' => $child->source,
      'context' => $child->context,
      'translation' => isset($child->translation) ? $child->translation : '',
    );
    if ($child->plid) {
      // Has a parent lid. Since we process in the order of plids, we already
      // have the parent in the array, so we can add the lid to the next plural
      // version to it. This builds a linked list of plurals.
      $string['child'] = TRUE;
      $strings[$child->plid]['plural'] = $child->lid;
    }
    $strings[$child->lid] = $string;
  }
  return $strings;
}