private static function store($locale, $entries) { $file = self::getFile($locale); $dir = dirname($file); if (!is_dir($dir)) { mkdir($dir, 0755, true); } Generators\Mo::toFile($entries, $file . 'mo'); Generators\Po::toFile($entries, $file . 'po'); Generators\PhpArray::toFile($entries, $file . 'php'); return $entries; }
private static function store($entries) { $file = self::getFile(self::$locale); $dir = base_path() . "/" . dirname($file); if (!is_dir($dir)) { mkdir($dir, 0755, true); } $entries->setHeader('Language', self::$locale); Generators\Po::toFile($entries, base_path() . "/" . $file . 'po'); // Generators\PhpArray::toFile($entries, base_path()."/".$file.'php'); return $entries; }
public function saveSectionTranslationsToFile(Section $section, Translations $translations) { $po = DIR_LANGUAGES_SITE_INTERFACE . '/' . $section->getLocale() . '.po'; $mo = DIR_LANGUAGES_SITE_INTERFACE . '/' . $section->getLocale() . '.mo'; PoGenerator::toFile($translations, $po); /* Do not generate mo for empty catalog, it crashes Zend\I18n gettext loader */ $empty = true; foreach ($translations as $entry) { if ($entry->hasTranslation()) { $empty = false; break; } } if (!$empty) { MoGenerator::$includeEmptyTranslations = true; MoGenerator::toFile($translations, $mo); } else { if (is_file($mo)) { unlink($mo); } } }
protected function saveTranslations() { Gettext\Generators\Po::toFile($this->translations, $this->arguments['src-po']); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->writeSection($output, 'Csv to Po converter'); $this->cwd = getcwd() . DIRECTORY_SEPARATOR; $output->writeln('<info>Using CWD</info> ' . $this->cwd); $csvFile = $this->getInputCsvFile($input, $output); $poFiles = $this->getInputPoFiles($input, $output); $outputFolder = $this->getOutputFolder($input, $output); $useDefaults = $input->getOption('use-defaults'); if ($useDefaults) { $output->writeln('<info>Csv file</info>:' . "\n" . $csvFile . "\n"); $output->writeln('<info>Po files</info>:'); $this->writeList($output, $poFiles); $output->writeln("\n" . '<info>Output folder</info>: ' . "\n" . $outputFolder . "\n"); } $writeHandles = []; foreach ($poFiles as $poFile) { $key = basename($poFile, '.po'); $output->writeln('<info>loading ' . $key . '</info>...'); $writeHandles[$key] = Translations::fromPoFile($poFile); } $header = null; $output->writeln('<info>reading from csv</info>...'); $reader = Reader::createFromPath($csvFile); foreach ($reader as $i => $row) { if ($header == null) { $header = $row; continue; } $original = null; foreach ($row as $j => $string) { if ($original == null) { $original = $string; continue; } if (empty($string)) { continue; } $writeHandle = $writeHandles[$header[$j]]; $translation = $writeHandle->find(null, $original); if ($translation != false && $translation->translation != $string) { if (!empty($translation->translation)) { $this->handleConflict($input, $output, $original, $translation->translation, $string); } else { $translation->setTranslation($string); } } else { $translation = new Translation(null, $original); $translation->setTranslation($string); $writeHandle[] = $translation; } } } foreach ($writeHandles as $key => $writeHandle) { $output->writeln('<info>writing ' . $key . '</info>...'); $content = Po::toString($writeHandle); file_put_contents($this->outputDir . DIRECTORY_SEPARATOR . $key . '.po', $content); } $output->writeln('<info>done</info>'); }