Back to LanguageHelper class

Method exists

public static bool
exists
(mixed $lang, mixed $basePath = JPATH_BASE)
Checks if a language exists.
Parameters
  • string $lang Language to check.
  • string $basePath Optional path to check.
Returns
  • bool True if the language exists.
Since
  • 3.7.0

Method exists - Source code

/**
 * Checks if a language exists.
 *
 * This is a simple, quick check for the directory that should contain language files for the given user.
 *
 * @param   string  $lang      Language to check.
 * @param   string  $basePath  Optional path to check.
 *
 * @return  boolean  True if the language exists.
 *
 * @since   3.7.0
 */
public static function exists($lang, $basePath = JPATH_BASE)
{
    static $paths = array();
    // Return false if no language was specified
    if (!$lang) {
        return false;
    }
    $path = $basePath . '/language/' . $lang;
    // Return previous check results if it exists
    if (isset($paths[$path])) {
        return $paths[$path];
    }
    // Check if the language exists
    $paths[$path] = is_dir($path);
    return $paths[$path];
}