vendor/nambu-private/pimcore-base/src/BaseBundle/Service/TranslationService.php line 8

Open in your IDE?
  1. <?php
  2. namespace BaseBundle\Service;
  3. use Pimcore\Model\Translation;
  4. use Pimcore\Tool;
  5. class TranslationService {
  6.     public function onTranslationChange() {
  7.         foreach (Tool::getValidLanguages() as $locale) {
  8.             $filePath PIMCORE_WEB_ROOT.'/var/tmp/translation-'.$locale.'.js';
  9.             if (file_exists($filePath)) unlink($filePath);
  10.         }
  11.     }
  12.     public static function generateJsFiles() {
  13.         foreach (Tool::getValidLanguages() as $locale) {
  14.             $filePath PIMCORE_WEB_ROOT.'/var/tmp/translation-'.$locale.'.js';
  15.             if (file_exists($filePath)) {
  16.                 continue;
  17.             }
  18.             $fileContent = ["var trmsg = {"];
  19.             $listClass = new Translation\Listing();
  20.             $listClass->setCondition('language = ? AND text != \'\'', [$locale]);
  21.             $translations $listClass->loadRaw();
  22.             foreach ($translations as $translation) {
  23.                 $translationTerm Tool\Text::removeLineBreaks($translation['text']);
  24.                 if (!empty($translationTerm)) {
  25.                     $fileContent[] = "'".str_replace(["'""\n"], ['\\\''''], $translation['key'])."': '".str_replace("'"'\\\''$translationTerm)."',";
  26.                 }
  27.             }
  28.             $fileContent[] = "};";
  29.             file_put_contents($filePathjoin(PHP_EOL$fileContent));
  30.         }
  31.     }
  32. }