Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
core_string_manager_standard Class Reference

Standard string_manager implementation. More...

Inheritance diagram for core_string_manager_standard:
core_string_manager

Public Member Functions

 __construct ($otherroot, $localroot, $translist, $transaliases=[])
 Create new instance of string manager.
 
 get_language_dependencies ($lang)
 Returns list of all explicit parent languages for the given language.
 
 get_list_of_countries ($returnall=false, $lang=null)
 Returns a localised list of all country names, sorted by localised name.
 
 get_list_of_currencies ($lang=null)
 Returns localised list of currencies.
 
 get_list_of_languages ($lang=null, $standard='iso6391')
 Returns a localised list of languages, sorted by code keys.
 
 get_list_of_translations ($returnall=false)
 Returns localised list of installed translations.
 
 get_performance_summary ()
 Returns information about the core_string_manager performance.
 
 get_revision ()
 Returns string revision counter, this is incremented after any string cache reset.
 
 get_string ($identifier, $component='', $a=null, $lang=null)
 Get String returns a requested string.
 
 load_component_strings ($component, $lang, $disablecache=false, $disablelocal=false)
 Load all strings for one component.
 
 reset_caches ($phpunitreset=false)
 Clears both in-memory and on-disk caches.
 
 string_deprecated ($identifier, $component)
 Has string been deprecated?
 
 string_exists ($identifier, $component)
 Does the string actually exist?
 
 translation_exists ($lang, $includeall=true)
 Checks if the translation exists for the language.
 

Protected Member Functions

 get_key_suffix ()
 Returns cache key suffix, this enables us to store string + lang menu caches in local caches on cluster nodes.
 
 load_deprecated_strings ()
 Parses all deprecated.txt in all plugins lang locations and returns the list of deprecated strings.
 
 populate_parent_languages ($lang, array $stack=array())
 Helper method that recursively loads all parents of the given language.
 

Protected Attributes

cache $cache
 lang string cache - it will be optimised more later
 
array $cacheddeprecated
 list of cached deprecated strings
 
int $countgetstring = 0
 get_string() counter
 
string $localroot
 location of all lang pack local modifications
 
cache $menucache
 stores list of available translations
 
string $otherroot
 location of all packs except 'en'
 
array $transaliases = []
 language aliases to use in the language selector
 
array $translist
 use disk cache
 

Detailed Description

Standard string_manager implementation.

Implements string_manager with getting and printing localised strings

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core_string_manager_standard::__construct ( $otherroot,
$localroot,
$translist,
$transaliases = [] )

Create new instance of string manager.

Parameters
string$otherrootlocation of downloaded lang packs - usually $CFG->dataroot/lang
string$localrootusually the same as $otherroot
array$translistlimit list of visible translations
array$transaliasesaliases to use for the languages in the language selector

Member Function Documentation

◆ get_key_suffix()

core_string_manager_standard::get_key_suffix ( )
protected

Returns cache key suffix, this enables us to store string + lang menu caches in local caches on cluster nodes.

We can not use prefix because it would cause problems when creating subdirs in cache file store.

Return values
string

◆ get_language_dependencies()

core_string_manager_standard::get_language_dependencies ( $lang)

Returns list of all explicit parent languages for the given language.

English (en) is considered as the top implicit parent of all language packs and is not included in the returned list. The language itself is appended to the end of the list. The method is aware of circular dependency risk.

See also
self\populate_parent_languages()
Parameters
string$langthe code of the language
Return values
arrayall explicit parent languages with the lang itself appended

◆ get_list_of_countries()

core_string_manager_standard::get_list_of_countries ( $returnall = false,
$lang = null )

Returns a localised list of all country names, sorted by localised name.

Parameters
bool$returnallreturn all or just enabled
string$langmoodle translation language, null means use current
Return values
arraytwo-letter country code => translated name.

Implements core_string_manager.

◆ get_list_of_currencies()

core_string_manager_standard::get_list_of_currencies ( $lang = null)

Returns localised list of currencies.

Parameters
string$langmoodle translation language, null means use current
Return values
arraycurrency code => localised currency name

