You are here

public static function i18n_string_textgroup_default::load_translation in Internationalization 7

Load translation from db

@todo Optimize when we've already got the source string

1 call to i18n_string_textgroup_default::load_translation()
i18n_string_textgroup_cached_logged::load_translation in tests/i18n_test.module
Load translation from db
1 method overrides i18n_string_textgroup_default::load_translation()
i18n_string_textgroup_cached_logged::load_translation in tests/i18n_test.module
Load translation from db

File

i18n_string/i18n_string.inc, line 669
API for internationalization strings

Class

i18n_string_textgroup_default
Textgroup handler for i18n_string API

Code

public static function load_translation($i18nstring, $langcode) {

  // Search the database using lid if we've got it or textgroup, context otherwise
  if (!empty($i18nstring->lid)) {

    // We've already got lid, we just need translation data
    $query = db_select('locales_target', 't');
    $query
      ->condition('t.lid', $i18nstring->lid);
  }
  else {

    // Still don't have lid, load string properties too
    $query = db_select('i18n_string', 's')
      ->fields('s');
    $query
      ->leftJoin('locales_target', 't', 's.lid = t.lid');
    $query
      ->condition('s.textgroup', $i18nstring->textgroup);
    $query
      ->condition('s.context', $i18nstring->context);
  }

  // Add translation fields
  $query
    ->fields('t', array(
    'translation',
    'i18n_status',
  ));
  $query
    ->condition('t.language', $langcode);

  // Speed up the query, we just need one row
  $query
    ->range(0, 1);
  return $query
    ->execute()
    ->fetchObject();
}