public function JSUrl() { if (!count($this->_js)) { return ''; } $url = $this->app->make('url')->to($this->app->config->get('combiner.javascript.route')) . '/'; $basedir = $this->app->basePath() . DIRECTORY_SEPARATOR . $this->app->config->get('combiner.javascript.path'); $count = 0; foreach ($this->_js as $file) { if (file_exists($basedir . DIRECTORY_SEPARATOR . $file)) { $url .= ($count ? ',' : '') . str_replace('/', '~', $file); $count++; } } return sprintf('%s/%d/', $url, $count); }
/** * Get the base path of the Laravel installation. * * @return string * @static */ public static function basePath() { return \Illuminate\Foundation\Application::basePath(); }
public function exportTranslations($group, $recursing = 0) { // TODO: clean up this recursion crap // this can come from the command line $ltm_translations = $this->getTranslationsTableName(); if (!$recursing) { $this->clearErrors(); $group = self::fixGroup($group); } if ($group && $group !== '*') { $this->getConnection()->affectingStatement("DELETE FROM {$ltm_translations} WHERE is_deleted = 1"); } elseif (!$recursing) { $this->getConnection()->affectingStatement("DELETE FROM {$ltm_translations} WHERE is_deleted = 1 AND `group` = ?", [$group]); } $inDatabasePublishing = $this->inDatabasePublishing(); if ($inDatabasePublishing < 3 && $inDatabasePublishing && ($inDatabasePublishing < 2 || !$recursing)) { if ($group && $group !== '*') { $this->getConnection()->affectingStatement(<<<SQL UPDATE {$ltm_translations} SET saved_value = value, status = ? WHERE (saved_value <> value || status <> ?) AND `group` = ? SQL , [Translation::STATUS_SAVED_CACHED, Translation::STATUS_SAVED, $group]); $translations = $this->translation->query()->where('status', '<>', Translation::STATUS_SAVED)->where('group', '=', $group)->get(['group', 'key', 'locale', 'saved_value']); } else { $this->getConnection()->affectingStatement(<<<SQL UPDATE {$ltm_translations} SET saved_value = value, status = ? WHERE (saved_value <> value || status <> ?) SQL , [Translation::STATUS_SAVED_CACHED, Translation::STATUS_SAVED]); $translations = $this->translation->query()->where('status', '<>', Translation::STATUS_SAVED)->get(['group', 'key', 'locale', 'saved_value']); } /* @var $translations Collection */ $this->clearCache($group); $this->clearUsageCache(false, $group); $translations->each(function ($tr) { $this->cacheTranslation($tr->group . '.' . $tr->key, $tr->saved_value, $tr->locale); }); } if (!$inDatabasePublishing || $inDatabasePublishing === 2 || $inDatabasePublishing === 3) { if (!in_array($group, $this->config(self::EXCLUDE_GROUPS_KEY))) { if ($group == '*') { $this->exportAllTranslations(1); } if ($inDatabasePublishing !== 3) { $this->clearCache($group); $this->clearUsageCache(false, $group); } $tree = $this->makeTree($this->translation->where('group', $group)->whereNotNull('value')->orderby('key')->get()); $configRewriter = new TranslationFileRewriter(); $exportOptions = array_key_exists('export_format', $this->config()) ? TranslationFileRewriter::optionFlags($this->config('export_format')) : null; // Laravel 5.1 $base_path = $this->app->basePath(); $pathTemplateResolver = new PathTemplateResolver($this->files, $base_path, $this->config('language_dirs'), '5'); $zipRoot = $base_path . $this->config('zip_root', mb_substr($this->app->langPath(), 0, -4)); // Laravel 4.2 //$base_path = base_path(); //$pathTemplateResolver = new PathTemplateResolver($this->files, $base_path, $this->config('language_dirs'), '4'); //$zipRoot = $base_path . $this->config('zip_root', mb_substr($this->app->make('path').'/lang', 0, -4)); if (mb_substr($zipRoot, -1) === '/') { $zipRoot = substr($zipRoot, 0, -1); } foreach ($tree as $locale => $groups) { if (isset($groups[$group])) { $translations = $groups[$group]; // use the new path mapping $computedPath = $base_path . $pathTemplateResolver->groupFilePath($group, $locale); $path = $computedPath; if ($path) { $configRewriter->parseSource($this->files->exists($path) ? $this->files->get($path) : ''); $output = $configRewriter->formatForExport($translations, $exportOptions); if ($this->zipExporting) { $pathPrefix = mb_substr($path, 0, mb_strlen($zipRoot)); $filePathName = $pathPrefix === $zipRoot ? mb_substr($path, mb_strlen($zipRoot)) : $path; //$this->makeDirPath($filePathName); $this->zipExporting->addFromString($filePathName, $output); } else { try { $this->makeDirPath($path); if (($result = $this->files->put($path, $output)) === false) { $this->errors[] = "Failed to write to {$path}"; } } catch (Exception $e) { $this->errors[] = $e->getMessage(); } } } } } if (!$inDatabasePublishing) { $this->translation->where('group', $group)->update(array('status' => Translation::STATUS_SAVED, 'saved_value' => new Expression('value'))); } } } }