processing export action

@param LanguageListener $listener
@param String $locale
@param String $type
@return \Illuminate\Http\RedirectResponse
978080
public function export(LanguageListener $listener, $locale, $type)
    {
        try {
            $separator    = app('config')->get('antares/translations::export.separator');
            $translations = Languages::where('code', $locale)->whereHas('translations', function($query) use($type) {
                        $query->where('area', $type)->orderBy('key', 'desc');
                    })->first()->translations;

            $lines = [implode($separator, ['Segment', 'Locale', 'Key', 'Translation'])];
            foreach ($translations as $translation) {
                $data = [
                    str_replace('antares/', '', $translation->group),
                    $locale,
                    '"' . $translation->key . '"',
                    '"' . $translation->value . '"',
                ];
                array_push($lines, implode($separator, $data));
            }
            $filename = 'export_' . date('Y_m_d_H_i_s') . '_' . $locale . '.csv';

            return Response::make(implode(PHP_EOL, $lines), '200', array(
                        'Content-Type'        => 'text/csv',
                        'Content-Disposition' => 'attachment; filename="' . $filename
            ));
        } catch (Exception $e) {
            dd($e);
            Log::warning($e);
            return $listener->exportFailed($e->getMessage());
        }
    }
1229759
public function index(SyncListener $listener, $area, $locale = null)
    {
        $lang = is_null($locale) ? app()->getLocale() : $locale;
        try {
            if (Translation::where('area', $area)->where('locale', $locale)->count()) {
                return redirect(handles('antares::translations/index/' . $area . '/' . $lang));
            }
            if (!is_null($locale)) {
                $this->synchronizer->synchronize(lang($locale), $area);
            } else {
                DB::transaction(function() use($area) {
                    $langs = app('languages')->langs();
                    foreach ($langs as $lang) {
                        $this->synchronizer->synchronize($lang, $area);
                    }
                });
            }
            return $listener->syncSuccess($area, $lang);
        } catch (Exception $e) {
            Log::warning($e);
            return $listener->syncFailed($area, $lang);
        }
    }
1096587
public function createJavaScriptLoader(string $locale = null): JavaScriptLoader
	{
		$compilers[] = $this->createJSCompiler($this->files[self::JS][null]);
		if ($locale !== null && isset($this->files[self::JS][$locale])) {
			$compilers[] = $this->createJSCompiler($this->files[self::JS][$locale]);
		}

		return new JavaScriptLoader($this->httpRequest->getUrl()->basePath . $this->outputDir, ...$compilers);
	}
790344
public function getTranslation($entity, $property, $locale)
    {
        $metadata = $this->metadataCollection->getMetadata($entity);
        if($metadata === null) {
            return null;
        }

        $property = $metadata->getProperty($property);
        if($property === null) {
            return null;
        }

        $strategy = $this->strategyResolver->getStrategy($property->getStrategy());
        return $strategy->getTranslation($entity, $property, $locale, $metadata);
    }
1326898
private function triggerActionEvent($instance, $action, $type = 'before')
    {
        if (method_exists($instance, $type . ucfirst($action))) {
            call_user_func([$instance, $type . ucfirst($action)]);
        }
    }
772233
public function handle(EventListenerInterface $listener)
    {
        if (!$listener->getListeners()) {
            return;
        }

        $content = $this->request->getContent();

        try {
            $options = Serializer::parse($content);
        } catch (\InvalidArgumentException $e) {
            $options = [];
        }

        foreach ($listener->getListeners() as $namespace => $callable) {
            $event = new $namespace($options);
            if ($event->isValid()) {
                $listener->trigger($namespace, $event);
                break;
            }
        }
    }
1249044
private function fireEvent($locale, $route, $attributes)
    {
        $response = event(self::EVENT_NAME, [$locale, $route, $attributes]);

        if ( ! empty($response))
            $response = array_shift($response);

        if (is_array($response))
            $attributes = array_merge($attributes, $response);

        return $attributes;
    }
334598
protected function writeLangList($locale, $group, $new_translations)
    {
        $translations = app('translator')->getLoader()->load($locale, $group);

        // Process translations
        foreach ($new_translations as $key => $value) {
            Arr::set(
                $translations,
                $this->encodeKey($key),
                $value
            );
        }

        // Get the language file path
        $language_file = $this->getLangPath() . "/{$locale}/{$group}.php";

        // Sanity check for new language files
        $this->ensureFileExists($language_file);

        if (is_writable($language_file) && ($fp = fopen($language_file, 'w')) !== false) {

            // Export values
            $content = var_export($translations[$group], true);

            // Decode all keys
            $content = $this->decodeKey($content);

            fputs($fp, $this->dumpLangArray("<?php\n\nreturn {$content};"));
            fclose($fp);
        }
        else {
            throw new Exception("Cannot open language file: {$language_file}");
        }
    }
