_locale_import_one_string

Versions
4.7
_locale_import_one_string($value, $mode, $lang = NULL)
5
_locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NULL, $file = NULL)
6 – 7
_locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NULL, $file = NULL, $group = 'default')

Imports a string into the database

Parameters

$op Operation to perform: 'db-store', 'db-report', 'mem-store' or 'mem-report'

$value Details of the string stored

$mode Should existing translations be replaced LOCALE_IMPORT_KEEP or LOCALE_IMPORT_OVERWRITE

$lang Language to store the string in

$file Object representation of file being imported, only required when op is 'db-store'

$group Text group to import PO file into (eg. 'default' for interface translations)

Related topics

▾ 3 functions call _locale_import_one_string()

st in includes/install.inc
Functional equivalent of t(), used when some systems are not available.
_locale_import_po in includes/locale.inc
Parses Gettext Portable Object file information and inserts into database
_locale_import_read_po in includes/locale.inc
Parses Gettext Portable Object file into an array

Code

includes/locale.inc, line 1909

<?php
function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NULL, $file = NULL, $group = 'default') {
  $report = &drupal_static(__FUNCTION__, array('additions' => 0, 'updates' => 0, 'deletes' => 0, 'skips' => 0));
  $header_done = &drupal_static(__FUNCTION__ . ':header_done', FALSE);
  $strings = &drupal_static(__FUNCTION__ . ':strings', array());

  switch ($op) {
    // Return stored strings
    case 'mem-report':
      return $strings;

    // Store string in memory (only supports single strings)
    case 'mem-store':
      $strings[isset($value['msgctxt']) ? $value['msgctxt'] : ''][$value['msgid']] = $value['msgstr'];
      return;

    // Called at end of import to inform the user
    case 'db-report':
      return array($header_done, $report['additions'], $report['updates'], $report['deletes'], $report['skips']);

    // Store the string we got in the database.
    case 'db-store':
      // We got header information.
      if ($value['msgid'] == '') {
        $header = _locale_import_parse_header($value['msgstr']);

        // Get the plural formula and update in database.
        if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->uri)) {
          list($nplurals, $plural) = $p;
          db_update('languages')
            ->fields(array(
              'plurals' => $nplurals,
              'formula' => $plural,
            ))
            ->condition('language', $lang)
            ->execute();
        }
        else {
          db_update('languages')
            ->fields(array(
              'plurals' => 0,
              'formula' => '',
            ))
            ->condition('language', $lang)
            ->execute();
        }
        $header_done = TRUE;
      }

      else {
        // Some real string to import.
        $comments = _locale_import_shorten_comments(empty($value['#']) ? array() : $value['#']);

        if (strpos($value['msgid'], "\0")) {
          // This string has plural versions.
          $english = explode("\0", $value['msgid'], 2);
          $entries = array_keys($value['msgstr']);
          for ($i = 3; $i <= count($entries); $i++) {
            $english[] = $english[1];
          }
          $translation = array_map('_locale_import_append_plural', $value['msgstr'], $entries);
          $english = array_map('_locale_import_append_plural', $english, $entries);
          foreach ($translation as $key => $trans) {
            if ($key == 0) {
              $plid = 0;
            }
            $plid = _locale_import_one_string_db($report, $lang, isset($value['msgctxt']) ? $value['msgctxt'] : '', $english[$key], $trans, $group, $comments, $mode, $plid, $key);
          }
        }

        else {
          // A simple string to import.
          $english = $value['msgid'];
          $translation = $value['msgstr'];
          _locale_import_one_string_db($report, $lang, isset($value['msgctxt']) ? $value['msgctxt'] : '', $english, $translation, $group, $comments, $mode);
        }
      }
  } // end of db-store operation
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.