Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PoItem.php

function PoItem::formatString

Formats a string for output on multiple lines.

3 calls to PoItem::formatString()
PoItem::formatItem in core/lib/Drupal/Component/Gettext/PoItem.php
Format the POItem as a string.
PoItem::formatPlural in core/lib/Drupal/Component/Gettext/PoItem.php
Formats a plural translation.
PoItem::formatSingular in core/lib/Drupal/Component/Gettext/PoItem.php
Formats a singular translation.

File

core/lib/Drupal/Component/Gettext/PoItem.php, line 277

Class

PoItem
PoItem handles one translation.

Namespace

Drupal\Component\Gettext

Code

private function formatString($string) {
    // Escape characters for processing.
    $string = addcslashes($string, "\x00..\x1f\\\"");
    // Always include a line break after the explicit \n line breaks from
    // the source string. Otherwise wrap at 70 chars to accommodate the extra
    // format overhead too.
    $parts = explode("\n", wordwrap(str_replace('\\n', "\\n\n", $string), 70, " \n"));
    // Multiline string should be exported starting with a "" and newline to
    // have all lines aligned on the same column.
    if (count($parts) > 1) {
        return "\"\"\n\"" . implode("\"\n\"", $parts) . "\"\n";
    }
    else {
        return "\"{$parts[0]}\"\n";
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal