Translate an application

@param string $application Name of the application
@param string $directory Application path
191481
private function translate_application($application, $directory) {
		$log = '';
		$log .= 'translating ' . $application . ' (' . $directory . ')' . "\n";

		// Fetch the templates in this directory
		$templates = $this->get_templates($directory);
		$strings = [];
		// Parse all the files we found
		foreach ($templates as $template) {
			$log .= $template . "\n";
			$strings = array_merge($strings, $this->get_strings($template, $directory));
		}

		// Translate the strings
		$language_interface = \Skeleton\I18n\Config::$language_interface;
		if (!class_exists($language_interface)) {
			throw new \Exception('The language interface does not exists: ' . $language_interface);
		}
		$languages = $language_interface::get_all();

		foreach ($languages as $language) {
			// Don't create a .po file if it is our base_language
			if ($language->name_short == \Skeleton\I18n\Config::$base_language) {
				continue;
			}

			$log .=  ' ' . $language->name_short;

			// If we already have a (partially) translated file, merge
			if (file_exists(\Skeleton\I18n\Config::$po_directory . '/' . $language->name_short . '/' . $application . '.po')) {
				$translated = \Skeleton\I18n\Util::load(\Skeleton\I18n\Config::$po_directory . '/' . $language->name_short . '/' . $application . '.po');
				$old_translated = \Skeleton\I18n\Util::load(\Skeleton\I18n\Config::$po_directory . '/' . $language->name_short . '.po');
				$translated = array_merge($translated, $old_translated);
			} else {
				$translated = [];
			}

			// Create a new array with the merged translations
			$new_po = [];
			foreach ($strings as $string) {
				if (isset($translated[$string]) and $translated[$string] != '') {
					$new_po[$string] = $translated[$string];
				} else {
					$new_po[$string] = '';
				}
			}

			$result1 = array_diff_key($new_po, $translated);
			$result2 = array_diff_key($translated, $new_po);
			if (count($result1) == 0 and count($result2) == 0) {
				// No new po file will be created, there are no changes
				continue;
			}

			// Stop doing what we are doing if there are no strings anyway
			if (count($new_po) == 0) {
				//continue;
			}

			// And save!
			\Skeleton\I18n\Util::save(\Skeleton\I18n\Config::$po_directory . '/' . $language->name_short . '/' . $application . '.po', $application, $language, $new_po);
		}

		$log .= "\n";
		return $log;
	}
342741
protected function parseDirectoryDo(\Gettext\Translations $translations, $rootDirectory, $relativePath, $subParsersFilter, $exclude3rdParty)
    {
        switch ($relativePath) {
            case '':
                $directoryAlternatives = array('application/config/generated_overrides', 'application/config', 'concrete/config');
                break;
            case 'application':
                $directoryAlternatives = array('config/generated_overrides', 'config');
                break;
            case 'concrete':
                $directoryAlternatives = array('config');
                break;
            default:
                return;
        }
        $prefix = ($relativePath === '') ? '' : "$relativePath/";
        $this->parseFileTypes($translations, $rootDirectory, $prefix, $directoryAlternatives);
        $this->parseTranslatableStrings($translations, $rootDirectory, $prefix, $directoryAlternatives);
    }
1337944
public function writeSupportDirectories(Package $package, $directory)
	{
		foreach (array('config', 'controllers', 'lang', 'migrations', 'views') as $support)
		{
			$this->writeSupportDirectory($package, $support, $directory);
		}
	}
1090115
public function loadLanguagePackFrom($directory)
    {
        $name = $title = basename($directory);

        if (file_exists($manifest = $directory.'/composer.json')) {
            $json = json_decode(file_get_contents($manifest), true);

            if (empty($json)) {
                throw new RuntimeException("Error parsing composer.json in $name: ".json_last_error_msg());
            }

            $locale = array_get($json, 'extra.flarum-locale.code');
            $title = array_get($json, 'extra.flarum-locale.title', $title);
        }

        if (! isset($locale)) {
            throw new RuntimeException("Language pack $name must define \"extra.flarum-locale.code\" in composer.json.");
        }

        $this->locales->addLocale($locale, $title);

        if (! is_dir($localeDir = $directory.'/locale')) {
            throw new RuntimeException("Language pack $name must have a \"locale\" subdirectory.");
        }

        if (file_exists($file = $localeDir.'/config.js')) {
            $this->locales->addJsFile($locale, $file);
        }

        if (file_exists($file = $localeDir.'/config.css')) {
            $this->locales->addCssFile($locale, $file);
        }

        foreach (new DirectoryIterator($localeDir) as $file) {
            if ($file->isFile() && in_array($file->getExtension(), ['yml', 'yaml'])) {
                $this->locales->addTranslations($locale, $file->getPathname());
            }
        }
    }
468648
public function move($directory, $name = null)
    {
        $this->dir($directory);

        $this->name($name);

        return $this;
    }
383835
public function ensureDirectory($directory)
	{
		if(!is_dir($directory))
		{
			$this->ensureDirectory(dirname($directory));
			echo "      mkdir ".strtr($directory,'\\','/')."\n";
			mkdir($directory);
		}
	}
