GetLanguageCode
in package
Use case for resolving language codes.
Tags
Table of Contents
Properties
Methods
- __construct() : mixed
- execute() : string
- Try to get language code from its ID.
- getLanguageName() : string
- Get language name from its ID.
- getScriptDirectionTag() : string
- Return a right-to-left direction indication in HTML if language is RTL.
Properties
$repository
private
LanguageRepositoryInterface
$repository
Methods
__construct()
public
__construct([LanguageRepositoryInterface|null $repository = null ]) : mixed
Parameters
- $repository : LanguageRepositoryInterface|null = null
-
Repository instance
execute()
Try to get language code from its ID.
public
execute(int $id, array<string, array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}> $languagesTable) : string
Parameters
- $id : int
-
Language ID
- $languagesTable : array<string, array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}>
-
Table of languages, usually from LanguagePresets::getAll()
Return values
string —Two-letter code (e.g., BCP 47) or empty string
getLanguageName()
Get language name from its ID.
public
getLanguageName(string|int $id) : string
Parameters
- $id : string|int
-
Language ID
Return values
string —Language name, empty string if not found
getScriptDirectionTag()
Return a right-to-left direction indication in HTML if language is RTL.
public
getScriptDirectionTag(string|int|null $id) : string
Parameters
- $id : string|int|null
-
Language ID
Tags
Return values
string —' dir="rtl" ' or empty string