FUEL CMS User Guide : Version 1.4


Fuel Language Class

This class is used for setting and retrieving the different language options Some code inspired by https://github.com/EllisLab/CodeIgniter/wiki/Language-Selection-2.

This class extends the Fuel_base_library class.

Properties Reference

Property Default Value Description
public
options
array('english' => 'English')
The language options available. Specified in the main FUEL config
selected english The currently selected language. The default is the language specified in the CI config
query_str_param lang The name of the query string parameter to use for setting the language
cookie_name none The name of the cookie to hold the currently selected language
cookie_exp 63072000 Default is 2 years
use_cookies 1 Use cookies to remember a selected language
detect_user_agent none Will check the user agent during language detection
default_option none The default language to use
domains none The domains used for different languages dependent on environment (e.g. mywebsite.de, mywebsite.fr)

Function Reference [+]

$this->fuel->language->initialize([$params=array()])

Initialize the object and set object parameters. Accepts an associative array as input, containing object preferences.

Returns

void

Parameters

(array) $params Array of initalization parameters  (optional)

$this->fuel->language->set_options($options)

Sets the language options.

Returns

void

Parameters

(array) $options Array of language options with the key being the language and the value being a friendly label

$this->fuel->language->options()

Returns the language options.

Returns

array

$this->fuel->language->has_multiple()

Returns boolean value if there are more than one language option.

Returns

boolean

$this->fuel->language->has_language('$lang')

Determines whether a language option exists.

Returns

boolean

$this->fuel->language->set_selected('$selected', ['$set_config'=FALSE], ['$set_query'=FALSE])

Sets the selected language.

Returns

boolean

Parameters

(string) $selected The selected language
(boolean) $set_config Set the config language value (optional)
(boolean) $set_query Set the query string lang value (optional)

$this->fuel->language->selected()

Returns the selected language.

Returns

boolean

$this->fuel->language->selected_label()

Returns the selected languages label value.

Returns

string

$this->fuel->language->set_default_option('$lang')

Sets the default language option.

Returns

string

Parameters

(string) $lang language key value to set as the default

$this->fuel->language->default_option()

The default language option.

Returns

string

$this->fuel->language->is_default('$lang')

Returns whether the language is the default language.

Returns

boolean

$this->fuel->language->is_valid('$lang')

Returns whether the language is a valid selection.

Returns

boolean

$this->fuel->language->detect(['$set_config'=FALSE])

Detects which language should be used.

Returns

string

Parameters

(boolean) $set_config Whether to set the selected value to the detected or not (optional)

$this->fuel->language->user_agent()

Retrieves the language set by the user agent.

Returns

string

Sets the language cookie.

Returns

void

Parameters

(string) $lang The selected language

Returns the language cookie value.

Returns

string

Returns the name of the cookie.

Returns

string

$this->fuel->language->set_query_str('$lang')

Sets the query string to the selected language from the query string.

Returns

void

Parameters

(string) $lang The selected language

$this->fuel->language->query_str_value()

Returns the selected language from the query string.

Returns

boolean

$this->fuel->language->mode()

Returns the method to use for setting language. Value is either 'segment', 'query_string' or both.

Returns

boolean

$this->fuel->language->set_mode('$mode')

Returns

boolean

$this->fuel->language->is_mode('$mode')

Returns a boolean value based on the mode value you pass.

Returns

boolean

Parameters

(string) $mode The name of the mode to test (e.g. 'segment', 'query_string')

$this->fuel->language->is_current_lang_segment('$segment')

Returns a boolean value depending on if the passed segment value equals the current language segment.

Returns

boolean

Parameters

(string) $segment The language segment value

$this->fuel->language->is_lang_segment('$lang')

Returns a boolean value depending on if the passed segment value is a valid language segment.

Returns

boolean

Parameters

(string) $lang The language segment value

$this->fuel->language->lang_segment(['$uri'=NULL], ['$routed'='both'])

Returns the language segment value or FALSE if none exists or the mode is set to "query_string".

Returns

string

Parameters

(string) $uri The URI string to check and extract the language segment from (optional)
(mixed) $routed Determines whether to use a routed (TRUE), non-routed (FALSE), or both (default) when looking at the URI segment if one is not provided in first argument (optional)

$this->fuel->language->cleaned_uri(['$uri'=NULL], ['$routed'=FALSE])

Cleans a URI string value of any language segements.

Returns

string

Parameters

(string) $uri The URI string to check. If none provided, will use the rsegment_array or rsegment_array on the URI object (optional)
(boolean) $routed Determines whether to use a routed (TRUE), non-routed (FALSE) when looking at the URI segment if one is not provided in first argument (optional)

$this->fuel->language->cleaned_uri_segments(['$uri'=NULL], ['$routed'=FALSE])

Cleans a URI segments of any language segements.

Returns

string

Parameters

(string) $uri The URI string to check. If none provided, will use the rsegment_array or rsegment_array on the URI object (optional)
(boolean) $routed Determines whether to use a routed (TRUE), non-routed (FALSE) when looking at the URI segment if one is not provided in first argument (optional)

$this->fuel->language->redirect_to_lang(['$lang'=NULL])

Will redirect you to a language specific URL if the passed or detected language value does not match the current language.

Returns

void

Parameters

(string) $lang The language to check and redirect to. If no value is provided, it will detect (optional)

$this->fuel->language->uri(['$uri'=''], ['$lang'=NULL])

Returns the URI path appending any necessary language information to the path.

Returns

string

Parameters

(string) $uri The URI path (optional)
(string) $lang The language version you want the current URL to represent (optional)

$this->fuel->language->url(['$uri'=''], ['$lang'=NULL])

Returns the URL appending any necessary language information to the path. This is an alias to the site_url function without the second http parameter. The site_lang_url function in the MY_language_helper calls this method.

Returns

string

Parameters

(string) $uri The URI path (optional)
(string) $lang The language version you want the current URL to represent (optional)