822410
public function delete(LanguageListener $listener, $id)
    {
        DB::beginTransaction();
        try {

            $language = Languages::query()->findOrFail($id);
            if ($language->is_default) {
                throw new Exception(trans('antares/translations::messages.unable_to_delete_default_language'));
            }
            $code = $language->code;
            $language->delete();

            $vendor = base_path('src');
            foreach (['core/foundation', 'core/licensing'] as $dir) {
                $path = implode(DIRECTORY_SEPARATOR, [$vendor, $dir, 'resources', 'lang', $code]);
                $this->deleteLangFiles($path);
            }
            $directories = $this->filesystem->directories($vendor . DIRECTORY_SEPARATOR . 'components');
            foreach ($directories as $directory) {
                $path = implode(DIRECTORY_SEPARATOR, [$directory, 'resources', 'lang', $code]);
                $this->deleteLangFiles($path);
            }
        } catch (Exception $e) {
            DB::rollback();
            return $listener->deleteFailed($e->getMessage());
        }
        DB::commit();
        return $listener->deleteSuccess();
    }
739380
public function addDebugListener($listener, $type = "")
    {
        if (!Text::isEmpty($type) && !in_array($type, ["exec", "query"])) {
            throw new DbException("Invalid filter type. Valid filter types are 'exec' and 'query'");
        }
        
        $types = Text::isEmpty($type)? ["exec", "query"]: [$type];
        foreach ($types as $type) {
            $this->_debugger->on($type, $listener);
        }
    }
515911
public function generateStandalone(GeneratorListener $listener)
    {
        $response    = $this->consoleKernel->call('report:analyzer');
        $splFileInfo = new SplFileInfo($this->consoleKernel->output());
        return new JsonResponse(['redirect' => handles('antares::logger/generate/download/' . trim($splFileInfo->getFilename()))], 200);
    }
1251196
public function publish(Listener $listener, array $input)
    {
        $queues = $this->publisher->queued();

        try {
            $this->publisher->connect($input);
        } catch (ServerException $e) {
            Log::emergency($e);
            $this->session->forget('antares.ftp');

            return $listener->publishingHasFailed(['error' => $e->getMessage()]);
        }

        $this->session->put('antares.ftp', $input);

        if ($this->publisher->connected() && !empty($queues)) {
            $this->publisher->execute();
        }

        return $listener->publishingHasSucceed();
    }
92338
private function exportResource(AbstractResource $resource, $locale)
    {
        $resources = [];

        $event = $this->dispatchEvent($resource, $locale);
        $embedResources = $event->getEmbedResources();

        // Grab data from event
        $resources[$resource->getResourceNode()->getId()] = [
            'node' => $resource->getResourceNode(),
            'template' => $event->getTemplate(),
            'assets' => $event->getAssets(),
            'files' => $event->getFiles(),
            'translation_domains' => $event->getTranslationDomains(),
            'resources' => array_keys($embedResources), // We only need IDs
        ];

        if (!empty($embedResources)) {
            foreach ($embedResources as $embedResource) {
                if (empty($resources[$embedResource->getResourceNode()->getId()])) {
                    // Current resource has not been exported yet
                    $exported = $this->exportResource($embedResource, $locale);
                    $resources = array_merge($resources, $exported);
                }
            }
        }

        return $resources;
    }
525496
public function setLocale($locale)
	{
		$this['config']->set('app.locale', $locale);

		$this['translator']->setLocale($locale);

		$this['events']->fire('locale.changed', array($locale));
	}
607401
protected function localizeDomain($domain, Localization $locale)
    {
        if (!$this->urlReplacer->hasLocalizationReplacer($domain)
            && !$this->urlReplacer->hasLanguageReplacer($domain)
        ) {
            $domain = $this->urlReplacer->appendLocalizationReplacer($domain);
        }

        $domain = $this->urlReplacer->replaceLanguage($domain, $locale->getLanguage());
        $domain = $this->urlReplacer->replaceCountry($domain, $locale->getCountry());
        $domain = $this->urlReplacer->replaceLocalization($domain, $locale->getLocale());

        return $this->urlReplacer->cleanup($domain);
    }
1285288
protected function currentLocaleChanged($locale)
    {
        PunicData::setDefaultLocale($locale);
        $app = Facade::getFacadeApplication();
        if ($app->bound('director')) {
            $event = new \Symfony\Component\EventDispatcher\GenericEvent();
            $event->setArgument('locale', $locale);
            $app->make('director')->dispatch('on_locale_load', $event);
        }
    }
682018
public function normalizer($inputType, $resource=null, $locale=null)
    {

        $extensions = $this->collectExtensions($inputType);

        $normalizer = $this->createNormalizer();

        $this->copyListeners($normalizer);

        foreach ($extensions as $extension) {
            call_user_func($extension, $normalizer, $inputType, $resource, $locale);
        }

        return $normalizer;
    }