phpBB API Documentation
Class

phpbb\language\language

class language

Wrapper class for loading translations

Constants

FALLBACK_LANGUAGE

Global fallback language

ISO code of the language to fallback to when the specified language entries cannot be found.

Methods

__construct(language_file_loader $loader, array|null $common_modules = null)

Constructor

set_user_language(string $user_lang_iso, bool $reload = false)

Function to set user's language to display.

set_default_language(string $default_lang_iso, bool $reload = false)

Function to set the board's default language to display.

array get_lang_array()

Returns language array

add_lang(string|array $component, string|null $extension_name = null)

Add Language Items

bool is_set($key $key)

string lang()

Advanced language substitution

array|string lang_raw(string|array $key)

Returns the raw value associated to a language key or the language key no translation is available.

string lang_array(string|array $key, array $args = array())

Act like lang() but takes a key and an array of parameters instead of using variadic

int get_plural_form(int|float $number, int|bool $force_rule = false)

Determine which plural form we should use.

string get_used_language()

Returns the ISO code of the used language

Details

at line 79
public __construct(language_file_loader $loader, array|null $common_modules = null)

Constructor

Parameters

language_file_loader $loader Language file loader
array|null $common_modules Array of common language modules to load (optional)

at line 115
public set_user_language(string $user_lang_iso, bool $reload = false)

Function to set user's language to display.

Parameters

string $user_lang_iso ISO code of the User's language
bool $reload Whether or not to reload language files

at line 128
public set_default_language(string $default_lang_iso, bool $reload = false)

Function to set the board's default language to display.

Parameters

string $default_lang_iso ISO code of the board's default language
bool $reload Whether or not to reload language files

at line 143
public array get_lang_array()

Returns language array

Note: This function is needed for the BC purposes, until \phpbb\user::lang[] is not removed.

Return Value

array Array of loaded language strings

at line 167
public add_lang(string|array $component, string|null $extension_name = null)

Add Language Items

Examples: $component = array('posting'); $component = array('posting', 'viewtopic') $component = 'posting'

Parameters

string|array $component The name of the language component to load
string|null $extension_name Name of the extension to load component from, or null for core file

at line 201
public bool is_set($key $key)

Parameters

$key $key array|string The language key we want to know more about. Can be string or array.

Return Value

bool Returns whether the language key is set.

at line 240
public string lang()

Advanced language substitution

Function to mimic sprintf() with the possibility of using phpBB's language system to substitute nullar/singular/plural forms. Params are the language key and the parameters to be substituted. This function/functionality is inspired by SHS` and Ashe.

Example call: $user->lang('NUMPOSTSIN_QUEUE', 1);

If the first parameter is an array, the elements are used as keys and subkeys to get the language entry: Example: $user->lang(array('datetime', 'AGO'), 1) uses $user->lang['datetime']['AGO'] as language entry.

Return Value

string Return localized string or the language key if the translation is not available

at line 256
public array|string lang_raw(string|array $key)

Returns the raw value associated to a language key or the language key no translation is available.

No parameter substitution is performed, can be a string or an array.

Parameters

string|array $key Language key

Return Value

array|string

at line 295
public string lang_array(string|array $key, array $args = array())

Act like lang() but takes a key and an array of parameters instead of using variadic

Parameters

string|array $key Language key
array $args Parameters

Return Value

string

at line 404
public int get_plural_form(int|float $number, int|bool $force_rule = false)

Determine which plural form we should use.

For some languages this is not as simple as for English.

Parameters

int|float $number The number we want to get the plural case for. Float numbers are floored.
int|bool $force_rule False to use the plural rule of the language package or an integer to force a certain plural rule

Return Value

int The plural-case we need to use for the number plural-rule combination

Exceptions

invalid_plural_rule_exception When $force_rule has an invalid value

at line 576
public string get_used_language()

Returns the ISO code of the used language

Return Value

string The ISO code of the currently used language