Exemplo n.º 1
0
 /**
  * Import labels from a .ini file to the database.
  *
  * @param  string $path    Label file path
  * @param  int    $storage Storage folder ID to import to
  * @return void
  */
 public function importCommand($path, $storage)
 {
     $this->outputLine('Importing labels');
     if (!file_exists($path)) {
         $this->outputLine('Could not find label file');
         $this->quit(1);
     }
     $labels = parse_ini_file($path);
     if (count($labels)) {
         $this->outputLine('Found ' . count($labels) . ' labels');
         $inserted = 0;
         $skipped = 0;
         foreach ($labels as $key => $value) {
             $existing = $this->labelRepo->findOneByLabelKey($key);
             if (!$existing) {
                 $label = new Label();
                 $label->setPid($storage);
                 $label->setLabelKey($key);
                 $label->setLabelValue($value);
                 $this->labelRepo->add($label);
                 $inserted++;
             } else {
                 $skipped++;
             }
         }
         $this->outputLine('Inserted ' . $inserted . ' new label(s).');
         $this->outputLine('Skipped ' . $skipped . ' existing label(s).');
         $this->quit();
     } else {
         $this->outputLine('No labels found to import');
         $this->quit();
     }
 }
Exemplo n.º 2
0
 /**
  * Search the database or local cache for the supplied label key, optionally
  * replacing the result with the markers array.
  *
  * @param  string $key     Label key
  * @param  array  $markers Optional array of markes to replace in the translation.
  *                         Key/value pairs
  * @return string          Found label, or the key if key could not be found
  */
 public function get($key, $markers = [])
 {
     if ($this->labelCache === null) {
         if (($this->labelCache = $this->getCache()->get('tev_labels')) === false) {
             $this->labelCache = $this->labelRepo->findAllKeysAndValues();
             $this->getCache()->set('tev_labels', $this->labelCache);
         }
     }
     if (isset($this->labelCache[$key])) {
         return $this->replaceValues($this->labelCache[$key], $markers);
     } else {
         return $key;
     }
 }