lang (function)

Last updated: Mon, Apr 17, 2023 12:38 pm
Return to Knowledgebase

Purpose

Used to retrieve language strings based on a specified key.

Location

users/helpers/us_helpers.php

Parameters

# Parameter Data Type Required Description
1 $key string Yes This is the language key that corresponds to the string you want to retrieve.
2 $markers = null array No This is an array of values that are used to replace dynamic markers in the language string.

Returns

Data Type Description of Returned Data
string Translation of the specified language key.

Further Documentation:

The lang function is used to retrieve language strings based on a specified key. This function is commonly used in web applications to allow for multi-language support.

The lang function takes two parameters:

$key (required) - This is the language key that corresponds to the string you want to retrieve.
$markers (optional) - This is an array of values that are used to replace dynamic markers in the language string. Dynamic markers are placeholders in the language string that will be replaced with specific values. If the $markers parameter is not provided, the function will return the language string as is.
Here's an example of how you might use the lang function in a web application:


// Include the language file
include('path/to/language/file.php');

// Retrieve a language string
$welcome_message = lang('WELCOME_MESSAGE');

// Retrieve a language string with dynamic markers
$username = 'John';
$greeting = lang('GREETING_MESSAGE', [$username]);



In this example, the lang function is used to retrieve two language strings. The first call retrieves the value of the WELCOME_MESSAGE key, which might be something like "Welcome to our website!" The second call retrieves the value of the GREETING_MESSAGE key, which might be something like "Hello %m1%!" The %m1% dynamic marker in this example is replaced with the value of $username, which is "John". The resulting value of $greeting would be "Hello John!".