class LanguageHelper

Language helper class

Methods

static  array
createLanguageList( string $actualLanguage, string $basePath = JPATH_BASE, boolean $caching = false, boolean $installed = false)

Builds a list of the system languages which can be used in a select option

static  string
detectLanguage()

Tries to detect the language.

static  array
getLanguages( string $key = 'default')

Get available languages

static  array
getInstalledLanguages( integer $clientId = null, boolean $processMetaData = false, boolean $processManifest = false, string $pivot = 'element', string $orderField = null, string $orderDirection = null)

Get a list of installed languages.

static  array
getContentLanguages( array $publishedStates = array(1), boolean $checkInstalled = true, string $pivot = 'lang_code', string $orderField = null, string $orderDirection = null)

Get a list of content languages.

static  boolean
parseIniFile( string $fileName, boolean $debug = false)

Parse strings from a language file.

static  boolean
saveToIniFile( string $fileName, array $strings)

Save strings to a language file.

static  boolean
exists( string $lang, string $basePath = JPATH_BASE)

Checks if a language exists.

static  mixed
getMetadata( string $lang)

Returns an associative array holding the metadata.

static  array
getKnownLanguages( string $basePath = JPATH_BASE)

Returns a list of known languages for an area

static  string
getLanguagePath( string $basePath = JPATH_BASE, string $language = null)

Get the path to a language

static  array
parseLanguageFiles( string $dir = null)

Searches for language directories within a certain base dir.

static  array
parseXMLLanguageFile( string $path)

Parse XML file for language information.

Details

static array createLanguageList( string $actualLanguage, string $basePath = JPATH_BASE, boolean $caching = false, boolean $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
boolean $caching True if caching is used
boolean $installed Get only installed languages

Return Value

array List of system languages

static string detectLanguage()

Tries to detect the language.

Return Value

string locale or null if not found

static array getLanguages( string $key = 'default')

Get available languages

Parameters

string $key Array key

Return Value

array An array of published languages

static array getInstalledLanguages( integer $clientId = null, boolean $processMetaData = false, boolean $processManifest = false, string $pivot = 'element', string $orderField = null, string $orderDirection = null)

Get a list of installed languages.

Parameters

integer $clientId The client app id.
boolean $processMetaData Fetch Language metadata.
boolean $processManifest Fetch Language manifest.
string $pivot The pivot of the returning array.
string $orderField Field to order the results.
string $orderDirection Direction to order the results.

Return Value

array Array with the installed languages.

static array getContentLanguages( array $publishedStates = array(1), boolean $checkInstalled = true, string $pivot = 'lang_code', string $orderField = null, string $orderDirection = null)

Get a list of content languages.

Parameters

array $publishedStates Array with the content language published states. Empty array for all.
boolean $checkInstalled Check if the content language is installed.
string $pivot The pivot of the returning array.
string $orderField Field to order the results.
string $orderDirection Direction to order the results.

Return Value

array Array of the content languages.

static boolean parseIniFile( string $fileName, boolean $debug = false)

Parse strings from a language file.

Parameters

string $fileName The language ini file path.
boolean $debug If set to true debug language ini file.

Return Value

boolean True if saved, false otherwise.

static boolean saveToIniFile( string $fileName, array $strings)

Save strings to a language file.

Parameters

string $fileName The language ini file path.
array $strings The array of strings.

Return Value

boolean True if saved, false otherwise.

static boolean exists( string $lang, string $basePath = JPATH_BASE)

Checks if a language exists.

This is a simple, quick check for the directory that should contain language files for the given user.

Parameters

string $lang Language to check.
string $basePath Optional path to check.

Return Value

boolean True if the language exists.

static mixed getMetadata( string $lang)

Returns an associative array holding the metadata.

Parameters

string $lang The name of the language.

Return Value

mixed If $lang exists return key/value pair with the language metadata, otherwise return NULL.

static array getKnownLanguages( string $basePath = JPATH_BASE)

Returns a list of known languages for an area

Parameters

string $basePath The basepath to use

Return Value

array key/value pair with the language file and real name.

static string getLanguagePath( string $basePath = JPATH_BASE, string $language = null)

Get the path to a language

Parameters

string $basePath The basepath to use.
string $language The language tag.

Return Value

string language related path or null.

static array parseLanguageFiles( string $dir = null)

Searches for language directories within a certain base dir.

Parameters

string $dir directory of files.

Return Value

array Array holding the found languages as filename => real name pairs.

static array parseXMLLanguageFile( string $path)

Parse XML file for language information.

Parameters

string $path Path to the XML files.

Return Value

array Array holding the found metadata as a key => value pair.

Exceptions

RuntimeException