Implements core_string_manager.

◆ get_list_of_languages()

core_string_manager_standard::get_list_of_languages ( $lang = null,
$standard = 'iso6391' )

Returns a localised list of languages, sorted by code keys.

Parameters
string$langmoodle translation language, null means use current
string$standardlanguage list standard
  • iso6392: three-letter language code (ISO 639-2/T) => translated name
  • iso6391: two-letter language code (ISO 639-1) => translated name
Return values
arraylanguage code => translated name

Implements core_string_manager.

◆ get_list_of_translations()

core_string_manager_standard::get_list_of_translations ( $returnall = false)

Returns localised list of installed translations.

Parameters
bool$returnallreturn all or just enabled
Return values
arraymoodle translation code => localised translation name

Implements core_string_manager.

◆ get_performance_summary()

core_string_manager_standard::get_performance_summary ( )

Returns information about the core_string_manager performance.

Return values
array

◆ get_revision()

core_string_manager_standard::get_revision ( )

Returns string revision counter, this is incremented after any string cache reset.

Return values
intlang string revision counter, -1 if unknown

Implements core_string_manager.

◆ get_string()

core_string_manager_standard::get_string ( $identifier,
$component = '',
$a = null,
$lang = null )

Get String returns a requested string.

Parameters
string$identifierThe identifier of the string to search for
string$componentThe module the string is associated with
string | object | array$aAn object, string or number that can be used within translation strings
string$langmoodle translation language, null means use current
Return values
stringThe String !

Implements core_string_manager.

◆ load_component_strings()

core_string_manager_standard::load_component_strings ( $component,
$lang,
$disablecache = false,
$disablelocal = false )

Load all strings for one component.

Parameters
string$componentThe module the string is associated with
string$lang
bool$disablecacheDo not use caches, force fetching the strings from sources
bool$disablelocalDo not use customized strings in xx_local language packs
Return values
arrayof all string for given component and lang

Implements core_string_manager.

◆ load_deprecated_strings()

core_string_manager_standard::load_deprecated_strings ( )
protected

Parses all deprecated.txt in all plugins lang locations and returns the list of deprecated strings.

Static variable is used for caching, this function is only called in dev environment.

Return values
arrayof deprecated strings in the same format they appear in deprecated.txt files: "identifier,component" where component is a normalised component (i.e. "core_moodle", "mod_assign", etc.)

◆ populate_parent_languages()

core_string_manager_standard::populate_parent_languages ( $lang,
array $stack = array() )
protected

Helper method that recursively loads all parents of the given language.

See also
self\get_language_dependencies()
Parameters
string$langlanguage code
array$stacklist of parent languages already populated in previous recursive calls
Return values
arraylist of all parents of the given language with the $lang itself added as the last element

◆ reset_caches()

core_string_manager_standard::reset_caches ( $phpunitreset = false)

Clears both in-memory and on-disk caches.

Parameters
bool$phpunitresettrue means called from our PHPUnit integration test reset

Implements core_string_manager.

◆ string_deprecated()

core_string_manager_standard::string_deprecated ( $identifier,
$component )

Has string been deprecated?

Usually checked only inside get_string() to display debug warnings.

Parameters
string$identifierThe identifier of the string to search for
string$componentThe module the string is associated with
Return values
booltrue if deprecated

Implements core_string_manager.

◆ string_exists()

core_string_manager_standard::string_exists ( $identifier,
$component )

Does the string actually exist?

get_string() is throwing debug warnings, sometimes we do not want them or we want to display better explanation of the problem. Note: Use with care!

Parameters
string$identifierThe identifier of the string to search for
string$componentThe module the string is associated with
Return values
boottrue if exists

Implements core_string_manager.

◆ translation_exists()

core_string_manager_standard::translation_exists ( $lang,
$includeall = true )

Checks if the translation exists for the language.

Parameters
string$langmoodle translation language code
bool$includeallinclude also disabled translations
Return values
booltrue if exists

Implements core_string_manager.


The documentation for this class was generated from the following file: