Menu

## Language extends KBase
in package

Language.php : 18

Class for language loading.

##### Tags

see
  https://www.kotchasan.com/

### Table of Contents

$cfg : object
  Config class instance.
$request : Request
  Server request class instance.
$installed_languages : array<string|int, mixed>
$language_name : string
$languages : object
arrayKeyExists() : bool
  Checks if a language variable specified by name exists and is an array with a given key.
get() : mixed
  Retrieves the language variable with the specified key.
getItems() : array<string|int, mixed>
  Retrieves multiple language items based on the specified keys.
installed() : array<string|int, mixed>
  Loads all installed language files.
installedLanguage() : array<string|int, mixed>
  Retrieves an array of installed languages.
keyExists() : int
  Checks if a language key exists in the given array of languages.
languageFolder() : string
  Retrieves the folder path where language files are stored.
load() : mixed
  Loads the language file based on the selected language.
name() : string
  Retrieves the name of the currently active language.
parse() : string
  Function that translates the language received from Theme parsing.
replace() : string
  Retrieves the language value based on the given key and replaces placeholders with values from the $replace array.
save() : string
  Saves the language file.
setName() : string
  Sets the language to be used.
sprintf() : string
  Format a string based on a key using sprintf formatting.
trans() : string
  Translates the given content by replacing language placeholders.
__construct() : mixed
  Loads the language.

### Properties

#### $cfg

KBase.php : 26

Config class instance.

`protected static object $cfg`

#### $request

KBase.php : 33

Server request class instance.

`protected static Request $request`

#### $installed_languages

Language.php : 23
`private static array<string|int, mixed> $installed_languages`

Installed languages.

#### $language_name

Language.php : 28
`private static string $language_name`

Name of the currently used language.

#### $languages

Language.php : 33
`private static object $languages = null`

Language data.

### Methods

#### arrayKeyExists()

Language.php : 187

Checks if a language variable specified by name exists and is an array with a given key.

`public static arrayKeyExists(string $name, string $key) : bool`

##### Parameters

$name : string

  The name of the language variable.

$key : string

  The key to check.

##### Tags

assert

  ('DATE_LONG', 1) [==] true

assert

  ('DATE_LONG', 7) [==] false

##### Return values

bool —

True if the language variable exists and is an array with the given key, false otherwise.

#### get()

Language.php : 50

Retrieves the language variable with the specified key.

`public static get(string $key[, mixed $default = null ][, mixed $value = null ]) : mixed`

##### Parameters

$key : string

  The language variable key or English text.

$default : mixed = null

  The default value to return if the key is not found.

$value : mixed = null

  If an array variable is specified and $value is set, returns the language value at $key[$value].

##### Tags

assert

  ('YEAR_OFFSET') [==] 543

assert

  ('XYZ', []) [==] []

assert

  ('DATE_LONG', null, 0) [==] 'อาทิตย์'

assert

  ('DATE_LONG', null, 12) [==] 'DATE_LONG'

assert

  ('not found', 'default') [==] 'default'

##### Return values

mixed —

The language value or the default value if the key is not found.

#### getItems()

Language.php : 74

Retrieves multiple language items based on the specified keys.

`public static getItems([array<string|int, mixed> $keys = [] ]) : array<string|int, mixed>`

##### Parameters

$keys : array<string|int, mixed> = []

  An array of language variable keys or English texts.

##### Return values

array<string|int, mixed> —

An array of language values.

#### installed()

Language.php : 93

Loads all installed language files.

`public static installed(string $type) : array<string|int, mixed>`

##### Parameters

$type : string

  The file type (php or js).

##### Return values

array<string|int, mixed> —

An array of language data.

#### installedLanguage()

Language.php : 138

Retrieves an array of installed languages.

`public static installedLanguage() : array<string|int, mixed>`

##### Return values

array<string|int, mixed> —

An array of installed languages.

#### keyExists()

Language.php : 165

Checks if a language key exists in the given array of languages.

`public static keyExists(array<string|int, mixed> $languages, string $key) : int`

##### Parameters

$languages : array<string|int, mixed>

  An array of language data.

$key : string

  The language key to check.

##### Tags

assert

  (array(array('id' => 0, 'key' => 'One'), array('id' => 100, 'key' => 'Two')), 'One') [==] 0

assert

  (array(array('id' => 0, 'key' => 'One'), array('id' => 100, 'key' => 'Two')), 'two') [==] 100

assert

  (array(array('id' => 0, 'key' => 'One'), array('id' => 100, 'key' => 'Two')), 'O') [==] -1

##### Return values

int —

The index of the found key, or -1 if not found.

#### languageFolder()

Language.php : 200

Retrieves the folder path where language files are stored.

`public static languageFolder() : string`

##### Return values

string —

The folder path where language files are stored.

#### load()

Language.php : 394

Loads the language file based on the selected language.

`public static load(string $lang) : mixed`

##### Parameters

$lang : string

  The language to be loaded.

##### Return values

mixed —

#### name()

Language.php : 212

Retrieves the name of the currently active language.

`public static name() : string`

##### Tags

assert

  () [==] 'th'

##### Return values

string —

The name of the currently active language.

#### parse()

Language.php : 244

Function that translates the language received from Theme parsing.

`public static parse(array<string|int, mixed> $match) : string`

##### Parameters

$match : array<string|int, mixed>

  The variable received from Theme parsing.

##### Tags

assert

  (array(1 => 'not found')) [==] 'not found'

##### Return values

string —

#### replace()

Language.php : 261

Retrieves the language value based on the given key and replaces placeholders with values from the $replace array.

`public static replace(string $key, mixed $replace) : string`

##### Parameters

$key : string

  The language key.

$replace : mixed

  The values to replace placeholders.

##### Tags

assert

  ('You want to :action', array(':action' => 'delete')) [==] 'You want to delete'

assert

  ('You want to %s', 'delete') [==] 'You want to delete'

assert

  ('You want to %s', 1) [==] 'You want to 1'

##### Return values

string —

#### save()

Language.php : 308

Saves the language file.

`public static save(array<string|int, mixed> $languages, string $type) : string`

##### Parameters

$languages : array<string|int, mixed>

  The language data to be saved.

$type : string

  The type of file to save ('php' or 'js').

##### Return values

string —

#### setName()

Language.php : 227

Sets the language to be used.

`public static setName(string $language) : string`

##### Parameters

$language : string

  The language to be set.

##### Return values

string —

The name of the language.

#### sprintf()

Language.php : 289

Format a string based on a key using sprintf formatting.

`public static sprintf(string $key, mixed ...$values) : string`

##### Parameters

$key : string

  The key to lookup in the language translations.

$values : mixed

  Optional values to substitute into the formatted string.

##### Tags

assert

  ('Error moving uploaded file %1s to %2s', 'one', 'two') [==] 'Error moving uploaded file one to two'

assert

  ('Error moving uploaded file %s to %s', 'one', 'two') [==] 'Error moving uploaded file one to two'

##### Return values

string —

The formatted string.

#### trans()

Language.php : 382

Translates the given content by replacing language placeholders.

`public static trans(string $content) : string`

##### Parameters

$content : string

  The content to be translated.

##### Tags

assert

  ('ภาษา {LNG_DATE_FORMAT} ไทย') [==] 'ภาษา d M Y เวลา H:i น. ไทย'

##### Return values

string —

The translated content.

#### __construct()

Language.php : 412

Loads the language.

`private __construct([string|null $lang = null ]) : mixed`

##### Parameters

$lang : string|null = null

  The language to be used. If not specified, it will read from the 'my_lang' cookie.

##### Return values

mixed —

## Search results