You are here

private function PoFileLoader::addMessage in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/translation/Loader/PoFileLoader.php \Symfony\Component\Translation\Loader\PoFileLoader::addMessage()

Save a translation item to the messages.

A .po file could contain by error missing plural indexes. We need to fix these before saving them.

Parameters

array $messages:

array $item:

1 call to PoFileLoader::addMessage()
PoFileLoader::parse in vendor/symfony/translation/Loader/PoFileLoader.php
Parses portable object (PO) format.

File

vendor/symfony/translation/Loader/PoFileLoader.php, line 159

Class

PoFileLoader
@copyright Copyright (c) 2010, Union of RAD http://union-of-rad.org (http://lithify.me/) @copyright Copyright (c) 2012, Clemens Tolboom

Namespace

Symfony\Component\Translation\Loader

Code

private function addMessage(array &$messages, array $item) {
  if (is_array($item['translated'])) {
    $messages[stripcslashes($item['ids']['singular'])] = stripcslashes($item['translated'][0]);
    if (isset($item['ids']['plural'])) {
      $plurals = $item['translated'];

      // PO are by definition indexed so sort by index.
      ksort($plurals);

      // Make sure every index is filled.
      end($plurals);
      $count = key($plurals);

      // Fill missing spots with '-'.
      $empties = array_fill(0, $count + 1, '-');
      $plurals += $empties;
      ksort($plurals);
      $messages[stripcslashes($item['ids']['plural'])] = stripcslashes(implode('|', $plurals));
    }
  }
  elseif (!empty($item['ids']['singular'])) {
    $messages[stripcslashes($item['ids']['singular'])] = stripcslashes($item['translated']);
  }
}