Checks if a language is supported

@param string $language
@param string|array $dirs OPTIONAL Directories where language files are stored
@return bool
553274
public static function exists($language, $dirs = null)
    {
        return Atomik::findFile("$language.php", $dirs ?: self::$config['dir']) !== false;
    }
603556
protected function hasLanguageCodesAsKeys(array $fields)
    {
        $languageCodes = $this->getContentLanguageCodes();

        foreach ($fields as $fieldIdentifier => $fieldData) {
            if (!is_array($fieldData) || empty($fieldData)) {
                return false;
            }

            foreach ($fieldData as $key => $data) {
                if (!in_array($key, $languageCodes, true)) {
                    return false;
                }
            }
        }

        return true;
    }
1323913
public function digipolisCleanDir($dirs, $opts = ['sort' => PartialCleanDirsTask::SORT_NAME])
    {
        $dirsArg = array();
        foreach (array_map('trim', explode(',', $dirs)) as $dir) {
            $dirParts = explode(':', $dir);
            if (count($dirParts) > 1) {
                $dirsArg[$dirParts[0]] = $dirParts[1];
                continue;
            }
            $dirsArg[] = $dirParts[0];
        }
        return $this->taskPartialCleanDirs($dirsArg)
            ->sortBy($opts['sort'])
            ->run();
    }
856677
public function setCurrentLanguage($language)
    {
        if (empty(self::$supported_languages[$language])) {
            return false;
        }
        
        self::$current_language = $language;
        
        session()->vars()[self::$context . "_language"] = $language;
        
        setcookie(self::$context . "_language", $language, time() + 365 * 24 * 3600);
        
        return true;
    }
138060
public static function setLanguage($language) {
        static::$language = $language;

        static::$message = array();

        $kernalLanguageFolder = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..';
        static::addMessage($kernalLanguageFolder);

        if (defined('API_ROOT')) {
            static::addMessage(API_ROOT);
        }
    }
1190145
protected function deleteLangFiles($path)
    {
        if (is_dir($path)) {
            $this->filesystem->cleanDirectory($path);
            $this->filesystem->deleteDirectory($path);
            return true;
        }
        return false;
    }
623065
final protected function loadTranslations($language)
    {
        // Don't load the same language twice, if that's the case
        if ($this->appConfig->getLanguage() !== $language) {

            $this->appConfig->setLanguage($language);
            $this->loadTranslationMessages($language);
            return true;

        } else {
            return false;
        }
    }
402706
public static function validate($language)
    {
        if (\in_array(\strtolower($language), self::$validLanguageCode, true)) {
            return \strtolower($language);
        }

        return false;
    }
1342275
public function checkWritableI18nDirectory($dir)
    {
        if (file_exists($dir)) {
            return is_writable($dir);
        }

        $parentDir = dirname($dir);

        return file_exists($parentDir) && is_writable($parentDir);
    }
454649
public function isValid($translations)
    {
        $this->message = null;

        // check if any translation contains restricted script tags
        $serializedStrings = serialize($translations);
        $invalids = array("<script", 'document.', 'javascript:', 'src=', 'background=', 'onload=');

        foreach ($invalids as $invalid) {
            if (stripos($serializedStrings, $invalid) !== false) {
                $this->message = 'script tags restricted for language files';
                return false;
            }
        }

        return true;
    }
715732
public static function getDefinedLanguages($dirs = null)
    {
        $dirs = $dirs ?: self::$config['dir'];
        $languages = array();
        foreach (array_filter(Atomik::path((array) $dirs)) as $dir) {
            if (is_dir($dir)) {
                foreach (new DirectoryIterator($dir) as $file) {
                    $filename = $file->getFilename();
                    if ($filename{0} == '.' || $file->isDir()) {
                        continue;
                    }
                    $languages[] = substr($filename, 0, strrpos($filename, '.'));
                }
            }
        }
        return $languages;
    }
373721
public function hasTranslation($slug = false, $language = null)
    {
        return $this->hasTrans($slug, null, $language);
    }
111314
public function getTranslationsFromFiles($domain, $path, array $directories = [])
    {
        if (!$directories) {
            $directories = [
                $path . 'Resources' . DIRECTORY_SEPARATOR . 'translations',
                $this->kernelRoot . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . $domain . DIRECTORY_SEPARATOR . 'translations',
            ];
        }

        $finder = new Finder();
        $translations = [];

        foreach ($directories as $directory) {
            if (is_dir($directory)) {
                $finder->files()
                    ->name($this->getFileNamePattern())
                    ->in($directory);

                foreach ($finder as $file) {
                    $translations = array_replace_recursive($this->getFileTranslationMessages($file, $domain), $translations);
                }
            }
        }

        return $translations;
    }
164871
private function _checkLanguage(&$language)
    {
        if (!isset($language)) {
            throw new Klarna_ArgumentNotSetException("Language");
        }
        if (is_numeric($language) && !is_int($language)) {
            $language = intval($language);
        }
        if (!is_numeric($language) || !is_int($language)) {
            throw new Klarna_InvalidTypeException("Language", "integer");
        }
    }
601700
public function exists($language, $basePath = ANPATH_BASE)
	{
        $directory = $this->getLanguagePath($basePath, $language);
        return is_dir($directory);
	}
919751
public static function setLanguage($language)
    {
        if (! ($language instanceof Language)) {
            $language = Language::findByCode($language);
        }

        if (! $language) {
            return false;
        }

        App::setLocale($language->code);
        request()->setDefaultLocale($language->code);
        self::$language = $language;

        return $language;
    }
284668
public static function parseLanguageFiles($dir = null)
	{
		$languages = array();

		// Search main language directory for subdirectories
		foreach (glob($dir . '/*', GLOB_NOSORT | GLOB_ONLYDIR) as $directory)
		{
			// But only directories with lang code format
			if (preg_match('#/[a-z]{2,3}-[A-Z]{2}$#', $directory))
			{
				$dirPathParts = pathinfo($directory);
				$file         = $directory . '/' . $dirPathParts['filename'] . '.xml';

				if (!is_file($file))
				{
					continue;
				}

				try
				{
					// Get installed language metadata from xml file and merge it with lang array
					if ($metadata = self::parseXMLLanguageFile($file))
					{
						$languages = array_replace($languages, array($dirPathParts['filename'] => $metadata));
					}
				}
				catch (\RuntimeException $e)
				{
				}
			}
		}

		return $languages;
	}