1269072
protected function parseDirectoryDo(\Gettext\Translations $translations, $rootDirectory, $relativePath, $subParsersFilter, $exclude3rdParty)
    {
        $prefix = ($relativePath === '') ? '' : "$relativePath/";
        foreach (array_merge(array(''), $this->getDirectoryStructure($rootDirectory, $exclude3rdParty)) as $child) {
            $shownDirectory = $prefix.(($child === '') ? '' : "$child/");
            $fullDirectoryPath = ($child === '') ? $rootDirectory : "$rootDirectory/$child";
            $contents = @scandir($fullDirectoryPath);
            if ($contents === false) {
                throw new \Exception("Unable to parse directory $fullDirectoryPath");
            }
            foreach ($contents as $file) {
                if ($file[0] !== '.') {
                    $fullFilePath = "$fullDirectoryPath/$file";
                    if (preg_match('/^(.*)\.xml$/', $file) && is_file($fullFilePath)) {
                        static::parseXml($translations, $fullFilePath, $shownDirectory.$file);
                    }
                }
            }
        }
    }
162710
private function ensureDirectoryExists($directory)
    {
        try {
            if (!$this->filesystem->exists($directory)) {
                $this->filesystem->mkdir($directory, 0770);
            }
        } catch (IOException $e) {
            throw new \RuntimeException(sprintf('Cannot create screenshot directory "%s".', $directory));
        }
    }
932022
public function setDirectory($directory = __DIR__)
    {
        if (!is_dir($directory)) {
            $message = "Directory {$directory} doesn't exist.";
            throw new \RuntimeException($message);
        }
        $this->directory = $directory;
        $this->gitattributesFile = $directory
            . DIRECTORY_SEPARATOR
            . '.gitattributes';

        return $this;
    }
802221
public function register(Application $app)
    {
        /** @var Translator $translator  */
        $translator = $app['translator'];
        $translator->addTranslationFolder(__DIR__ . DIRECTORY_SEPARATOR . 'Messages');

        /** @var ApplicationConfiguration $config */
        $config = $app['config'];

        $partialsCollection = new PartialsCollection($app['markdown']);
        $app['partials'] = $partialsCollection;

        /** @var Partial[] $partials */
        $partials = $config->getPartials();
        if ($partials) {
            foreach ($partials as $partial) {
                if (! $partial->getName()) {
                    throw new Exception\MissingNameForPartialException('The name of the partial to load is missing');
                }

                $content = '';
                if ($partial->getContent()) {
                    $content = $partial->getContent();
                } elseif ($partial->getLink()) {
                    if (! is_readable($partial->getLink())) {
                        $app['monolog']->error(
                            sprintf($translator->translate('PPCPP:EXC-NOPARTIAL'), $partial->getLink())
                        );
                        continue;
                    }

                    $content = file_get_contents($partial->getLink());
                }
                $partialsCollection->set($partial->getName(), $content);
            }
        }
    }
1239269
public function setDirectory($directory)
    {
        if (class_exists('\Latte\Engine', true))
        {
            // If possible, load Latte\Engine
            $this->latte = new Latte;
            $this->latte->setTempDirectory(realpath(Core::$tempDir . DS . 'Latte'));
        }
        else
        {
            throw new LayoutException("Could not load LatteEngine. Is it installed or Composer not loaded?", 1);
        }
    }
188112
public function registerCommands(Application $application)
    {
        if (!is_dir($dir = $this->getPath() . '/Command')) {
            return;
        }
        $explorer = new Explorer($dir);
        $explorer->setSearchPattern('/[a-zA-Z0-9]Command\.php$/i');
        
        $prefixNS = $this->getNamespace() . '\\Command';
        foreach ($explorer->getFiles() as $file) {
            $namespace = $prefixNS;
            $class = $namespace . '\\' . $file->getBasename('.php');
            $r = new \ReflectionClass($class);
            if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
                $application->add($r->newInstance());
            }
        }
    }
1052459
private function getTranslations($directory, $language)
    {
        $contentJson = '';

        $directoryJson = ($language == 'en') ? '/en/' : '/../json/';

        $fileJson = $directory.$directoryJson.$language.'.json';

        if (file_exists($fileJson)) {
            $contentJson = json_decode(file_get_contents($fileJson), true);
        }

        return [
            'json'       => $contentJson,
            'auth'       => include($directory.'/'.$language.'/auth.php'),
            'pagination' => include($directory.'/'.$language.'/pagination.php'),
            'passwords'  => include($directory.'/'.$language.'/passwords.php'),
            'validation' => include($directory.'/'.$language.'/validation.php'),
        ];
    }
15402
protected function createDirectory($directory)
    {
        // create parent directory if needed
        $parent = \Gaufrette\Util\Path::dirname($directory);
        if (!$this->isDir($parent)) {
            $this->createDirectory($parent);
        }

        // create the specified directory
        $created = ftp_mkdir($this->getConnection(), $directory);
        if (false === $created) {
            throw new \RuntimeException(sprintf('Could not create the \'%s\' directory.', $directory));
        }
    }
276557
public static function translate($string, Translation $translation = null) {
		if ($translation !== null) {
			$translation = self::get($translation->language, $translation->application_name);
		} else {
			$translation = self::get(\Application::get()->language, \Application::get()->name);
		}

		return $translation->translate_string($string);
	}
1340874
public static function setApplicationDir(array $dir)
    {
        if (DIRECTORY_SEPARATOR == '\\') {//windows
            array_walk($dir, function (&$val) {
                $val = str_replace('/', DIRECTORY_SEPARATOR, $val);
            });
        }
        self::$appDir = array_merge(self::$appDir, $dir);
    }
1261626
protected function makeDir($directory)
	{
		if ( ! $this->files->isDirectory($this->getPath($directory)))
		{
			$this->files->makeDirectory($this->getPath($directory), 0777, true);
		}
	}