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.

Properties

protected array $common_language_files
protected bool $common_language_files_loaded
protected string $default_language
protected string $user_language
protected array $language_fallback
protected array $lang
protected array $loaded_language_sets
protected language_file_loader $loader

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(array|string $key)

No description

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 = [])

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

load_common_language_files()

Loads common language files

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

array
set_fallback_array(bool $reload = false)

Returns language fallback data

load_core_file(string $component)

Load core language file

load_extension(string $extension_name, string $component)

Load extension language file

reload_language_files()

Reload language files

Details

at line 79
__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
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
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
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
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
bool is_set(array|string $key)

No description

Parameters

array|string $key

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
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('NUM_POSTS_IN_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
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
string lang_array(string|array $key, array $args = [])

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 378
protected load_common_language_files()

Loads common language files

at line 404
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

at line 576
string get_used_language()

Returns the ISO code of the used language

Return Value

string

The ISO code of the currently used language

at line 588
protected array set_fallback_array(bool $reload = false)

Returns language fallback data

Parameters

bool $reload

Whether or not to reload language files

Return Value

array

at line 617
protected load_core_file(string $component)

Load core language file

Parameters

string $component

Name of the component to load

at line 635
protected load_extension(string $extension_name, string $component)

Load extension language file

Parameters

string $extension_name

Name of the extension to load language from

string $component

Name of the component to load

at line 650
protected reload_language_files()

Reload language files