Back to LanguageHelper class

Method createLanguageList

public static array
createLanguageList
(mixed $actualLanguage, mixed $basePath = JPATH_BASE, mixed $caching = false, mixed $installed = false)
Builds a list of the system languages which can be used in a select option
Parameters
  • string $actualLanguage Client key for the area
  • string $basePath Base path to use
  • bool $caching True if caching is used
  • bool $installed Get only installed languages
Returns
  • array List of system languages
Since
  • 1.5

Method createLanguageList - Source code

/**
 * Builds a list of the system languages which can be used in a select option
 *
 * @param   string   $actualLanguage  Client key for the area
 * @param   string   $basePath        Base path to use
 * @param   boolean  $caching         True if caching is used
 * @param   boolean  $installed       Get only installed languages
 *
 * @return  array  List of system languages
 *
 * @since   1.5
 */
public static function createLanguageList($actualLanguage, $basePath = JPATH_BASE, $caching = false, $installed = false)
{
    $list = array();
    $clientId = $basePath === JPATH_ADMINISTRATOR ? 1 : 0;
    $languages = $installed ? static::getInstalledLanguages($clientId, true) : self::getKnownLanguages($basePath);
    foreach ($languages as $languageCode => $language) {
        $metadata = $installed ? $language->metadata : $language;
        $list[] = array('text' => $metadata['nativeName'] ?? $metadata['name'], 'value' => $languageCode, 'selected' => $languageCode === $actualLanguage ? 'selected="selected"' : null);
    }
    return $list;
}