Skip to content

Commit 266182f

Browse files
committed
docs(l10n): improve method documentation for locale handling in L10nHelper
1 parent 652592a commit 266182f

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

src/Helpers/L10nHelper.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ class L10nHelper
1010
/**
1111
* Get the available locale codes from the configuration.
1212
*
13+
* The method returns an associative array of locales, where the element key is always the same as the value.
14+
*
15+
* Example:
16+
* ```
17+
* [
18+
* 'en' => 'en',
19+
* 'sl' => 'sl',
20+
* ]
21+
* ```
22+
*
1323
* @return string[]
1424
*
1525
* @throws InvalidConfigurationException
@@ -35,8 +45,19 @@ public static function getAvailableLocales(): array
3545
}
3646

3747
/**
38-
* Get a list of available locales for the application.
39-
* Returns an array of locale codes (as keys) and their corresponding names (as values).
48+
* Get the available locale options for use in select boxes or similar UI elements.
49+
*
50+
* The method returns an associative array of locales, where the element key is the locale code and the element value is the language name.
51+
*
52+
* Example:
53+
* ```
54+
* [
55+
* 'en' => 'English',
56+
* 'sl' => 'Slovenian',
57+
* ]
58+
* ```
59+
*
60+
* Please note: **The language name is provided by the `intl` PHP extension, therefore, you must have it installed to use this method.**
4061
*
4162
* @return string[]
4263
*
@@ -52,6 +73,14 @@ public static function getLocaleOptions(): array
5273
* 1. If the `intl` PHP extension is installed, use the `\Locale` class to get the language name.
5374
* 2. Otherwise, return the language code
5475
*
76+
* Examples:
77+
* ```
78+
* L10nHelper::getLanguageName('en') // English
79+
* L10nHelper::getLanguageName('sl') // Slovenian
80+
* L10nHelper::getLanguageName('sl', true) // Slovenian (sl)
81+
* L10nHelper::getLanguageName('xx') // xx
82+
* ```
83+
*
5584
* @param string $code Language code
5685
* @param bool $include_code Include the language code in the output (in parentheses)
5786
* @return string Language name

0 commit comments

Comments
 (0)