You are here

function _potx_save_string in Translation template extractor 8

Same name and namespace in other branches
  1. 5.2 potx.inc \_potx_save_string()
  2. 5 potx.inc \_potx_save_string()
  3. 6.3 potx.inc \_potx_save_string()
  4. 6 potx.inc \_potx_save_string()
  5. 6.2 potx.inc \_potx_save_string()
  6. 7.3 potx.inc \_potx_save_string()
  7. 7 potx.inc \_potx_save_string()
  8. 7.2 potx.inc \_potx_save_string()

Default $save_callback used by the potx system.

Saves values to global arrays to reduce memory consumption problems when passing around big chunks of values.

Parameters

string $value: The string value. If NULL, the array of collected values are returned for the given $string_mode.

int $context: From Drupal 7, separate contexts are supported. POTX_CONTEXT_NONE is the default, if the code does not specify a context otherwise.

string $file: Name of file where the string was found.

int $line: Line number where the string was found.

int $string_mode: String mode: POTX_STRING_INSTALLER, POTX_STRING_RUNTIME or POTX_STRING_BOTH.

2 calls to _potx_save_string()
PotxCommands::potx in src/Commands/PotxCommands.php
Extract translatable strings from Drupal source code.
potx_drush_extract in ./potx.drush.inc
Drush command callback.
8 string references to '_potx_save_string'
PotxCommands::potx in src/Commands/PotxCommands.php
Extract translatable strings from Drupal source code.
PotxExtractTranslationForm::submitForm in src/Form/PotxExtractTranslationForm.php
Form submission handler.
PotxTest::buildOutput in tests/src/Kernel/PotxTest.php
Build the output from parsed files.
PotxTest::parseFile in tests/src/Kernel/PotxTest.php
Parse the given file with the given API version.
PotxTest::parsePhpContent in tests/src/Kernel/PotxTest.php
Parse the given file with the given API version.

... See full list

File

./potx.inc, line 3311
Extraction API used by the web and command line interface.

Code

function _potx_save_string($value = NULL, $context = NULL, $file = NULL, $line = 0, $string_mode = POTX_STRING_RUNTIME) {
  global $_potx_strings, $_potx_install;
  if (isset($value)) {

    // Value set but empty. Mark error on empty translatable string. Only trim
    // for empty string checking, since we should store leading/trailing
    // whitespace as it appears in the string otherwise.
    $check_empty = trim($value);
    if (empty($check_empty)) {
      potx_status('error', t('Empty string attempted to be localized. Please do not leave test code for localization in your source.'), $file, $line);
      return;
    }
    switch ($string_mode) {
      case POTX_STRING_BOTH:

        // Mark installer strings as duplicates of runtime strings if
        // the string was both recorded in the runtime and in the installer.
        $_potx_install[$value][$context][$file][] = $line . ' (dup)';

      // Break intentionally missing.
      case POTX_STRING_RUNTIME:

        // Mark runtime strings as duplicates of installer strings if
        // the string was both recorded in the runtime and in the installer.
        $_potx_strings[$value][$context][$file][] = $line . ($string_mode == POTX_STRING_BOTH ? ' (dup)' : '');
        break;
      case POTX_STRING_INSTALLER:
        $_potx_install[$value][$context][$file][] = $line;
        break;
    }
  }
  else {
    return $string_mode == POTX_STRING_RUNTIME ? $_potx_strings : $_potx_install;
  }
}