3 * @file src/Core/L10n.php
5 namespace Friendica\Core;
7 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").
17 * Returns the current language code
19 * @return string Language code
21 public static function getCurrentLang()
23 return DI::l10n()->getCurrentLang();
29 * @return L10nClass The new L10n class with the new language
31 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
33 public static function withLang(string $lang)
35 return DI::l10n()->withLang($lang);
39 * Return the localized version of the provided string with optional string interpolation
41 * This function takes a english string as parameter, and if a localized version
42 * exists for the current language, substitutes it before performing an eventual
43 * string interpolation (sprintf) with additional optional arguments.
46 * - DI::l10n()->t('This is an example')
47 * - DI::l10n()->t('URL %s returned no result', $url)
48 * - DI::l10n()->t('Current version: %s, new version: %s', $current_version, $new_version)
51 * @param array $vars Variables to interpolate in the translation string
55 public static function t($s, ...$vars)
57 return DI::l10n()->t($s, ...$vars);
61 * Return the localized version of a singular/plural string with optional string interpolation
63 * This function takes two english strings as parameters, singular and plural, as
64 * well as a count. If a localized version exists for the current language, they
65 * are used instead. Discrimination between singular and plural is done using the
66 * localized function if any or the default one. Finally, a string interpolation
67 * is performed using the count as parameter.
70 * - DI::l10n()->tt('Like', 'Likes', $count)
71 * - DI::l10n()->tt("%s user deleted", "%s users deleted", count($users))
73 * @param string $singular
74 * @param string $plural
80 public static function tt(string $singular, string $plural, int $count)
82 return DI::l10n()->tt($singular, $plural, $count);
86 * Return installed languages codes as associative array
88 * Scans the view/lang directory for the existence of "strings.php" files, and
89 * returns an alphabetical list of their folder names (@-char language codes).
90 * Adds the english language if it's missing from the list.
92 * Ex: array('de' => 'de', 'en' => 'en', 'fr' => 'fr', ...)
96 public static function getAvailableLanguages()
98 return L10nClass::getAvailableLanguages();
102 * Translate days and months names.
104 * @param string $s String with day or month name.
106 * @return string Translated string.
108 public static function getDay($s)
110 return DI::l10n()->getDay($s);
114 * Translate short days and months names.
116 * @param string $s String with short day or month name.
118 * @return string Translated string.
120 public static function getDayShort($s)
122 return DI::l10n()->getDayShort($s);
128 * @return array index is present tense verb
129 * value is array containing past tense verb, translation of present, translation of past
130 * @hook poke_verbs pokes array
132 public static function getPokeVerbs()
134 return DI::l10n()->getPokeVerbs();