Documentation

LanguagePresets

Infrastructure class for predefined language definitions.

Provides access to default language configurations including ISO codes, regex patterns, and display settings.

Tags
category

Lwt

author

HugoFara hugo.farajallah@protonmail.com

license

Unlicense http://unlicense.org/

link
https://hugofara.github.io/lwt/docs/php/
since
3.0.0

Table of Contents

Properties

$definitions  : array<string, array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}>|null
Cached language definitions.
$jsonPath  : string
Path to JSON definitions file.

Methods

clearCache()  : void
Clear cached definitions (for testing).
exists()  : bool
Check if a language is defined.
get()  : array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}|null
Get definition for a specific language.
getAll()  : array<string, array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}>
Get all language definitions in legacy array format.
getGlosbeIso()  : string|null
Get Glosbe ISO code for a language.
getGoogleIso()  : string|null
Get Google ISO code for a language.
getNames()  : array<string|int, string>
Get all language names.
isRightToLeft()  : bool
Check if a language uses right-to-left script.
usesBiggerFont()  : bool
Check if a language requires bigger font.
loadFromJson()  : array<string, array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}>
Load language definitions from JSON file.

Properties

$definitions

Cached language definitions.

private static array<string, array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}>|null $definitions = null

$jsonPath

Path to JSON definitions file.

private static string $jsonPath = __DIR__ . '/Data/langdefs.json'

Methods

clearCache()

Clear cached definitions (for testing).

public static clearCache() : void

exists()

Check if a language is defined.

public static exists(string $name) : bool
Parameters
$name : string

Language name

Return values
bool

get()

Get definition for a specific language.

public static get(string $name) : array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}|null
Parameters
$name : string

Language name (e.g., "English", "Japanese")

Return values
array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}|null

getAll()

Get all language definitions in legacy array format.

public static getAll() : array<string, array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}>

Returns an associative array where keys are language names and values are indexed arrays with the following structure:

  • 0: glosbeIso (string) - Glosbe dictionary ISO code
  • 1: googleIso (string) - Google Translate ISO code
  • 2: biggerFont (bool) - Whether to use larger font
  • 3: wordCharRegExp (string) - Regex for word characters
  • 4: sentSplRegExp (string) - Regex for sentence splitting
  • 5: makeCharacterWord (bool) - Whether to split characters as words
  • 6: removeSpaces (bool) - Whether to remove spaces
  • 7: rightToLeft (bool) - Whether language is RTL
Tags
throws
RuntimeException

If JSON file cannot be read or parsed

Return values
array<string, array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}>

getGlosbeIso()

Get Glosbe ISO code for a language.

public static getGlosbeIso(string $name) : string|null
Parameters
$name : string

Language name

Return values
string|null

Glosbe ISO code or null if not found

getGoogleIso()

Get Google ISO code for a language.

public static getGoogleIso(string $name) : string|null
Parameters
$name : string

Language name

Return values
string|null

Google ISO code or null if not found

getNames()

Get all language names.

public static getNames() : array<string|int, string>
Return values
array<string|int, string>

isRightToLeft()

Check if a language uses right-to-left script.

public static isRightToLeft(string $name) : bool
Parameters
$name : string

Language name

Return values
bool

usesBiggerFont()

Check if a language requires bigger font.

public static usesBiggerFont(string $name) : bool
Parameters
$name : string

Language name

Return values
bool

loadFromJson()

Load language definitions from JSON file.

private static loadFromJson() : array<string, array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}>
Tags
throws
RuntimeException

If file cannot be read or JSON is invalid

Return values
array<string, array{0: string, 1: string, 2: bool, 3: string, 4: string, 5: bool, 6: bool, 7: bool}>

        
On this page

Search results