The format_code_lang() WordPress PHP function is used to return the full name of a language given its two-letter code.
Usage
Here’s a basic usage example:
$code = 'fr'; $language = format_code_lang($code); echo $language; // Outputs: 'French'
Parameters
- $code (string – Optional): The two-letter language code. Default is ” (empty string).
More Information
See WordPress Developer Resources: format_code_lang()
This function only works in a multisite environment. It’s not suitable for use in regular plugins on non-multisite installs, as it will result in an Uncaught Error: Call to undefined function format_code_lang() error.
Examples
Basic Usage
This code will return the full language name for the code ‘fr’.
$code = 'fr'; $language = format_code_lang($code); echo $language; // Outputs: 'French'
Default Value
If no parameter is provided, the function will return an empty string.
$language = format_code_lang(); echo $language; // Outputs: ''
Non-Existent Code
For a non-existent or unsupported code, the function will return the code itself.
$code = 'zz'; $language = format_code_lang($code); echo $language; // Outputs: 'zz'
Case Insensitivity
The function is case-insensitive. It will return the same result for upper and lower case codes.
$code = 'DE'; $language = format_code_lang($code); echo $language; // Outputs: 'German'
Multisite Environment
Remember, this function only works in a multisite environment.
if (function_exists('format_code_lang')) { $code = 'es'; $language = format_code_lang($code); echo $language; // Outputs: 'Spanish' } else { echo 'The function format_code_lang() is not defined in this environment.'; }