]> git.mxchange.org Git - friendica.git/blob - src/Core/L10n.php
@brief is removed completely
[friendica.git] / src / Core / L10n.php
1 <?php
2 /**
3  * @file src/Core/L10n.php
4  */
5 namespace Friendica\Core;
6
7 use Friendica\Core\L10n\L10n as L10nClass;
8 use Friendica\DI;
9
10 /**
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").
13  */
14 class L10n
15 {
16         /**
17          * Returns the current language code
18          *
19          * @return string Language code
20          */
21         public static function getCurrentLang()
22         {
23                 return DI::l10n()->getCurrentLang();
24         }
25
26         /**
27          * @param string $lang
28          *
29          * @return L10nClass The new L10n class with the new language
30          *
31          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
32          */
33         public static function withLang(string $lang)
34         {
35                 return DI::l10n()->withLang($lang);
36         }
37
38         /**
39          * Return the localized version of the provided string with optional string interpolation
40          *
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.
44          *
45          * Usages:
46          * - L10n::t('This is an example')
47          * - L10n::t('URL %s returned no result', $url)
48          * - L10n::t('Current version: %s, new version: %s', $current_version, $new_version)
49          *
50          * @param string $s
51          * @param array  $vars Variables to interpolate in the translation string
52          *
53          * @return string
54          */
55         public static function t($s, ...$vars)
56         {
57                 return DI::l10n()->t($s, ...$vars);
58         }
59
60         /**
61          * Return the localized version of a singular/plural string with optional string interpolation
62          *
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.
68          *
69          * Usages:
70          * - L10n::tt('Like', 'Likes', $count)
71          * - L10n::tt("%s user deleted", "%s users deleted", count($users))
72          *
73          * @param string $singular
74          * @param string $plural
75          * @param int    $count
76          *
77          * @return string
78          * @throws \Exception
79          */
80         public static function tt(string $singular, string $plural, int $count)
81         {
82                 return DI::l10n()->tt($singular, $plural, $count);
83         }
84
85         /**
86          * Return installed languages codes as associative array
87          *
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.
91          *
92          * Ex: array('de' => 'de', 'en' => 'en', 'fr' => 'fr', ...)
93          *
94          * @return array
95          */
96         public static function getAvailableLanguages()
97         {
98                 return L10nClass::getAvailableLanguages();
99         }
100
101         /**
102          * Translate days and months names.
103          *
104          * @param string $s String with day or month name.
105          *
106          * @return string Translated string.
107          */
108         public static function getDay($s)
109         {
110                 return DI::l10n()->getDay($s);
111         }
112
113         /**
114          * Translate short days and months names.
115          *
116          * @param string $s String with short day or month name.
117          *
118          * @return string Translated string.
119          */
120         public static function getDayShort($s)
121         {
122                 return DI::l10n()->getDayShort($s);
123         }
124
125         /**
126          * Load poke verbs
127          *
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
131          */
132         public static function getPokeVerbs()
133         {
134                 return DI::l10n()->getPokeVerbs();
135         }
136 }