You are here

function i18nstrings_get_string in Internationalization 6

Same name and namespace in other branches
  1. 5.3 i18nstrings/i18nstrings.module \i18nstrings_get_string()
  2. 5 experimental/i18nstrings.module \i18nstrings_get_string()
  3. 5.2 experimental/i18nstrings.module \i18nstrings_get_string()

Get string for a language.

Parameters

$context: Context string or object.

$langcode: Language code to retrieve string for.

Return value

  • Translation string as object if found.
  • FALSE if no translation
1 call to i18nstrings_get_string()
i18nstrings_translate_string in i18nstrings/i18nstrings.module
Get translation for user defined string.

File

i18nstrings/i18nstrings.module, line 548
Internationalization (i18n) package - translatable strings.

Code

function i18nstrings_get_string($context, $langcode) {
  $context = i18nstrings_context($context);

  // First try the cache
  $translation = i18nstrings_cache($context, $langcode);
  if (isset($translation)) {
    return $translation;
  }
  else {

    // Search translation and add it to the cache.
    list($where, $args) = i18nstrings_context_query($context);
    $where[] = "t.language = '%s'";
    $args[] = $langcode;

    // Get translation that may have an input format to apply
    $text = db_fetch_object(db_query("SELECT s.lid, t.translation FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE " . implode(' AND ', $where), $args));
    if ($text && $text->translation) {
      i18nstrings_cache($context, $langcode, NULL, $text->translation);
      return $text->translation;
    }
    else {
      i18nstrings_cache($context, $langcode, NULL, FALSE);
      return $text ? NULL : FALSE;
    }
  }
}