3 * @file src/Core/L10n.php
5 namespace Friendica\Core;
7 use Friendica\BaseObject;
8 use Friendica\Core\L10n\L10n as L10nClass;
11 * Provide Language, Translation, and Localization functions to the application
12 * Localization can be referred to by the numeronym L10N (as in: "L", followed by ten more letters, and then "N").
14 class L10n extends BaseObject
17 * Returns the current language code
19 * @return string Language code
21 public static function getCurrentLang()
23 return self::getClass(L10nClass::class)->getCurrentLang();
27 * This function should be called before formatting messages in a specific target language
28 * different from the current user/system language.
30 * It saves the current translation strings in a separate variable and loads new translations strings.
32 * If called repeatedly, it won't save the translation strings again, just load the new ones.
35 * @brief Stores the current language strings and load a different language.
36 * @param string $lang Language code
39 public static function pushLang($lang)
41 self::getClass(L10nClass::class)->pushLang($lang);
45 * Restores the original user/system language after having used pushLang()
47 public static function popLang()
49 self::getClass(L10nClass::class)->popLang();
53 * @brief Return the localized version of the provided string with optional string interpolation
55 * This function takes a english string as parameter, and if a localized version
56 * exists for the current language, substitutes it before performing an eventual
57 * string interpolation (sprintf) with additional optional arguments.
60 * - L10n::t('This is an example')
61 * - L10n::t('URL %s returned no result', $url)
62 * - L10n::t('Current version: %s, new version: %s', $current_version, $new_version)
65 * @param array $vars Variables to interpolate in the translation string
68 public static function t($s, ...$vars)
70 return self::getClass(L10nClass::class)->t($s, ...$vars);
74 * @brief Return the localized version of a singular/plural string with optional string interpolation
76 * This function takes two english strings as parameters, singular and plural, as
77 * well as a count. If a localized version exists for the current language, they
78 * are used instead. Discrimination between singular and plural is done using the
79 * localized function if any or the default one. Finally, a string interpolation
80 * is performed using the count as parameter.
83 * - L10n::tt('Like', 'Likes', $count)
84 * - L10n::tt("%s user deleted", "%s users deleted", count($users))
86 * @param string $singular
87 * @param string $plural
92 public static function tt(string $singular, string $plural, int $count)
94 return self::getClass(L10nClass::class)->tt($singular, $plural, $count);
98 * @brief Return installed languages codes as associative array
100 * Scans the view/lang directory for the existence of "strings.php" files, and
101 * returns an alphabetical list of their folder names (@-char language codes).
102 * Adds the english language if it's missing from the list.
104 * Ex: array('de' => 'de', 'en' => 'en', 'fr' => 'fr', ...)
108 public static function getAvailableLanguages()
110 return L10nClass::getAvailableLanguages();
114 * @brief Translate days and months names.
116 * @param string $s String with day or month name.
117 * @return string Translated string.
119 public static function getDay($s)
121 return self::getClass(L10nClass::class)->getDay($s);
125 * @brief Translate short days and months names.
127 * @param string $s String with short day or month name.
128 * @return string Translated string.
130 public static function getDayShort($s)
132 return self::getClass(L10nClass::class)->getDayShort($s);